Sunday, January 17, 2010

Improving Axis2 http transport client

Until Axis2 1.5 a separate http client instance was created per request by default. This leads to an connection timeout problem with the high loads. See here for more details.

In order to solve this issue Axis2 1.5.1 uses one http client object cached in configuration context for all requests. Since by default MultiThreadedHttpConnectionManager allows two request per host this causes an issue if tried to invoke a service more than twice.

Following options can be taken to solve this issue.
serviceClient.getOptions().setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, Constants.VALUE_TRUE);
this would build the response stream once the response stream returned and release the connection. But this may have a performance hit since it build the OM tree at transport level.
2.Clean up the transport after each call

However both the above methods can only invoke two requests at time since there is only two connections. Again this may cause problems with invoking slow services. This can be avoided by the following technique to increase the default number of connections.

ConfigurationContext configurationContext =

            MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();

            HttpConnectionManagerParams params = new HttpConnectionManagerParams();
            HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
            configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

and call serviceClient.cleanupTransport(); after each service invocation.

Friday, January 15, 2010

Changing Axis2 application path

By default Axis2 generates an context path as follows when deployed it in tomcat or other application server.


but most of the it is requried to customize this as follows.


Below steps can be used to achive this.
1. Rename the web app name axis2 to myApp
2. Uncomment and edit the servicePath parameter at the axis2.xml file
3. Add the following entry to web.xml. Here we need to add this entry rather than chaing existing one since services part is hard coded in some places.


How to get a path like this?


This can be done my making this application as ROOT app
1. change the myApp to ROOT

Thursday, January 7, 2010

WSO2 Data Services v2.2.0 released

Axis2 lets users to develop web services from the java code. This can either be a POJO where users write the business logic first or a generated code with the WSDL. In whatever form real business logic retrieve data from the data store (most of the time a database) and update it.

Therefore isn't it useful to publish the data stored in permanent storage straight away (I.e using some descriptor files) without doing any coding? WSO2 Data services server let users to publish data by just writing a descriptor file. Currently it can publish data stored in many forms. eg. Databases, text files, excel sheets, google docs etc..
Since WSO2 Data services server build on top of WSO2 carbon platform it inherit all the WS* features such as security, reliable messaging, addressing etc ..

Following are some of the key features:

- Multiple data source support - any relational database accessible via JDBC, CSV, Excel, JNDI bound data sources and Google Spreadsheets
- Web service and REST interfaces for data
- Customizable response format to match your next adaptor's input
- Support for large data sets with little to no impact to the server's memory usage
- Nested queries and federated response from multiple disparate data sources
- Role based content filtering
- Full support for WS-Security, WS-Trust, WS-Policy, WS-SecureConversation and XKMS
- Web based GUI wizard
- Multi transport support - send and receive your data in either HTTP(s), SMTP, JMS and XMPP
- Reliable delivery of data
- Access throttling based on IP/Domain or frequency

WSO2 Data Services 2.2.0 can be downloaded from

Friday, January 1, 2010

Axis2 Authentication

The servlet specification provides four authentication mechanisms for any web application. Therefore any web services engine which receives http requests through a servlet can use those authentication mechanisms. Here is how you can do BASIC and DIGEST authentication with Apache Axis2 deployed under tomcat.

Axis2 war distribution is a standard web application. This war distribution contains a web.xml and within it there is a servlet called AxisServlet which is used to receive the http requests.

Configuring the war distribution.
First the following should add to the web.xml file to protect the AxisServlet from the anonymous access.

<!-- <auth-method>BASIC</auth-method> -->

<web-resource-name>Protected Resource</web-resource-name>


then add the following to the tomcat-users.xml

Now the servlet is protected and Lets see how to provide the credentials when accessing the service. This is in fact done by using the functionality available with the commons http client.

ServiceClient serviceClient = new ServiceClient();
serviceClient.setTargetEPR(new EndpointReference("http://localhost:8080/axis2/services/Version/getVersion"));

HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();

serviceClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE, authenticator);

This request can be send through a tcpmon to understand how this authentication works. First Axis2 client sends a normal request and tomcat server returns an Unauthorized response with the required authentication method.

HTTP/1.1 401 Unauthorized

Server: Apache-Coyote/1.1

WWW-Authenticate: Digest realm="default", qop="auth", nonce="6da725c4d901eee87d2ad49cadbac74a", opaque="37629e27fec9bfaf38063bc3ab65f12d"

After receiving this Axis2 client sends another request with the authentication details.