This document covers the sending and receiving of SOAP messages with Axis2 using HTTP as the transport mechanism.
<transportSender name="http" class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> <parameter name="PROTOCOL">HTTP/1.1</parameter> <parameter name="Transfer-Encoding">chunked</parameter> </transportSender>The above code snippet shows the simplest configuration of a transport sender for common use. The <parameter/> element is used to specify additional constraints that the sender should comply with. The HTTP PROTOCOL parameter should be set as HTTP/1.0 or HTTP/1.1. The default version is HTTP/1.1. Note that chunking support is available only for HTTP/1.1. Thus, even if "chunked" is specified as a parameter, if the HTTP version is 1.0, this setting will be ignored by the transport framework. Also, KeepAlive is enabled by default in HTTP/1.1. If you use HTTP1.1 for its Keep-Alive ability, but you need to disable chunking at runtime (some servers don't allow chunked requests to prevent denial of service), you can do so in the Stub:
options.setProperty(HTTPConstants.CHUNKED, "false");Some absolute properties are provided at runtime instead. For example, character encoding style (UTF-8, UTF-16, etc.) is provided via MessageContext.
<transportSender name="https" class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> <parameter name="PROTOCOL">HTTP/1.1</parameter> <parameter name="Transfer-Encoding">chunked</parameter> </transportSender>Please note that by default HTTPS works only when the server does not expect to authenticate the clients (1-way SSL only) and where the server has the clients' public keys in its trust store. If you want to perform SSL client authentication (2-way SSL), you may use the Protocol.registerProtocol feature of HttpClient. You can overwrite the "https" protocol, or use a different protocol for your SSL client authentication communications if you don't want to mess with regular https. Find more information at http://jakarta.apache.org/commons/httpclient/sslguide.html
For Socket timeout:
<parameter name="SO_TIMEOUT">some_integer_value</parameter>
For Connection timeout:
<parameter name="CONNECTION_TIMEOUT">some_integer_value</parameter>
... Options options = new Options(); options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds)); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds)); // or options.setTimeOutInMilliSeconds(timeOutInMilliSeconds); ...
The default HTTP version is 1.1. There are two methods in which the user can change the HTTP version to 1.0
<parameter name="PROTOCOL">HTTP/1.0</parameter>
... options.setProperty(org.apache.axis2.context.MessageContextConstants.HTTP_PROTOCOL_VERSION, org.apache.axis2.transport.http.HTTPConstants.HEADER_PROTOCOL_10); ...
<transportSender name="http" class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> <parameter name="PROTOCOL">HTTP/1.1</parameter> <parameter name="PROXY" proxy_host="proxy_host_name" proxy_port="proxy_host_port" >userName:domain:passWord</parameter> </transportSender>For a particular proxy, if authentication is not available, enter the "userName:domain:passWord" as "anonymous:anonymous:anonymous".
At runtime, the user can override the PROXY settings using the HttpTransportProperties.ProxyProperties object. Within your client stub, create an instance of this object, configure proxy values for it, and then set it to the MessageContext's property bag via options.setProperty(). For example:
... Options options = new Options(); ... HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.new ProxyProperties(); proxyProperties.setProxyHostName(....); proxyProperties.setProxyPort(...); ... options.setProperty(HttpConstants.PROXY, proxyProperties); ...
The above code will override the deployment proxy configuration settings.
HttpClient supports three different types of HTTP authentication schemes: Basic, Digest and NTLM. Based on the challenge provided by the server, HttpClient automatically selects the authentication scheme with which the request should be authenticated. The most secure method is NTLM and the Basic is the least secure.
NTLM is the most complex of the authentication protocols supported by HttpClient. It requires an instance of NTCredentials to be available for the domain name of the server or the default credentials. Note that since NTLM does not use the notion of realms, HttpClient uses the domain name of the server as the name of the realm. Also note that the username provided to the NTCredentials should not be prefixed with the domain - ie: "axis2" is correct whereas "DOMAIN\axis2" is not correct.
There are some significant differences in the way that NTLM works compared with basic and digest authentication. These differences are generally handled by HttpClient, however having an understanding of these differences can help avoid problems when using NTLM authentication.
... Options options = new Options(); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername("username"); auth.setPassword("password"); // set if realm or domain is known options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); ...
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
MultiThreadedHttpConnectionManager conmgr = new MultiThreadedHttpConnectionManager(); conmgr.getParams().setDefaultMaxConnectionsPerHost(10); HttpClient client = new HttpClient(conmgr); configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);