Permalink
Browse files

Upgraded to HttpCore 4.2

  • Loading branch information...
1 parent ff9f2b0 commit 23c020578c7d8c5e210299931eb984437e074467 @ok2c ok2c committed May 5, 2012
View
2 httpasyncclient/src/examples/org/apache/http/examples/nio/client/ZeroCopyHttpExchange.java
@@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception {
File upload = new File(args[0]);
File download = new File(args[1]);
ZeroCopyPost httpost = new ZeroCopyPost("http://localhost:8080/", upload,
- ContentType.create("text/plain", null));
+ ContentType.create("text/plain"));
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
View
2 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java
@@ -73,7 +73,7 @@ protected HttpParams createHttpParams() {
public static void setDefaultHttpParams(HttpParams params) {
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
+ HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSocketBufferSize(params, 8192);
View
24 ...syncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
@@ -31,18 +31,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.Header;
import org.apache.http.HttpException;
-import org.apache.http.HttpResponse;
-import org.apache.http.impl.nio.conn.DefaultClientAsyncConnection;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpClientConnection;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
- private final Log headerlog = LogFactory.getLog("org.apache.http.headers");
private final Log log = LogFactory.getLog(HttpAsyncRequestExecutor.class);
public LoggingAsyncRequestExecutor() {
@@ -121,26 +117,6 @@ public void responseReceived(
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Response received");
}
-
- // TODO: move header logging back to DefaultAsyncClientConnection
- // once DefaultNHttpClientConnection#onResponseReceived method
- // becomes available.
- if (this.headerlog.isDebugEnabled()) {
- HttpResponse response = conn.getHttpResponse();
- String id;
- if (conn instanceof DefaultClientAsyncConnection) {
- id = ((DefaultClientAsyncConnection) conn).getId();
- } else {
- id = conn.toString();
- }
- if (response != null && this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(id + " << " + response.getStatusLine().toString());
- Header[] headers = response.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- this.headerlog.debug(id + " << " + headers[i].toString());
- }
- }
- }
super.responseReceived(conn);
}
View
18 ...asyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultClientAsyncConnection.java
@@ -26,13 +26,11 @@
*/
package org.apache.http.impl.nio.conn;
-import java.io.IOException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
-import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
import org.apache.http.nio.conn.ClientAsyncConnection;
@@ -84,15 +82,25 @@ public String getId() {
}
@Override
- public void submitRequest(final HttpRequest request) throws IOException, HttpException {
+ protected void onResponseReceived(HttpResponse response) {
+ if (response != null && this.headerlog.isDebugEnabled()) {
+ this.headerlog.debug(this.id + " << " + response.getStatusLine().toString());
+ Header[] headers = response.getAllHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ this.headerlog.debug(this.id + " << " + headers[i].toString());
+ }
+ }
+ }
+
+ @Override
+ protected void onRequestSubmitted(HttpRequest request) {
if (request != null && this.headerlog.isDebugEnabled()) {
this.headerlog.debug(this.id + " >> " + request.getRequestLine().toString());
Header[] headers = request.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
this.headerlog.debug(this.id + " >> " + headers[i].toString());
}
}
- super.submitRequest(request);
}
@Override
View
15 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
@@ -27,13 +27,11 @@
package org.apache.http.nio.client.methods;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
-import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
@@ -66,16 +64,11 @@ protected abstract void onCharReceived(
protected final void onEntityEnclosed(
final HttpEntity entity, final ContentType contentType) throws IOException {
this.contentType = contentType != null ? contentType : ContentType.DEFAULT_TEXT;
- try {
- String cs = this.contentType.getCharset();
- if (cs == null) {
- cs = HTTP.DEFAULT_CONTENT_CHARSET;
- }
- Charset charset = Charset.forName(cs);
- this.chardecoder = charset.newDecoder();
- } catch (UnsupportedCharsetException ex) {
- throw new UnsupportedEncodingException(this.contentType.getCharset());
+ Charset charset = this.contentType.getCharset();
+ if (charset == null) {
+ charset = HTTP.DEF_CONTENT_CHARSET;
}
+ this.chardecoder = charset.newDecoder();
this.bbuf = ByteBuffer.allocate(this.bufSize);
this.cbuf = CharBuffer.allocate(this.bufSize);
}
View
5 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
@@ -30,6 +30,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import org.apache.http.Consts;
import org.apache.http.HttpAsyncTestBase;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
@@ -173,7 +174,7 @@ public void handle(
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else {
response.setStatusCode(HttpStatus.SC_OK);
- NStringEntity entity = new NStringEntity("success", HTTP.ASCII);
+ NStringEntity entity = new NStringEntity("success", Consts.ASCII);
response.setEntity(entity);
}
response.setHeader(HTTP.CONN_DIRECTIVE,
@@ -427,7 +428,7 @@ public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
this.httpclient.setCredentialsProvider(credsProvider);
HttpPost httppost = new HttpPost("/");
- httppost.setEntity(new NStringEntity("some important stuff", HTTP.ISO_8859_1));
+ httppost.setEntity(new NStringEntity("some important stuff", Consts.ISO_8859_1));
Future<HttpResponse> future = this.httpclient.execute(target, httppost, null);
HttpResponse response = future.get();
View
4 ...lient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthenticationFallBack.java
@@ -29,6 +29,7 @@
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
+import org.apache.http.Consts;
import org.apache.http.HttpAsyncTestBase;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
@@ -59,7 +60,6 @@
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.ImmutableHttpProcessor;
@@ -161,7 +161,7 @@ public void handle(
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else {
response.setStatusCode(HttpStatus.SC_OK);
- StringEntity entity = new StringEntity("success", HTTP.ASCII);
+ StringEntity entity = new StringEntity("success", Consts.ASCII);
response.setEntity(entity);
}
}
View
4 ...asyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientReauthentication.java
@@ -30,6 +30,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.http.Consts;
import org.apache.http.HttpAsyncTestBase;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
@@ -61,7 +62,6 @@
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.ImmutableHttpProcessor;
@@ -168,7 +168,7 @@ public void handle(
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else {
response.setStatusCode(HttpStatus.SC_OK);
- StringEntity entity = new StringEntity("success", HTTP.ASCII);
+ StringEntity entity = new StringEntity("success", Consts.ASCII);
response.setEntity(entity);
}
}
View
10 ...asyncclient/src/test/java/org/apache/http/impl/nio/client/TestStatefulConnManagement.java
@@ -63,9 +63,9 @@
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.SyncBasicHttpContext;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -159,7 +159,7 @@ public Object getUserToken(final HttpContext context) {
HttpContext[] contexts = new HttpContext[workerCount];
HttpWorker[] workers = new HttpWorker[workerCount];
for (int i = 0; i < contexts.length; i++) {
- HttpContext context = new SyncBasicHttpContext();
+ HttpContext context = new BasicHttpContext();
Object token = Integer.valueOf(i);
context.setAttribute("user", token);
contexts[i] = context;
@@ -300,7 +300,7 @@ public Object getUserToken(final HttpContext context) {
HttpHost target = start(registry, null);
// Bottom of the pool : a *keep alive* connection to Route 1.
- HttpContext context1 = new SyncBasicHttpContext();
+ HttpContext context1 = new BasicHttpContext();
context1.setAttribute("user", "stuff");
Future<HttpResponse> future1 = this.httpclient.execute(
@@ -317,7 +317,7 @@ public Object getUserToken(final HttpContext context) {
// Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
// Send it to another route. Must be a keepalive.
- HttpContext context2 = new SyncBasicHttpContext();
+ HttpContext context2 = new BasicHttpContext();
Future<HttpResponse> future2 = this.httpclient.execute(
new HttpHost("127.0.0.1", target.getPort(), target.getSchemeName()),
@@ -337,7 +337,7 @@ public Object getUserToken(final HttpContext context) {
// So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
// The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
// When this happens, the RouteSpecificPool becomes empty.
- HttpContext context3 = new SyncBasicHttpContext();
+ HttpContext context3 = new BasicHttpContext();
Future<HttpResponse> future3 = this.httpclient.execute(
target, new HttpGet("/"), context3, null);
HttpResponse response3 = future3.get();
View
12 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
@@ -34,6 +34,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.http.Consts;
import org.apache.http.HttpAsyncTestBase;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
@@ -56,7 +57,6 @@
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.junit.After;
import org.junit.Assert;
@@ -219,7 +219,7 @@ public void testCharConsumer() throws Exception {
for (int i = 0; i < 5; i++) {
HttpAsyncRequestProducer httppost = HttpAsyncMethods.createPost(
target.toURI() + "/echo/stuff", s,
- ContentType.create("text/plain", HTTP.ASCII));
+ ContentType.create("text/plain", Consts.ASCII));
AsyncCharConsumer<String> consumer = new BufferingCharConsumer();
Future<String> future = this.httpclient.execute(httppost, consumer, null);
String result = future.get();
@@ -240,7 +240,7 @@ public void testCharConsumerSmallBufffer() throws Exception {
for (int i = 0; i < 5; i++) {
HttpAsyncRequestProducer httppost = HttpAsyncMethods.createPost(
target.toURI() + "/echo/stuff", s,
- ContentType.create("text/plain", HTTP.ASCII));
+ ContentType.create("text/plain", Consts.ASCII));
AsyncCharConsumer<String> consumer = new BufferingCharConsumer(512);
Future<String> future = this.httpclient.execute(httppost, consumer, null);
String result = future.get();
@@ -260,7 +260,7 @@ public void testResourceReleaseOnSuccess() throws Exception {
HttpAsyncRequestProducer httppost = HttpAsyncMethods.createPost(
target.toURI() + "/echo/stuff", s,
- ContentType.create("text/plain", HTTP.ASCII));
+ ContentType.create("text/plain", Consts.ASCII));
BufferingCharConsumer consumer = Mockito.spy(new BufferingCharConsumer());
Future<String> future = this.httpclient.execute(httppost, consumer, null);
String result = future.get();
@@ -274,7 +274,7 @@ public void testResourceReleaseOnException() throws Exception {
HttpHost target = start();
HttpAsyncRequestProducer httppost = HttpAsyncMethods.createPost(
target.toURI() + "/echo/stuff", "stuff",
- ContentType.create("text/plain", HTTP.ASCII));
+ ContentType.create("text/plain", Consts.ASCII));
AsyncCharConsumer<String> consumer = Mockito.spy(new BufferingCharConsumer());
Mockito.doThrow(new IOException("Kaboom")).when(consumer).onCharReceived(
Mockito.any(CharBuffer.class), Mockito.any(IOControl.class));
@@ -297,7 +297,7 @@ public void testResourceReleaseOnBuildFailure() throws Exception {
HttpHost target = start();
HttpAsyncRequestProducer httppost = HttpAsyncMethods.createPost(
target.toURI() + "/echo/stuff", "stuff",
- ContentType.create("text/plain", HTTP.ASCII));
+ ContentType.create("text/plain", Consts.ASCII));
BufferingCharConsumer consumer = Mockito.spy(new BufferingCharConsumer());
Mockito.doThrow(new HttpException("Kaboom")).when(consumer).buildResult(Mockito.any(HttpContext.class));
View
4 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
@@ -169,7 +169,7 @@ public void cleanUp() throws Exception {
private final boolean forceChunking;
protected TestZeroCopyPost(final String requestURI, final boolean forceChunking) {
- super(URI.create(requestURI), TEST_FILE, ContentType.create("text/plain", null));
+ super(URI.create(requestURI), TEST_FILE, ContentType.create("text/plain"));
this.forceChunking = forceChunking;
}
@@ -248,7 +248,7 @@ public void handle(
}
if (ok) {
NFileEntity responseEntity = new NFileEntity(TEST_FILE,
- ContentType.create("text/plian", null));
+ ContentType.create("text/plian"));
if (this.forceChunking) {
responseEntity.setChunked(true);
}
View
4 pom.xml
@@ -71,10 +71,10 @@
<maven.compile.target>1.5</maven.compile.target>
<maven.compile.optimize>true</maven.compile.optimize>
<maven.compile.deprecation>true</maven.compile.deprecation>
- <httpcore.version>4.2-beta1</httpcore.version>
+ <httpcore.version>4.2</httpcore.version>
<httpclient.version>4.2-beta1</httpclient.version>
<commons-logging.version>1.1.1</commons-logging.version>
- <commons-io.version>2.0.1</commons-io.version>
+ <commons-io.version>2.3</commons-io.version>
<junit.version>4.8.1</junit.version>
<mockito.version>1.8.5</mockito.version>
</properties>

0 comments on commit 23c0205

Please sign in to comment.