Removed references to deprecated API
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1311381 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d544026bee
commit
0cea739a38
httpclient/src/test/java/org/apache/http/impl/client
|
@ -49,7 +49,6 @@ import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.entity.DeflateDecompressingEntity;
|
import org.apache.http.client.entity.DeflateDecompressingEntity;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.protocol.RequestAcceptEncoding;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
@ -92,7 +91,7 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
|
@ -115,7 +114,7 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
|
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
|
@ -138,7 +137,8 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
|
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
Assert.assertEquals("The entity text is correctly transported", entityText,
|
Assert.assertEquals("The entity text is correctly transported", entityText,
|
||||||
|
@ -158,7 +158,8 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
Assert.assertEquals("The entity text is correctly transported", entityText,
|
Assert.assertEquals("The entity text is correctly transported", entityText,
|
||||||
|
@ -223,48 +224,6 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that we can turn off the new Content-Coding support. The default is that it's on, but that is a change
|
|
||||||
* to existing behaviour and might not be desirable in some situations.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testCanBeDisabledAtRequestTime() throws Exception {
|
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
|
||||||
|
|
||||||
/* Assume that server will see an Accept-Encoding header. */
|
|
||||||
final boolean [] sawAcceptEncodingHeader = { true };
|
|
||||||
|
|
||||||
this.localServer.register("*", new HttpRequestHandler() {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
|
|
||||||
response.setEntity(new StringEntity(entityText));
|
|
||||||
response.addHeader("Content-Type", "text/plain");
|
|
||||||
Header[] acceptEncodings = request.getHeaders("Accept-Encoding");
|
|
||||||
|
|
||||||
sawAcceptEncodingHeader[0] = acceptEncodings.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
AbstractHttpClient client = createHttpClient();
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
|
||||||
|
|
||||||
client.removeRequestInterceptorByClass(RequestAcceptEncoding.class);
|
|
||||||
|
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
|
||||||
|
|
||||||
Assert.assertFalse("The Accept-Encoding header was not there", sawAcceptEncodingHeader[0]);
|
|
||||||
Assert.assertEquals("The entity isn't treated as gzip or zip content", entityText,
|
|
||||||
EntityUtils.toString(response.getEntity()));
|
|
||||||
|
|
||||||
client.getConnectionManager().shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the returned {@link HttpEntity} in the response correctly overrides
|
* Test that the returned {@link HttpEntity} in the response correctly overrides
|
||||||
* {@link HttpEntity#writeTo(OutputStream)} for gzip-encoding.
|
* {@link HttpEntity#writeTo(OutputStream)} for gzip-encoding.
|
||||||
|
@ -277,7 +236,7 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
@ -301,7 +260,8 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
|
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
HttpResponse response = client.execute(getServerHttp(), request);
|
HttpResponse response = client.execute(getServerHttp(), request);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
@ -319,7 +279,8 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
|
String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
|
||||||
Assert.assertEquals("The entity text is correctly transported", entityText, response);
|
Assert.assertEquals("The entity text is correctly transported", entityText, response);
|
||||||
|
@ -333,7 +294,8 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
|
|
||||||
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
|
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
|
||||||
|
|
||||||
DefaultHttpClient client = createHttpClient();
|
HttpClient client = new CompressionDecorator(new DefaultHttpClient());
|
||||||
|
|
||||||
HttpGet request = new HttpGet("/some-resource");
|
HttpGet request = new HttpGet("/some-resource");
|
||||||
String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
|
String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
|
||||||
Assert.assertEquals("The entity text is correctly transported", entityText, response);
|
Assert.assertEquals("The entity text is correctly transported", entityText, response);
|
||||||
|
@ -457,10 +419,6 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultHttpClient createHttpClient() {
|
|
||||||
return new ContentEncodingHttpClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sub-ordinate task passed off to a different thread to be executed.
|
* Sub-ordinate task passed off to a different thread to be executed.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue