...
Warning |
---|
At the moment, cxf-rt-transports-http-hc5 transport does not support OSGi based deployments |
This client transport supports HTTP/2.
Using the HTTP Components 4.x/5.x Transport from Java Code
...
Code Block | ||
---|---|---|
| ||
Bus bus = BusFactory.getDefaultBus(); // insist on the async connector to use PATCH. bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); // allows the async connector to use HTTP/2 protocol (if supported by the server) bus.setProperty(AsyncHTTPConduit.ENABLE_HTTP2, enableHttp2); |
Setting Credentials
The "normal" CXF/JAX-WS method of setting user credentials via the BindingProvider.USERNAME_PROPERTY/PASSWORD_PROPERTY will work with the Async transport as well. However, the HttpAsyncClient library does have some additional capabilities around NTLM that can be leveraged. In order to use that, you need to:
- Turn on the AutoRedirect and turn off the Chunking for the Conduit. This will allow CXF to cache the response in a manner that will allow the transport to keep resending the request during the authentication negotiation.
Force the use of the Async transport even for synchronous calls
Code Block java java bp.getRequestContext().put("use.async.http.conduit", Boolean.TRUE); bp.getRequestContext().put("org.apache.cxf.transports.http2.enabled", Boolean.TRUE); // optionally, enable HTTP/2
or using AsyncHTTPConduit.USE_ASYNC constant
Code Block java java bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); bp.getRequestContext().put(AsyncHTTPConduit.ENABLE_HTTP2, Boolean.TRUE); // optionally, enable HTTP/2
Set the property "org.apache.http.auth.Credentials" to an instance of the Credentials. For example:
Code Block java java Credentials creds = new NTCredentials("username", "pswd", null, "domain"); bp.getRequestContext().put(Credentials.class.getName(), creds);
Netty 4.x
This client transport supports HTTP/2.
Configuration
The Asynchronous HTTP Transport has several options that can set using Bus properties or via the OSGi configuration services to control various aspects of the underlying Apache HTTP Components HttpAsyncClient objects.
...
org.apache.cxf.transport.http.async.CONNECTION_TTL | Maximum time a connection to live(from creation to expiry) . Default is 60000. |
org.apache.cxf.transport.http.async.MAX_CONNECTIONS | Maximum number of connections opened in total. Default is 5000. |
org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS | Maximum number of connections opened per host. Default is 1000. |
Settings related to HTTP/2 support (Apache CXF versions 4.0.2+/3.6.1+/3.5.7+/3.4.11+):
org.apache.cxf.transports.http2.enabled | true | false | Allows HTTP/2 protocol if supported by the server. Default is false. |
Settings related to Apache HttpAsyncClient threads and selectors:
...