You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/10/01 16:30:15 UTC
svn commit: r1528103 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src:
examples/org/apache/http/examples/nio/client/
main/java/org/apache/http/impl/nio/client/
main/java/org/apache/http/nio/conn/ main/java/org/apache/http/nio/conn/ssl/
Author: olegk
Date: Tue Oct 1 14:30:15 2013
New Revision: 1528103
URL: http://svn.apache.org/r1528103
Log:
Fixed broken SSL tunneling setup; added authenticating proxy example
Added:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java (with props)
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/SchemeIOSessionStrategy.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ssl/SSLIOSessionStrategy.java
Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java?rev=1528103&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java (added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java Tue Oct 1 14:30:15 2013
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.examples.nio.client;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
+
+import java.util.concurrent.Future;
+
+/**
+ * This example demonstrates a basic asynchronous HTTP request / response exchange
+ * over a secure connection tunneled through an authenticating proxy.
+ */
+public class AsyncClientProxyAuthentication {
+
+ public static void main(String[] args)throws Exception {
+ CredentialsProvider credsProvider = new BasicCredentialsProvider();
+ credsProvider.setCredentials(
+ new AuthScope("someproxy", 8080),
+ new UsernamePasswordCredentials("username", "password"));
+ CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+ try {
+ httpclient.start();
+ HttpHost proxy = new HttpHost("someproxy", 8080);
+ RequestConfig config = RequestConfig.custom()
+ .setProxy(proxy)
+ .build();
+ HttpGet request = new HttpGet("https://issues.apache.org/");
+ request.setConfig(config);
+ Future<HttpResponse> future = httpclient.execute(request, null);
+ HttpResponse response = future.get();
+ System.out.println("Response: " + response.getStatusLine());
+ System.out.println("Shutting down");
+ } finally {
+ httpclient.close();
+ }
+ }
+
+}
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/examples/org/apache/http/examples/nio/client/AsyncClientProxyAuthentication.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java?rev=1528103&r1=1528102&r2=1528103&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java Tue Oct 1 14:30:15 2013
@@ -332,6 +332,14 @@ class MainClientExec implements Internal
final HttpClientContext localContext = state.getLocalContext();
final HttpResponse currentResponse = state.getCurrentResponse();
+ if (!state.isRouteEstablished()) {
+ final int status = currentResponse.getStatusLine().getStatusCode();
+ if (status == HttpStatus.SC_OK) {
+ state.setCurrentResponse(null);
+ return;
+ }
+ }
+
if (this.connReuseStrategy.keepAlive(currentResponse, localContext)) {
final long validDuration = this.keepaliveStrategy.getKeepAliveDuration(
currentResponse, localContext);
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/SchemeIOSessionStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/SchemeIOSessionStrategy.java?rev=1528103&r1=1528102&r2=1528103&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/SchemeIOSessionStrategy.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/SchemeIOSessionStrategy.java Tue Oct 1 14:30:15 2013
@@ -29,6 +29,8 @@ package org.apache.http.nio.conn;
import org.apache.http.HttpHost;
import org.apache.http.nio.reactor.IOSession;
+import java.io.IOException;
+
/**
* I/O session layering strategy for complex protocol schemes, which employ
* a transport level security protocol to secure HTTP communication
@@ -54,6 +56,6 @@ public interface SchemeIOSessionStrategy
* @param iosession the I/O session.
* @return upgraded I/O session.
*/
- IOSession upgrade(HttpHost host, IOSession iosession);
+ IOSession upgrade(HttpHost host, IOSession iosession) throws IOException;
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ssl/SSLIOSessionStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ssl/SSLIOSessionStrategy.java?rev=1528103&r1=1528102&r2=1528103&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ssl/SSLIOSessionStrategy.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ssl/SSLIOSessionStrategy.java Tue Oct 1 14:30:15 2013
@@ -27,6 +27,7 @@
package org.apache.http.nio.conn.ssl;
+import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
@@ -74,7 +75,7 @@ public class SSLIOSessionStrategy implem
this(sslcontext, new BrowserCompatHostnameVerifier());
}
- public SSLIOSession upgrade(final HttpHost host, final IOSession iosession) {
+ public SSLIOSession upgrade(final HttpHost host, final IOSession iosession) throws IOException {
Asserts.check(!(iosession instanceof SSLIOSession), "I/O session is already upgraded to TLS/SSL");
final SSLIOSession ssliosession = new SSLIOSession(
iosession,
@@ -95,6 +96,7 @@ public class SSLIOSessionStrategy implem
});
iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
+ ssliosession.initialize();
return ssliosession;
}