How to Use Apache Axis2 for SOAP Calls

 

1.  Download the Axis2 library from the apache website.

2.  Extract the .zip file.

3.  Add the .jar files from axis2-x.x.x\lib to your build path.

4.  Rename the addressing-1.5.4.mar file located in axis2-x.x.x\ repository\modules to addressing-1.5.4.jar, and add it to your build path.

5.  Generate your OperationsService objects using wsdl2java, located in axis2-x.x.x\bin.

// Replace WSDLPATH with the url or path to the wsdl, and OUTPUTPATH with the path to your code output folder.
wsdl2java.bat –uri WSDLPATH/OperationsService.svc?wsdl -o OUTPUTPATH -d adb -g -u -sn OperationsService -pn wsHttpEndpointOperations -Ew false -ns2p urn:hisoftware:compliancesheriff:services=hisoftware.compliancesheriff.services.operations,urn:hisoftware:compliancesheriff:data=hisoftware.compliancesheriff.data.operations

wsdl2java.bat –uri WSDLPATH/ReportingService.svc?wsdl -o OUTPUTPATH -d adb -g -u
-sn ReportingService -pn wsHttpEndpointReporting -Ew false -ns2p urn:hisoftware:compliancesheriff:services=hisoftware.compliancesheriff.services.reporting,urn:hisoftware:compliancesheriff:data=hisoftware.compliancesheriff.data.reporting

 

6.  In your project setup your client.

final String apiKey = "22DF0959F20743660304CB829B3891F0";
final String endpoint = "http://www.example.com/ComplianceSheriff/OperationsService.svc";
final String replyToAddress = "http://www.w3.org/2005/08/addressing/anonymous";

EndpointReference endpnt = new EndpointReference();
endpnt.setAddress(endpoint);
EndpointReference replyTopnt = new EndpointReference();
replyTopnt.setAddress(replyToAddress);
OperationsServiceStub opService = new OperationsServiceStub();

ServiceClient opServiceClient = opService._getServiceClient();
opServiceClient.setTargetEPR(endpnt);
opServiceClient.engageModule("addressing");
opServiceClient.getOptions().setReplyTo(replyTopnt);
opServiceClient.addStringHeader((new QName("urn:hisoftware:compliancesheriff:data",
"ApiKey")), apiKey);

 

7.  Create the object needed to perform the API call.

Example: CreateScan

//Create a data binding object for the call
CreateScan createScan = new CreateScan();

// Create Scan object that will be in the body of the soap call
Scan myScan = new Scan();
ArrayOfstring additionalDomains = new ArrayOfstring();
additionalDomains.addString("www.example2.com");
additionalDomains.addString("www.example3.com");
myScan.setAdditionalDomains(additionalDomains);
myScan.setDisplayName("ExampleScanAxis2API");
myScan.setBaseUrl("http://www.example.com");

// Set the scan in your data binding object for the call
createScan.setScan(myScan);

 

8.  Perform the call, and get results back.

CreateScanResponse scanResult = opService.createScan(createScan);