Author: cschneider
Date: Mon Nov 15 23:39:35 2010
New Revision: 1035487
URL: http://svn.apache.org/viewvc?rev=1035487&view=rev
Log:
Remove dependency cycle with config and move proxy logic out of HTTPConduit
Added:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
(with props)
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ClientOnlyHTTPTransportFactory.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java?rev=1035487&r1=1035486&r2=1035487&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
Mon Nov 15 23:39:35 2010
@@ -123,6 +123,7 @@ public abstract class AbstractHTTPTransp
protected void configure(Object bean) {
configure(bean, null, null);
}
+
protected void configure(Object bean, String name, String extraName) {
Configurer configurer = bus.getExtension(Configurer.class);
if (null != configurer) {
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ClientOnlyHTTPTransportFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ClientOnlyHTTPTransportFactory.java?rev=1035487&r1=1035486&r2=1035487&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ClientOnlyHTTPTransportFactory.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ClientOnlyHTTPTransportFactory.java
Mon Nov 15 23:39:35 2010
@@ -22,7 +22,6 @@ import java.io.IOException;
import javax.annotation.Resource;
-
import org.apache.cxf.Bus;
import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.service.model.EndpointInfo;
@@ -60,9 +59,7 @@ public class ClientOnlyHTTPTransportFact
EndpointInfo endpointInfo,
EndpointReferenceType target
) throws IOException {
- HTTPConduit conduit = target == null
- ? new HTTPConduit(bus, endpointInfo)
- : new HTTPConduit(bus, endpointInfo, target);
+ HTTPConduit conduit = new HTTPConduit(bus, endpointInfo, target);
// Spring configure the conduit.
String address = conduit.getAddress();
if (address != null && address.indexOf('?') != -1) {
@@ -72,5 +69,5 @@ public class ClientOnlyHTTPTransportFact
conduit.finalizeConfig();
return conduit;
}
-
+
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1035487&r1=1035486&r2=1035487&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Mon Nov 15 23:39:35 2010
@@ -27,9 +27,7 @@ import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
-import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@@ -44,7 +42,6 @@ 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;
@@ -52,7 +49,6 @@ import org.apache.cxf.Bus;
import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.configuration.Configurable;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
@@ -79,7 +75,6 @@ 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;
@@ -179,22 +174,6 @@ public class HTTPConduit
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.
* <p>
@@ -225,6 +204,8 @@ public class HTTPConduit
private URL defaultEndpointURL;
private String defaultEndpointURLString;
private boolean fromEndpointReferenceType;
+
+ private ProxyFactory proxyFactory;
// Configurable values
@@ -236,16 +217,6 @@ public class HTTPConduit
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
* name.
@@ -323,7 +294,7 @@ public class HTTPConduit
if (t != null) {
fromEndpointReferenceType = true;
}
-
+ proxyFactory = new ProxyFactory();
initializeConfig();
CXFAuthenticator.addAuthenticator();
}
@@ -362,6 +333,37 @@ public class HTTPConduit
}
+ private static void configureConduitFromEndpointInfo(HTTPConduit conduit,
+ EndpointInfo endpointInfo) {
+ if (conduit.getClient() == null) {
+ conduit.setClient(endpointInfo.getTraversedExtensor(
+ new HTTPClientPolicy(), HTTPClientPolicy.class));
+ }
+ if (conduit.getAuthorization() == null) {
+ conduit.setAuthorization(endpointInfo.getTraversedExtensor(
+ new AuthorizationPolicy(), AuthorizationPolicy.class));
+
+ }
+ if (conduit.getProxyAuthorization() == null) {
+ conduit.setProxyAuthorization(endpointInfo.getTraversedExtensor(
+ new ProxyAuthorizationPolicy(),
+ ProxyAuthorizationPolicy.class));
+
+ }
+ if (conduit.getTlsClientParameters() == null) {
+ conduit.setTlsClientParameters(endpointInfo.getTraversedExtensor(
+ null, TLSClientParameters.class));
+ }
+ if (conduit.getTrustDecider() == null) {
+ conduit.setTrustDecider(endpointInfo.getTraversedExtensor(null,
+ MessageTrustDecider.class));
+ }
+ if (conduit.getAuthSupplier() == null) {
+ conduit.setAuthSupplier(endpointInfo.getTraversedExtensor(null,
+ HttpAuthSupplier.class));
+ }
+ }
+
/**
* This call gets called by the HTTPTransportFactory after it
* causes an injection of the Spring configuration properties
@@ -371,32 +373,8 @@ public class HTTPConduit
// See if not set by configuration, if there are defaults
// in order from the Endpoint, Service, or Bus.
- if (this.clientSidePolicy == null) {
- clientSidePolicy = endpointInfo.getTraversedExtensor(
- new HTTPClientPolicy(), HTTPClientPolicy.class);
- }
- if (this.authorizationPolicy == null) {
- authorizationPolicy = endpointInfo.getTraversedExtensor(
- new AuthorizationPolicy(), AuthorizationPolicy.class);
-
- }
- if (this.proxyAuthorizationPolicy == null) {
- proxyAuthorizationPolicy = endpointInfo.getTraversedExtensor(
- new ProxyAuthorizationPolicy(),
ProxyAuthorizationPolicy.class);
-
- }
- if (this.tlsClientParameters == null) {
- tlsClientParameters = endpointInfo.getTraversedExtensor(
- null, TLSClientParameters.class);
- }
- if (this.trustDecider == null) {
- trustDecider = endpointInfo.getTraversedExtensor(
- null, MessageTrustDecider.class);
- }
- if (this.authSupplier == null) {
- authSupplier = endpointInfo.getTraversedExtensor(
- null, HttpAuthSupplier.class);
- }
+ configureConduitFromEndpointInfo(this, endpointInfo);
+
if (trustDecider == null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE,
@@ -447,28 +425,6 @@ 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());
@@ -552,7 +508,8 @@ public class HTTPConduit
HTTPClientPolicy csPolicy = getClient(message);
HttpURLConnectionFactory f = getConnectionFactory(currentURL);
- HttpURLConnection connection = f.createConnection(getProxy(csPolicy,
currentURL), currentURL);
+ HttpURLConnection connection =
f.createConnection(proxyFactory.createProxy(csPolicy, currentURL),
+ currentURL);
connection.setDoOutput(true);
long timeout = csPolicy.getConnectionTimeout();
@@ -1090,67 +1047,6 @@ public class HTTPConduit
}
/**
- * This method returns the Proxy server should it be set on the
- * Client Side Policy.
- *
- * @return The proxy server or null, if not set.
- */
- 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;
- }
- }
- // 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
* configuration.
@@ -1712,7 +1608,8 @@ public class HTTPConduit
connection.disconnect();
HTTPClientPolicy cp = getClient(message);
- connection =
getConnectionFactory(newURL).createConnection(getProxy(cp, newURL), newURL);
+ connection =
getConnectionFactory(newURL).createConnection(proxyFactory.createProxy(cp,
newURL),
+ newURL);
connection.setDoOutput(true);
// TODO: using Message context to deceided HTTP send properties
connection.setConnectTimeout((int)cp.getConnectionTimeout());
Added:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java?rev=1035487&view=auto
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
(added)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
Mon Nov 15 23:39:35 2010
@@ -0,0 +1,145 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.transport.http;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.util.regex.Pattern;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.transports.http.configuration.ProxyServerType;
+
+public class ProxyFactory {
+ /**
+ * 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 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;
+
+ public ProxyFactory() {
+ this.systemProxyConfiguration = createSystemProxyConfiguration();
+ }
+
+ private static HTTPClientPolicy createSystemProxyConfiguration() {
+ // Retrieve system properties (if any)
+ HTTPClientPolicy systemProxyConfiguration = null;
+ 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 per 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)) {
+ systemProxyConfiguration.setNonProxyHosts(nonProxyHosts);
+ }
+ }
+ return systemProxyConfiguration;
+ }
+
+ /**
+ * This method returns the Proxy server should it be set on the
+ * Client Side Policy.
+ *
+ * @return The proxy server or null, if not set.
+ */
+ public Proxy createProxy(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 = PatternBuilder.build(policy.getNonProxyHosts());
+ if (pattern.matcher(hostname).matches()) {
+ // Excluded hostname -> no proxy
+ return null;
+ }
+ }
+ // 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()));
+ }
+}
Propchange:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb?rev=1035487&r1=1035486&r2=1035487&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb
(original)
+++ cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xjb
Mon Nov 15 23:39:35 2010
@@ -32,19 +32,4 @@
<jaxb:class implClass="org.apache.cxf.wsdl.TExtensibilityElementImpl"/>
</jaxb:bindings>
- <!-- Map HTTPClientPolicy.nonProxyHosts to a Pattern using our own
'Adapter' -->
- <jaxb:bindings schemaLocation="http-conf.xsd"
- node="xs:complexty...@name='HTTPClientPolicy']">
- <jaxb:bindings node="xs:complexContent/xs:extension">
- <jaxb:bindings node="xs:attribu...@name='NonProxyHosts']">
- <jaxb:property>
- <jaxb:baseType>
- <jaxb:javaType name="java.util.regex.Pattern"
-
parseMethod="org.apache.cxf.transport.http.PatternBuilder.build" />
- </jaxb:baseType>
- </jaxb:property>
- </jaxb:bindings>
- </jaxb:bindings>
- </jaxb:bindings>
-
</jaxb:bindings>
Modified:
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java?rev=1035487&r1=1035486&r2=1035487&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
(original)
+++
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
Mon Nov 15 23:39:35 2010
@@ -177,13 +177,13 @@ public class HTTPConduitTest extends Ass
}
/**
- * This test verifies the precidence of Authorization Information.
- * Setting authorization information on the Message takes precidence
+ * This test verifies the precedence of Authorization Information.
+ * Setting authorization information on the Message takes precedence
* over a Basic Auth Supplier with preemptive UserPass, and that
* followed by setting it directly on the Conduit.
*/
@Test
- public void testAuthPolicyPrecidence() throws Exception {
+ public void testAuthPolicyPrecedence() throws Exception {
Bus bus = new CXFBusImpl();
EndpointInfo ei = new EndpointInfo();
ei.setAddress("http://nowhere.com/bar/foo");