Submitted on August 1, 2006 - 01:57.
Apache Axis2 client API, which mainly includes ServiceClient or OperationClient, provides easy to use methods for users to send and receive SOAP and REST messages. This API has methods to get/set frequently used parameters. But in addition to that, there are a number of optional parameters that a user can set. Client API does not provide methods for each of these parameter, but user can set those as properties using the Options object that you pass in to the ServiceClient or OperationClient. These parameters helps the users to tweak Apache Axis2 client side engine's internal settings while sending and receiving messages. All these should be set through the client API using setProperty() method of the Options object that you pass in.
Options options = new Options();
options.setProperty(propertyName, propertyValue);
ServiceClient serviceClient = new ServiceClient();
sender.setOptions(options);
Now let's have a quick look at the different parameters available in Axis2 engine.
| Category | Constant | Possible Values |
| Generic Constants | Constants.Configuration.TRANSPORT_URL | any URL |
| Constants.Configuration. CHARACTER_SET_ENCODING | Character set encoding scheme as a String | |
| Constants.Configuration.ENABLE_MTOM |
"true"/"false"or Boolean.TRUE/Boolean.FALSE |
|
| WS-Addressing module specific constants | AddressingConstants. WS_ADDRESSING_VERSION |
org.apache.axis2.addressing. |
| AddressingConstants. REPLACE_ADDRESSING_HEADERS |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
|
| AddressingConstants. DISABLE_ADDRESSING_FOR_OUT_MESSAGES |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
|
| HTTP Constants | HTTPConstants.CHUNKED |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
| HTTPConstants.NTLM_AUTHENTICATION | an instance of
org.apache.axis2.transport.http. |
|
| HTTPConstants.PROXY | an instance of
org.apache.axis2.transport.http. |
|
| HTTPConstants.BASIC_AUTHENTICATION | an instance of
org.apache.axis2.transport.http. |
|
| HTTPConstants.SO_TIMEOUT | Integer | |
| HTTPConstants.CONNECTION_TIMEOUT | Integer | |
| HTTPConstants.USER_AGENT | String | |
| HTTPConstants.MC_GZIP_REQUEST |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
|
| HTTPConstants.MC_ACCEPT_GZIP |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
|
| HTTPConstants.COOKIE_STRING | String | |
| HTTPConstants.HTTP_PROTOCOL_VERSION |
|
|
| HTTPConstants.HTTP_HEADERS | ArrayList of org.apache.commons.httpclient.Header objects | |
| HTTPConstants.REUSE_HTTP_CLIENT |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
|
| HTTPConstants.CACHED_HTTP_CLIENT |
org.apache.commons.httpclient.HttpClient |
|
| Constants to be used in a REST invocation | Constants.Configuration.ENABLE_REST |
"true"/"false" or Boolean.TRUE/Boolean.FALSE |
| Constants.Configuration.HTTP_METHOD |
org.apache.axis2.Constants.Configuration. |
|
| Constants.Configuration.CONTENT_TYPE |
|
Now let's see what each of these parameters mean and what they can tweak inside Axis2
Sometimes you want to send your SOAP message through a node, before it reaches to its destination. This means you want to give transport URL different from the URL of the ultimate destination. A typical example would be wanting to send this SOAP (or REST)message through a transparent proxy or through a message monitoring applet. How can that be done using the ServiceClient API?
options.setTo("http://destination.org");
options.setProperty(MessageContextConstants.TRANSPORT_URL, "http://myProxy.org");
This will send your SOAP message to "http://myProxy.org", but if WS-Addressing is enabled, wsa:To will contain "http://destination.org" as To address.
This will enable user to set the character set encoding scheme to be used when sending the message. Default is set to "UTF-8"
This will enable/disable MTOM support for outgoing messages. Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
This will enable to select one of the two WS-Addressing versions available, if WS-Addressing is engaged. Possible values are:
org.apache.axis2.addressing.AddressingConstants.Final.WSA_NAMESPACE
and
org.apache.axis2.addressing.AddressingConstants.Submission.WSA_NAMESPACE
AddressingOutHandler picks up the addressing information from the message context and set them to the outgoing message. But someone may have already put some addressing headers, before the AddressingOutHandler. This flag will notify the handler whether to override them or not. Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
If WS-Addressing is engaged globally or some how in effect for this particular invocation, this will disable Axis2 from putting WS-Addressing headers in to the out going SOAP message. (Note that Axis2 will not put addressing headers to the outgoing message, irrespective of the above flag, if the incoming message did not contain addressing headers). Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
This will enable/disable chunking support. Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
This enables the user to pass in NTLM authentication information, such as host, port, realm, username, password to be used with HTTP transport sender. The value should always be an instance of:
org.apache.axis2.transport.http.HttpTransportProperties.
NTLMAuthentication
This enables the user to pass in proxy information, such as proxy host name, port, domain, username, password to be used with HTTP transport sender. The value should always be an instance of:
org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties
This enables the user to pass in basic authentication information, such as host, port, realm, username, password to be used with HTTP transport sender. The value should always be an instance of:
org.apache.axis2.transport.http.HttpTransportProperties.BasicAuthentication
This enables the user to pass in socket timeout value as an Integer. If nothing is set, the default value is 60000 milli seconds.
This enables the user to pass in connection timeout value as an Integer. If nothing is set, the default value is 60000 milli seconds.
This enables the user to set the user agent header in the outgoing HTTP request. Default value is "Axis2"
If set this will GZip your request and send over to the destination. Before doing this, you must make sure that the receiving end supports GZip compressed streams.
Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
Whether or not you send a gzip-ped request, you can choose to receive GZIP back from the server using this flag. Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
This enables the user to set the cookie string header in the outgoing HTTP request.
This will set the HTTP protocol version to be used in sending the SOAP requests. Possible values are :
HTTP/1.1 - HTTPConstants.HEADER_PROTOCOL_11
HTTP/1.0 - HTTPConstants.HEADER_PROTOCOL_10
Default is to use HTTP/1.1.
You might sometimes want to send your own custom HTTP headers. You can set an ArrayList filled with
org.apache.commons.httpclient.Header
objects using the above property. You must not try to override the Headers the Axis2 engine is setting to the outgoing message.
You might want to use the same HTTPClient instance for multiple invocations. This flag will notify the engine to use the same HTTPClient between invocations.
If user had requested to re-use an HTTPClient using the above property, this property can be used to set a custom HTTPClient to be re-used.
Enabling REST using the above flag will send your request as a REST invocation. Possible values are:
"true"/"false" or Boolean.TRUE/Boolean.FALSE
This will help the user to pick the HTTP method to be used during a REST invocation. Possible values are :
org.apache.axis2.Constants.Configuration.HTTP_METHOD_GET
and
org.apache.axis2.Constants.Configuration.HTTP_METHOD_POST
Default is to use POST method.
This will help the user to pick the content type to be used during a REST invocation. Possible values are :
HTTPConstants.MEDIA_TYPE_APPLICATION_XML
HTTPConstants.MEDIA_TYPE_X_WWW_FORM
MEDIA_TYPE_TEXT_XML
MEDIA_TYPE_MULTIPART_RELATED
The properties mentioned above helps user to gain control in message sending and receiving process. And at the same time it helps to maintain a much cleaner API, rather than having two methods, to set and get, for each and every property.
Ok, I tweaked the Axis2 engine using one or more of the above parameters, but how can I know whether those actually work? Look no further than the next setion.
It's pretty much easy. You need to channel all your messages through TCPMon (It's a TCP packet sniffer which you can be used to watch message exchanges). This will show you the way to setup TCPMon for the above task.
Then modify your TO EPR, which you pass in to OperationClient or ServiceClient constructor, to send your messages through the TCPMon. Thats it !!
You set the parameters to the Options object. When you invoke the Web service though the client API, this option get registered with the message context that is being created. MessageContext is a construct within Axis2, which holds all the information about a particular message (Refer Apache Axis2 Architecture Guide if you want to understand what message context means).
When handlers are invoked they get access to the message context along with all the properties you set. This is how properties are passed in to the AddressingHandler.
When you pass HTTP parameters, they are used within the HTTP transport sender (which most of the time is org.apache.axis2.transport.http.CommonsHTTPTransportSender. This is a special type of a handler which sits at the end of the handler chain.
Project/Language : Apache Axis2 /Java 1.0
Environment : JDK 1.4 or later
Eran Chinthaka, Senior Software Engineer, WSO2 Inc.chinthaka at wso2 dot com
Is there a HTTPConstants.HTTP_HEADERS in Axis2?
Hi,
I cut and paste the HTTPConstants.java with Axis2 1.0 release, it
seems that there is no HTTP_HEADERS constant in the source code:
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed 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.axis2.transport.http;
import java.io.UnsupportedEncodingException;
/**
* HTTP protocol and message context constants.
*/
public class HTTPConstants {
public static final String HTTP_CONTENT_TYPE = "HTTP_CONTENT_TYPE";
public static final String PROTOCOL_VERSION = "PROTOCOL";
public static final String MEDIA_TYPE_X_WWW_FORM =
"application/x-www-form-urlencoded";
public static final String MEDIA_TYPE_TEXT_XML = "text/xml";
public static final String MEDIA_TYPE_MULTIPART_RELATED = "multipart/related";
public static final String MEDIA_TYPE_APPLICATION_XML = "application/xml";
public static final String MEDIA_TYPE_APPLICATION_SOAP_XML = "application/soap+xml";
/**
* Field REQUEST_URI
*/
public static final String REQUEST_URI = "REQUEST_URI";
/**
* Field RESPONSE_CODE
*/
public static final String RESPONSE_CODE = "RESPONSE_CODE";
/**
* Field RESPONSE_WORD
*/
public static final String RESPONSE_WORD = "RESPONSE_WORD";
/**
* Field RESPONSE_ACK_CODE_VAL
*/
public static final String RESPONSE_ACK_CODE_VAL = "202";
/**
* Field SOCKET
*/
public static final String SOCKET = "SOCKET";
/**
* Field RESPONSE_HEADERS
*/
public static final String RESPONSE_HEADERS = "HTTP-Response-Headers";
/**
* Field REQUEST_HEADERS
*/
public static final String REQUEST_HEADERS = "HTTP-Request-Headers";
/**
* Field PLUGIN_WRITER
*/
public static final String PLUGIN_WRITER = "transport.http.plugin.writer";
/**
* Field PLUGIN_SERVICE_NAME
*/
public static final String PLUGIN_SERVICE_NAME = "transport.http.plugin.serviceName";
/**
* AXIS servlet plugin parameter names.
*/
public static final String PLUGIN_NAME = "transport.http.plugin.pluginName";
/**
* Field PLUGIN_LOG
*/
public static final String PLUGIN_LOG = "transport.http.plugin.log";
/**
* Field PLUGIN_IS_DEVELOPMENT
*/
public static final String PLUGIN_IS_DEVELOPMENT = "transport.http.plugin.isDevelopment";
/**
* Field PLUGIN_EXCEPTION_LOG
*/
public static final String PLUGIN_EXCEPTION_LOG = "transport.http.plugin.exceptionLog";
/**
* Field PLUGIN_ENGINE
*/
public static final String PLUGIN_ENGINE = "transport.http.plugin.engine";
/**
* Field PLUGIN_ENABLE_LIST
*/
public static final String PLUGIN_ENABLE_LIST = "transport.http.plugin.enableList";
/**
* Field OK[]
*/
public static final char OK[] = ("200 OK").toCharArray();
/**
* Field NOCONTENT[]
*/
public static final byte NOCONTENT[] = ("202 OK\n\n").getBytes();
/**
* Field MC_HTTP_STATUS_MESSAGE
*/
public static String MC_HTTP_STATUS_MESSAGE = "transport.http.statusMessage";
/**
* Field MC_HTTP_STATUS_CODE
*/
public static String MC_HTTP_STATUS_CODE = "transport.http.statusCode";
/**
* Field MC_HTTP_SERVLETRESPONSE
*/
public static String MC_HTTP_SERVLETRESPONSE = "transport.http.servletResponse";
/**
* Field MC_HTTP_SERVLETREQUEST
*/
public static String MC_HTTP_SERVLETREQUEST = "transport.http.servletRequest";
/**
* Field MC_HTTP_SERVLETPATHINFO
*/
public static String MC_HTTP_SERVLETPATHINFO = "transport.http.servletPathInfo";
/**
* Field MC_HTTP_SERVLETLOCATION
*/
public static String MC_HTTP_SERVLETLOCATION = "transport.http.servletLocation";
/**
* Field MC_HTTP_SERVLET
*/
public static String MC_HTTP_SERVLET = "transport.http.servlet";
/**
* Field HEADER_USER_AGENT
*/
public static final String HEADER_USER_AGENT = "User-Agent";
/**
* Field HEADER_TRANSFER_ENCODING_CHUNKED
*/
public static final String HEADER_TRANSFER_ENCODING_CHUNKED = "chunked".intern();
/* http 1.1 */
/**
* Field HEADER_TRANSFER_ENCODING
*/
public static final String HEADER_TRANSFER_ENCODING = "Transfer-Encoding".intern();
/**
* Field HEADER_SOAP_ACTION
*/
public static final String HEADER_SOAP_ACTION = "SOAPAction";
/**
* Field HEADER_SET_COOKIE2
*/
public static final String HEADER_SET_COOKIE2 = "Set-Cookie2";
/**
* Field HEADER_SET_COOKIE
*/
public static final String HEADER_SET_COOKIE = "Set-Cookie";
/**
* Field HEADER_PROXY_AUTHORIZATION
*/
public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization";
/**
* Field HEADER_PROTOCOL_V11
*/
public static final String HEADER_PROTOCOL_V11 = "1.1".intern();
/**
* Field HEADER_PROTOCOL_V10
*/
public static final String HEADER_PROTOCOL_V10 = "1.0".intern();
/**
* Field HEADER_PROTOCOL_11
*/
public static final String HEADER_PROTOCOL_11 = "HTTP/1.1";
/**
* Field HEADER_PROTOCOL_10
*/
public static final String HEADER_PROTOCOL_10 = "HTTP/1.0";
/**
* Field HEADER_PRAGMA
*/
public static final String HEADER_PRAGMA = "Pragma";
/**
* Field HEADER_POST
*/
public static final String HEADER_POST = "POST";
/**
* Field HEADER_LOCATION
*/
public static final String HEADER_LOCATION = "Location";
/**
* Field HEADER_HOST
*/
public static final String HEADER_HOST = "Host";
/**
* Field HEADER_GET
*/
public static final String HEADER_GET = "GET";
/**
* Field HEADER_EXPECT_100_Continue
*/
public static final String HEADER_EXPECT_100_Continue = "100-continue";
/**
* Field HEADER_EXPECT
*/
public static final String HEADER_EXPECT = "Expect";
/**
* Field HEADER_DEFAULT_CHAR_ENCODING
*/
public static final String HEADER_DEFAULT_CHAR_ENCODING = "iso-8859-1";
/**
* Field HEADER_COOKIE2
*/
public static final String HEADER_COOKIE2 = "Cookie2";
/**
* Field HEADER_COOKIE
*/
public static final String HEADER_COOKIE = "Cookie";
/**
* Field HEADER_CONTENT_TYPE_JMS
*/
public static final String HEADER_CONTENT_TYPE_JMS = "ContentType";
/**
* Field HEADER_CONTENT_TYPE
*/
public static final String HEADER_CONTENT_TYPE = "Content-Type";
/**
* Field HEADER_CONTENT_TRANSFER_ENCODING
*/
public static final String HEADER_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
/**
* Field HEADER_CONTENT_LOCATION
*/
public static final String HEADER_CONTENT_LOCATION = "Content-Location";
/**
* Field HEADER_CONTENT_LENGTH
*/
public static final String HEADER_CONTENT_LENGTH = "Content-Length";
/**
* Field HEADER_CONTENT_ID
*/
public static final String HEADER_CONTENT_ID = "Content-Id";
/**
* Field HEADER_CONTENT_DESCRIPTION
*/
public static final String HEADER_CONTENT_DESCRIPTION = "Content-Description";
/**
* Field HEADER_CONNECTION_KEEPALIVE
*/
public static final String HEADER_CONNECTION_KEEPALIVE = "Keep-Alive".intern();
/**
* Field HEADER_CONNECTION_CLOSE
*/
public static final String HEADER_CONNECTION_CLOSE = "close".intern();
/**
* Field HEADER_CONNECTION
*/
public static final String HEADER_CONNECTION = "Connection";
/**
* Field HEADER_CACHE_CONTROL_NOCACHE
*/
public static final String HEADER_CACHE_CONTROL_NOCACHE = "no-cache";
/**
* Field HEADER_CACHE_CONTROL
*/
public static final String HEADER_CACHE_CONTROL = "Cache-Control";
/**
* Field HEADER_AUTHORIZATION
*/
public static final String HEADER_AUTHORIZATION = "Authorization";
/**
* Field HEADER_ACCEPT_TEXT_ALL
*/
public static final String HEADER_ACCEPT_TEXT_ALL = "text/*";
/**
* Field HEADER_ACCEPT_MULTIPART_RELATED
*/
public static final String HEADER_ACCEPT_MULTIPART_RELATED = "multipart/related";
/**
* Field HEADER_ACCEPT_APPL_SOAP
*/
public static final String HEADER_ACCEPT_APPL_SOAP = "application/soap+xml";
/**
* Field HEADER_ACCEPT_APPLICATION_DIME
*/
public static final String HEADER_ACCEPT_APPLICATION_DIME = "application/dime";
/**
* Field HEADER_ACCEPT
*/
public static final String HEADER_ACCEPT = "Accept";
/**
* Field CHAR_SET_ENCODING
*/
public static String CHAR_SET_ENCODING = "charset";
/**
* Field UNAUTH[]
*/
public static final byte UNAUTH[] = ("401 Unauthorized").getBytes();
/**
* Field SO_TIMEOUT
*/
public static final String SO_TIMEOUT = "SO_TIMEOUT";
/**
* Field SENDER[]
*/
public static final byte SENDER[] = "400".getBytes();
public static final String PROXY = "PROXY";
public static final String MTOM_RECEIVED_CONTENT_TYPE = "MTOM_RECEIVED";
/**
* Field ISE[]
*/
public static final byte ISE[] = ("500 Internal server error").getBytes();
/**
* Field HTTP_REQ_TYPE
*/
public static final String HTTP_REQ_TYPE = "HTTP_REQ_TYPE";
/**
* Default content encoding chatset
*/
public static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
/**
* Field HTTP[]
*/
public static char HTTP[] = "HTTP/1.0 ".toCharArray();
/**
* Field DEFAULT_SO_TIMEOUT
*/
public static final int DEFAULT_SO_TIMEOUT = 60000;
/**
* Field DEFAULT_CONNECTION_TIMEOUT
*/
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
/**
* Field CONNECTION_TIMEOUT
*/
public static final String CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT";
/**
* Field CACHED_HTTP_CLIENT
*/
public static final String CACHED_HTTP_CLIENT = "CACHED_HTTP_CLIENT";
/**
* Field CACHED_HTTP_CLIENT
*/
public static final String REUSE_HTTP_CLIENT = "REUSE_HTTP_CLIENT";
/**
* Field HTTP_METHOD
*/
public static final String HTTP_METHOD = "HTTP_METHOD";
public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
public static final String HEADER_CONTENT_ENCODING = "Content-Encoding";
public static final String COMPRESSION_GZIP = "gzip";
/**
* If you want the HTTP sender to indicate that it can accept a gziped
* response, set this message context property to true. The sender will
* automatically unzip the response if its gzipped.
*/
public static final String MC_ACCEPT_GZIP = "transport.http.acceptGzip";
/**
* by default the HTTP request body is not compressed. set this message
* context property to true to have the request body gzip compressed.
*/
public static final String MC_GZIP_REQUEST = "transport.http.gzipRequest";
/**
* Method getBytes.
*
* @param data
* @return Returns byte[].
*/
public static byte[] getBytes(final String data) {
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
try {
return data.getBytes(HTTP_ELEMENT_CHARSET);
} catch (UnsupportedEncodingException e) {
}
return data.getBytes();
}
}
Can you clarify it or would be realy appreciated that you have the code snipet in the article which is working:-).
Checked Axis2 SVN Source Tree
Hi,
I just checked the Axis2 Source Code Repository, it looks like that
"HTTP_HEADERS" was added under revision 426253 on July 27.
Could you please post the info related to Axis2 Build which these client parameters are added and functional?
Thanks a lot!