You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/09/20 23:09:53 UTC
svn commit: r1388220 - in
/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient:
AsyncHTTPConduit.java CXFAsyncRequester.java
Author: dkulp
Date: Thu Sep 20 21:09:53 2012
New Revision: 1388220
URL: http://svn.apache.org/viewvc?rev=1388220&view=rev
Log:
Boost the performance a bit by using some singletons
Modified:
cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequester.java
Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1388220&r1=1388219&r2=1388220&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java Thu Sep 20 21:09:53 2012
@@ -378,10 +378,12 @@ public class AsyncHTTPConduit extends UR
protected synchronized HttpResponse getHttpResponse() throws IOException {
while (httpResponse == null) {
- try {
- wait(csPolicy.getReceiveTimeout());
- } catch (InterruptedException e) {
- throw new IOException(e);
+ if (exception == null) { //already have an exception, skip waiting
+ try {
+ wait(csPolicy.getReceiveTimeout());
+ } catch (InterruptedException e) {
+ throw new IOException(e);
+ }
}
if (httpResponse == null) {
outbuf.shutdown();
@@ -489,7 +491,7 @@ public class AsyncHTTPConduit extends UR
return new HttpsURLConnectionInfo(url, method, cipherSuite, localCerts, principal, serverCerts, peer);
}
- protected synchronized int getResponseCode() throws IOException {
+ protected int getResponseCode() throws IOException {
return getHttpResponse().getStatusLine().getStatusCode();
}
Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequester.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequester.java?rev=1388220&r1=1388219&r2=1388220&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequester.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequester.java Thu Sep 20 21:09:53 2012
@@ -35,8 +35,17 @@ import org.apache.http.ProtocolException
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.RequestAddCookies;
+import org.apache.http.client.protocol.RequestAuthCache;
+import org.apache.http.client.protocol.RequestClientConnControl;
+import org.apache.http.client.protocol.RequestDefaultHeaders;
+import org.apache.http.client.protocol.RequestProxyAuthentication;
+import org.apache.http.client.protocol.RequestTargetAuthentication;
+import org.apache.http.client.protocol.ResponseProcessCookies;
import org.apache.http.concurrent.BasicFuture;
import org.apache.http.concurrent.FutureCallback;
+import org.apache.http.impl.client.ProxyAuthenticationStrategy;
+import org.apache.http.impl.client.TargetAuthenticationStrategy;
import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
import org.apache.http.nio.conn.scheme.AsyncScheme;
@@ -49,16 +58,43 @@ import org.apache.http.params.HttpConnec
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.params.SyncBasicHttpParams;
+import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
public class CXFAsyncRequester {
private final ClientAsyncConnectionManager caConMan;
+
+ // these have per-instance Logger instances that have sync methods to setup.
+ private final TargetAuthenticationStrategy targetAuthenticationStrategy = new TargetAuthenticationStrategy();
+ private final ProxyAuthenticationStrategy proxyAuthenticationStrategy = new ProxyAuthenticationStrategy();
+ private final BasicHttpProcessor httpproc;
public CXFAsyncRequester(
ClientAsyncConnectionManager caConMan) {
super();
this.caConMan = caConMan;
+
+ httpproc = new BasicHttpProcessor();
+ httpproc.addInterceptor(new RequestDefaultHeaders());
+ // Required protocol interceptors
+ httpproc.addInterceptor(new RequestContent());
+ httpproc.addInterceptor(new RequestTargetHost());
+ // Recommended protocol interceptors
+ httpproc.addInterceptor(new RequestClientConnControl());
+ httpproc.addInterceptor(new RequestUserAgent());
+ httpproc.addInterceptor(new RequestExpectContinue());
+ // HTTP state management interceptors
+ httpproc.addInterceptor(new RequestAddCookies());
+ httpproc.addInterceptor(new ResponseProcessCookies());
+ // HTTP authentication interceptors
+ httpproc.addInterceptor(new RequestAuthCache());
+ httpproc.addInterceptor(new RequestTargetAuthentication());
+ httpproc.addInterceptor(new RequestProxyAuthentication());
}
public <T> Future<T> execute(
@@ -116,6 +152,10 @@ public class CXFAsyncRequester {
HttpConnectionParams.setSocketBufferSize(params, 16332);
return params;
}
+ @Override
+ protected BasicHttpProcessor createHttpProcessor() {
+ return httpproc;
+ }
};
context.setAttribute(ClientContext.SCHEME_REGISTRY, reg);
//CXF handles redirects ourselves
@@ -129,6 +169,9 @@ public class CXFAsyncRequester {
return null;
}
});
+ dhac.setTargetAuthenticationStrategy(targetAuthenticationStrategy);
+ dhac.setProxyAuthenticationStrategy(proxyAuthenticationStrategy);
+
dhac.execute(requestProducer, responseConsumer, context, callback);
return future;