Consuming our Soap API from Java using Apache Axis2

Help with the Esendex API

Consuming our Soap API from Java using Apache Axis2

Postby Scott » Tue Mar 16, 2010 12:32 am

In order to consume our Soap interface endpoints using Apache Axis2 there are a couple of changes that need to be made to the generated client stub code from our wsdls.

To generate the client side code of our SendService you would need to follow the following steps.

1. Download and install Apache Axis2
2. Generate the Client Stub with the following command line from http://ws.apache.org/axis2/1_3/userguide-creatingclients.html#choosingclient

%AXIS2_HOME%\bin\WSDL2Java -uri https://www.esendex.com/secure/messenge ... .asmx?wsdl -p com.esendex.ems.soapinterface -d adb -s

This will generate the service stub class in a subdirectory with the path "src\com\esendex\ems\soapinterface\SendService.java"

3. We now need to alter the stub slightly to resolve a couple of issues with using axis2 and our soap api.
3a). First we need to enforce soap version 1.1 as Apache Axis2 uses version 1.2 by default
We do this by replacing the following line in the generated stub class.

//Set the soap version
_serviceClient.getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

with

//Set the soap version
_serviceClient.getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

3b). Secondly we need to disable chunking as Apache Axis2 enables this by default and with our Soap interface it expects the Content-Length property to be set to the size of the request.
We do this by disabling Chunked Requests by adding the following line after the previous change we have made. You will need to include a reference to the HTTPConstants enum found in the org.apache.axis2.transport.http library at the top of the Stub class.

import org.apache.axis2.transport.http.HTTPConstants;

_serviceClient.getOptions().setProperty(HTTPConstants.CHUNKED, false);

Making these changes should now resolve the issues we have seen so far with consuming our Soap API via Java using Apache Axis2

A complete stub class has been attached to this forum post along with a sample application for sending a text message, you will need to assign your Esendex credentials to the relevant variables as shown by the comments in the code.

Any queries please respond to this thread.

Scott

Attachments:
WsdlAxis2.zip
Scott
 
Posts: 1
Joined: Tue Mar 16, 2010 12:08 am

Return to API



cron
© Esendex Ltd 2010
Company Registration Number: 04217280