Client HTTP Transport (including SSL support)Page edited by Daniel KulpConfiguring SSL SupportTo configure your client to use SSL, you'll need to add an <http:conduit> definition to your XML configuration file. See the Configuration guide to learn how to supply your own XML configuration file to CXF. If you are already using Spring, this can be added to your existing beans definitions. A wsdl_first_https sample can be found in the CXF distribution with more detail. Also see this blog entry for another example. Here is a sample of what your conduit definition might look like: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xsi:schemaLocation=" http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <http:conduit name="{http://apache.org/hello_world}HelloWorld.http-conduit"> <http:tlsClientParameters> <sec:keyManagers keyPassword="password"> <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Morpit.jks"/> </sec:keyManagers> <sec:trustManagers> <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/> </sec:trustManagers> <sec:cipherSuitesFilter> <!-- these filters ensure that a ciphersuite with export-suitable or null encryption is used, but exclude anonymous Diffie-Hellman key change as this is vulnerable to man-in-the-middle attacks --> <sec:include>.*_EXPORT_.*</sec:include> <sec:include>.*_EXPORT1024_.*</sec:include> <sec:include>.*_WITH_DES_.*</sec:include> <sec:include>.*_WITH_NULL_.*</sec:include> <sec:exclude>.*_DH_anon_.*</sec:exclude> </sec:cipherSuitesFilter> </http:tlsClientParameters> <http:authorization> <sec:UserName>Betty</sec:UserName> <sec:Password>password</sec:Password> </http:authorization> <http:client AutoRedirect="true" Connection="Keep-Alive"/> </http:conduit> </beans> The first thing to notice is the "name" attribute on <http:conduit>. This allows CXF to associate this HTTP Conduit configuration with a particular WSDL Port. The name includes the service's namespace, the WSDL port name (as found in the wsdl:service section of the WSDL), and ".http-conduit". It follows this template: "{WSDL Namespace}portName.http-conduit". Note: it's the PORT name, not the service name. Thus, it's likely something like "MyServicePort", not "MyService". If you are having trouble getting the template to work, another (temporary) option for the name value is simply "*.http-conduit". Another option for the name attribute is a reg-ex _expression_ for the ORIGINAL URL of the endpoint. The configuration is matched at conduit creation so the address used in the WSDL or used for the JAX-WS Service.create(...) call can be used for the name. For example, you can do: <http:conduit name="http://localhost:8080/.*"> ...... </http:conduit> to configure a conduit for all interactions on localhost:8080. If you have multiple clients interacting with different services on the same server, this is probably the easiest way to configure it. Advanced ConfigurationHTTP client endpoints can specify a number of HTTP connection attributes including whether the endpoint automatically accepts redirect responses, whether the endpoint can use chunking, whether the endpoint will request a keep-alive, and how the endpoint interacts with proxies. A client endpoint can be configured using three mechanisms:
Using ConfigurationNamespaceThe elements used to configure an HTTP client are defined in the namespace http://cxf.apache.org/transports/http/configuration. It is commonly referred to using the prefix http-conf. In order to use the HTTP configuration elements you will need to add the lines shown below to the beans element of your endpoint's configuration file. In addition, you will need to add the configuration elements' namespace to the xsi:schemaLocation attribute. HTTP Consumer Configuration Namespace
<beans ...
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration
...
xsi:schemaLocation="...
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
...>
The conduit elementYou configure an HTTP client using the http-conf:conduit element and its children. The http-conf:conduit element takes a single attribute, name, that specifies the WSDL port element that corresponds to the endpoint. The value for the name attribute takes the form portQName.http-conduit. For example, the code below shows the http-conf:conduit element that would be used to add configuration for an endpoint that was specified by the WSDL fragment <port binding="widgetSOAPBinding" name="widgetSOAPPort> if the endpoint's target namespace was http://widgets.widgetvendor.net. http-conf:conduit Element ... <http-conf:conduit name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-conduit"> ... </http-conf:conduit> <http-conf:conduit name="*.http-conduit"> <!-- you can also using the wild card to specify the http-conduit that you want to configure --> ... </http-conf:conduit> ... The http-conf:conduit element has a number of child elements that specify configuration information. They are described below. See also Sun's JSSE Guide for more information on configuring SSL.
The client elementThe http-conf:client element is used to configure the non-security properties of a client's HTTP connection. Its attributes, described below, specify the connection's properties.
Example using the Client ElementThe example below shows a the configuration for an HTTP client that wants to keep its connection to the server open between requests, will only retransmit requests once per invocation, and cannot use chunking streams. HTTP Consumer Endpoint Configuration <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <http-conf:conduit name="{http://apache.org/hello_world_soap_http}SoapPort.http-conduit"> <http-conf:client Connection="Keep-Alive" MaxRetransmits="1" AllowChunking="false" /> </http-conf:conduit> </beans> Again, see the Configuration page for information on how to get CXF to detect your configuration file. The tlsClientParameters elementThe TLSClientParameters are listed here and here. A new feature starting in CXF 2.0.5 is the disableCNcheck attribute for this element. It defaults to false, indicating that the hostname given in the HTTPS URL will be checked against the service's Common Name (CN) given in its certificate during SOAP client requests, and failing if there is a mismatch. If set to true (not recommended for production use), such checks will be bypassed. That will allow you, for example, to use a URL such as localhost during development. Using WSDLNamespaceThe WSDL extension elements used to configure an HTTP client are defined in the namespace http://cxf.apache.org/transports/http/configuration. It is commonly referred to using the prefix http-conf. In order to use the HTTP configuration elements you will need to add the line shown below to the definitions element of your endpoint's WSDL document. HTTP Consumer WSDL Element's Namespace
<definitions ...
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration
The client elementThe http-conf:client element is used to specify the connection properties of an HTTP client in a WSDL document. The http-conf:client element is a child of the WSDL port element. It has the same attributes as the client element used in the configuration file. ExampleThe example below shows a WSDL fragment that configures an HTTP clientto specify that it will not interact with caches. WSDL to Configure an HTTP Consumer Endpoint <service ...> <port ...> <soap:address ... /> <http-conf:client CacheControl="no-cache" /> </port> </service> Using java codeHow to configure the HTTPConduit for the SOAP Client?First you need get the HTTPConduit from the Proxy object or Client, then you can set the HTTPClientPolicy, AuthorizationPolicy, ProxyAuthorizationPolicy, TLSClientParameters, and/or HttpBasicAuthSupplier. import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.transport.http.HTTPConduit; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; ... URL wsdl = getClass().getResource("wsdl/greeting.wsdl"); SOAPService service = new SOAPService(wsdl, serviceName); Greeter greeter = service.getPort(portName, Greeter.class); // Okay, are you sick of configuration files ? // This will show you how to configure the http conduit dynamically Client client = ClientProxy.getClient(greeter); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(36000); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setReceiveTimeout(32000); http.setClient(httpClientPolicy); ... greeter.sayHi("Hello"); How to override the service address ?If you are using JAXWS API to create the proxy obejct, here is an example which is complete JAX-WS compliant code
URL wsdlURL = MyService.class.getClassLoader
.getResource ("myService.wsdl");
QName serviceName = new QName("urn:myService", "MyService");
MyService service = new MyService(wsdlURL, serviceName);
ServicePort client = service.getServicePort();
BindingProvider provider = (BindingProvider)client;
// You can set the address per request here
provider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://my/new/url/to/the/service");
If you are using CXF ProxyFactoryBean to create the proxy object , you can do like this JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); poxyFactory.setServiceClass(ServicePort.class); // you could set the service address with this method proxyFactory.setAddress("theUrlyouwant"); ServicePort client = (ServicePort) proxyFactory.create(); Here is another way which takes advantage of JAXWS's Service.addPort() API URL wsdlURL = MyService.class.getClassLoader.getResource("service2.wsdl"); QName serviceName = new QName("urn:service2", "MyService"); QName portName = new QName("urn:service2", "ServicePort"); MyService service = new MyService(wsdlURL, serviceName); // You can add whatever address as you want service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "http://the/new/url/myService"); // Passing the SEI class that is generated by wsdl2java ServicePort proxy = service.getPort(portName, SEI.class); Client Cache Control DirectivesThe following table lists the cache control directives supported by an HTTP client.
A Note About ChunkingThere are two ways of putting a body into an HTTP stream:
In general, Chunked will perform better as the streaming can take place directly. HOWEVER, there are some problems with chunking:
If you are getting strang errors (generally not soap faults, but other HTTP type errors) when trying to interact with a service, try turning off chunking to see if that helps. NTLM AuthenticationCXF doesn't support NTLM authentication "out of the box", but with some additional libraries and configuration, the standard HttpURLConnection objects that we use can do the NTLM authentication. First, you need a library that will augment the HttpURLConnection to do it. See: http://jcifs.samba.org/src/docs/httpclient.html Note: jcifs is LGPL licensed, not Apache licensed. Next, you need to configure jcifs to use the correct domains, wins servers, etc... Notice that the //Set the jcifs properties jcifs.Config.setProperty("jcifs.smb.client.domain", "ben.com"); jcifs.Config.setProperty("jcifs.netbios.wins", "xxx.xxx.xxx.xxx"); jcifs.Config.setProperty("jcifs.smb.client.soTimeout", "300000"); //5 minutes jcifs.Config.setProperty("jcifs.netbios.cachePolicy", "1200"); //20 minutes //jcifs.Config.setProperty("jcifs.smb.client.username", "myNTLogin"); //jcifs.Config.setProperty("jcifs.smb.client.password", "secret"); //Register the jcifs URL handler to enable NTLM jcifs.Config.registerSmbURLHandler(); Finally, you need to setup the CXF client to turn off chunking. The reason is that the NTLM authentication requires a 3 part handshake which breaks the streaming. //Turn off chunking so that NTLM can occur Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(36000); httpClientPolicy.setAllowChunking(false); http.setClient(httpClientPolicy);
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache CXF Documentation > Client HTTP Transport (inc... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
- [CONF] Apache CXF Documentation > Client HTTP Transport... confluence
