Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 43027 invoked from network); 20 Oct 2010 01:58:41 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 20 Oct 2010 01:58:41 -0000 Received: (qmail 62699 invoked by uid 500); 20 Oct 2010 01:58:41 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 62640 invoked by uid 500); 20 Oct 2010 01:58:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 62633 invoked by uid 99); 20 Oct 2010 01:58:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Oct 2010 01:58:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Oct 2010 01:58:38 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DEE9923889ED; Wed, 20 Oct 2010 01:57:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1024491 - in /cxf/branches/2.3.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports/http/src/main/resources/schemas/wsdl/ rt/transports/http/src/test/java/org/apache/cxf/transport/http/ Date: Wed, 20 Oct 2010 01:57:40 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101020015740.DEE9923889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Wed Oct 20 01:57:40 2010 New Revision: 1024491 URL: http://svn.apache.org/viewvc?rev=1024491&view=rev Log: Merged revisions 1024489 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1024489 | dkulp | 2010-10-19 21:52:33 -0400 (Tue, 19 Oct 2010) | 11 lines [CXF-2839] CXF HttpConduit doesn't read VM proxy settings Patch from Guillaume Sauthier applied * Add NonProxyHosts as a configuration parameter in HTTPConduit * Introduce PatternBuilder + TestCase * Only use Proxy when the hostname is not in the nonProxyHosts list * Directly map HTTPClientPolicy.nonProxyHosts as a Pattern * Use PatternBuilder as a JAXB Adapter * Introduce a systemProxyConfiguration in the HTTPConduit * Hopefully make the proxy selection code a little more readable * Use constants for HTTP proxy property names ........ Added: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/PatternBuilder.java - copied unchanged from r1024489, cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/PatternBuilder.java cxf/branches/2.3.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/PatternBuilderTest.java - copied unchanged from r1024489, cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/PatternBuilderTest.java Modified: cxf/branches/2.3.x-fixes/ (props changed) cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Wed Oct 20 01:57:40 2010 @@ -1 +1 @@ -/cxf/trunk:1-1022129,1022154,1022194,1022401-1022402,1022911,1023068,1023121,1023804,1023971-1023973,1024006,1024070,1024487 +/cxf/trunk:1-1022129,1022154,1022194,1022401-1022402,1022911,1023068,1023121,1023804,1023971-1023973,1024006,1024070,1024487,1024489 Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1024491&r1=1024490&r2=1024491&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original) +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Wed Oct 20 01:57:40 2010 @@ -44,6 +44,7 @@ import java.util.concurrent.ConcurrentHa import java.util.concurrent.Executor; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import javax.xml.namespace.QName; @@ -78,6 +79,7 @@ import org.apache.cxf.transport.https.Ce import org.apache.cxf.transport.https.CertConstraintsInterceptor; import org.apache.cxf.transport.https.CertConstraintsJaxBUtils; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; +import org.apache.cxf.transports.http.configuration.ProxyServerType; import org.apache.cxf.version.Version; import org.apache.cxf.workqueue.WorkQueueManager; import org.apache.cxf.ws.addressing.EndpointReferenceType; @@ -175,7 +177,23 @@ public class HTTPConduit * Endpoint Qname to give the configuration name of this conduit. */ private static final String SC_HTTP_CONDUIT_SUFFIX = ".http-conduit"; - + + /** + * JVM/System property name holding the hostname of the http proxy. + */ + private static final String HTTP_PROXY_HOST = "http.proxyHost"; + + /** + * JVM/System property name holding the port of the http proxy. + */ + private static final String HTTP_PROXY_PORT = "http.proxyPort"; + + /** + * JVM/System property name holding the list of hosts/patterns that + * should not use the proxy configuration. + */ + private static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts"; + /** * This field holds the connection factory, which primarily is used to * factor out SSL specific code from this implementation. @@ -212,11 +230,21 @@ public class HTTPConduit /** * This field holds the QoS configuration settings for this conduit. - * This field is injected via spring configuration based on the conduit + * This field is injected via spring configuration based on the conduit * name. */ private HTTPClientPolicy clientSidePolicy; - + + /** + * This field holds ONLY the static System proxy configuration: + * + http.proxyHost + * + http.proxyPort (default 8080) + * + http.nonProxyHosts (default null) + * It is initialized at the instance creation (and may be null + * if there is no appropriate System properties) + */ + private HTTPClientPolicy systemProxyConfiguration; + /** * This field holds the password authorization configuration. * This field is injected via spring configuration based on the conduit @@ -419,6 +447,28 @@ public class HTTPConduit } } + // Retrieve system properties (if any) + String proxyHost = System.getProperty(HTTP_PROXY_HOST); + if (proxyHost != null) { + // System is configured with a proxy, use it + + systemProxyConfiguration = new HTTPClientPolicy(); + systemProxyConfiguration.setProxyServer(proxyHost); + systemProxyConfiguration.setProxyServerType(ProxyServerType.HTTP); + + // 8080 is the default proxy port value as pert some documentation + String proxyPort = System.getProperty(HTTP_PROXY_PORT, "8080"); + systemProxyConfiguration.setProxyServerPort(Integer.valueOf(proxyPort)); + + // Load non proxy hosts + String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS); + if (!StringUtils.isEmpty(nonProxyHosts)) { + Pattern pattern = PatternBuilder.build(nonProxyHosts); + systemProxyConfiguration.setNonProxyHosts(pattern); + } + } + + // Get the correct URLConnection factory based on the // configuration. connectionFactory = retrieveConnectionFactory(getAddress()); @@ -502,7 +552,7 @@ public class HTTPConduit HTTPClientPolicy csPolicy = getClient(message); HttpURLConnectionFactory f = getConnectionFactory(currentURL); - HttpURLConnection connection = f.createConnection(getProxy(csPolicy), currentURL); + HttpURLConnection connection = f.createConnection(getProxy(csPolicy, currentURL), currentURL); connection.setDoOutput(true); long timeout = csPolicy.getConnectionTimeout(); @@ -1045,25 +1095,67 @@ public class HTTPConduit * * @return The proxy server or null, if not set. */ - private Proxy getProxy(HTTPClientPolicy policy) { - Proxy proxy = null; - if (policy != null - && policy.isSetProxyServer() - && !StringUtils.isEmpty(policy.getProxyServer())) { - proxy = new Proxy( - Proxy.Type.valueOf(policy.getProxyServerType().toString()), - new InetSocketAddress(policy.getProxyServer(), - policy.getProxyServerPort())); + private Proxy getProxy(HTTPClientPolicy policy, URL currentUrl) { + if (policy != null) { + // Maybe the user has provided some proxy information + if (policy.isSetProxyServer() + && !StringUtils.isEmpty(policy.getProxyServer())) { + return getProxy(policy, currentUrl.getHost()); + } else { + // There is a policy but no Proxy configuration, + // fallback on the system proxy configuration + return getSystemProxy(currentUrl.getHost()); + } + } else { + // Use system proxy configuration + return getSystemProxy(currentUrl.getHost()); + } + } + + /** + * Get the system proxy (if any) for the given URL's host. + */ + private Proxy getSystemProxy(String hostname) { + if (systemProxyConfiguration != null) { + return getProxy(systemProxyConfiguration, hostname); + } + + // No proxy configured + return null; + } + + /** + * Honor the nonProxyHosts property value (if set). + */ + private Proxy getProxy(final HTTPClientPolicy policy, final String hostname) { + if (policy.isSetNonProxyHosts()) { + + // Try to match the URL hostname with the exclusion pattern + Pattern pattern = policy.getNonProxyHosts(); + if (pattern.matcher(hostname).matches()) { + // Excluded hostname -> no proxy + return null; + } } - return proxy; + // Either nonProxyHosts is not set or the pattern did not match + return createProxy(policy); + } + + /** + * Construct a new {@code Proxy} instance from the given policy. + */ + private Proxy createProxy(final HTTPClientPolicy policy) { + return new Proxy(Proxy.Type.valueOf(policy.getProxyServerType().toString()), + new InetSocketAddress(policy.getProxyServer(), + policy.getProxyServerPort())); } /** * This call places HTTP Header strings into the headers that are relevant - * to the Authorization policies that are set on this conduit by + * to the Authorization policies that are set on this conduit by * configuration. *

- * An AuthorizationPolicy may also be set on the message. If so, those + * An AuthorizationPolicy may also be set on the message. If so, those * policies are merged. A user name or password set on the messsage * overrides settings in the AuthorizationPolicy is retrieved from the * configuration. @@ -1351,7 +1443,7 @@ public class HTTPConduit /** * This method sets the Trust Decider for this HTTP Conduit. - * Using this method overrides any trust decider configured for this + * Using this method overrides any trust decider configured for this * HTTPConduit. */ public void setTrustDecider(MessageTrustDecider decider) { @@ -1416,7 +1508,7 @@ public class HTTPConduit /** * This method performs a redirection retransmit in response to * a 302 or 305 response code. - * + * * @param connection The active URL connection * @param message The outbound message. * @param cachedStream The cached request. @@ -1620,7 +1712,7 @@ public class HTTPConduit connection.disconnect(); HTTPClientPolicy cp = getClient(message); - connection = getConnectionFactory(newURL).createConnection(getProxy(cp), newURL); + connection = getConnectionFactory(newURL).createConnection(getProxy(cp, newURL), newURL); connection.setDoOutput(true); // TODO: using Message context to deceided HTTP send properties connection.setConnectTimeout((int)cp.getConnectionTimeout()); Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb?rev=1024491&r1=1024490&r2=1024491&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb (original) +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb Wed Oct 20 01:57:40 2010 @@ -31,4 +31,20 @@ + + + + + + + + + + + + + + Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd?rev=1024491&r1=1024490&r2=1024491&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd (original) +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd Wed Oct 20 01:57:40 2010 @@ -349,6 +349,17 @@ + + + + Specifies the list of hostnames that will not use the proxy configuration. + Examples of value: + * "localhost" -> A single hostname + * "localhost|www.google.com" -> 2 hostnames that will not use the proxy configuration + * "localhost|www.google.*|*.apache.org" -> It's also possible to use a pattern-like value + + +