Skip to main content
Omnitracs Knowledge Base

J2EE Using Axis2

A QSP customer has graciously shared their guidelines instructions for integrating with the Services Portal through J2EE using Axis2.

Here's a recipe for using Axis 2 1.1.1 w/ Qualcomm:

1. Download and install Axis2 from http://ws.apache.org/axis2/. The current release version (as of 3/21) is 1.1.1. One can easily become confused as Axis1 is still available and supported for production use.

2. Download the WSDL from https://services.omnitracs.com/otsWebWS/services/OTSWebSvcs/wsdl/OTSWebSvcs.wsdl and save it to a file (c:\omnitracs.wsdl or wherever)

3. Generate client stubs. In windows, execute this command:

C:\axis2-1.1.1\bin\wsdl2java.bat -uri c:\qualcomm.wsdl -p com.yourcompany.client -d adb -s -o c:\youroutputdir\client

Here is some sample code for invoking the web service:

public static String callOV(String url, String proxyHost, String proxyPort,

   String userName, String password, String transId, String subId)

   throws Exception {

  OTSWebSvcsServiceStub stub = new OTSWebSvcsServiceStub(url);

 

  if (proxyHost != null && proxyHost.length() > 0) {

   Options options = stub._getServiceClient().getOptions();

 

   HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();

   proxyProperties.setProxyName(proxyHost);

   proxyProperties.setProxyPort(new Integer(proxyPort).intValue());

   options.setProperty(HTTPConstants.PROXY, proxyProperties);

 

  }

 

  OMFactory factory = OMAbstractFactory.getOMFactory();

  OMNamespace wsseNS = factory

    .createOMNamespace(

      "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",

      "wsse");

 

  OMNamespace envNS = factory.createOMNamespace(

    "http://schemas.xmlsoap.org/soap/envelope/""SOAP-ENV");

 

  OMElement securityElement = factory.createOMElement("Security", wsseNS);

  OMAttribute soapThing = factory.createOMAttribute("mustUnderstand",

    envNS, "1");

  securityElement.addAttribute(soapThing);

  OMElement untElem = factory.createOMElement("UsernameToken", wsseNS);

  OMElement unameElem = factory.createOMElement("Username", wsseNS);

  OMElement pwElem = factory.createOMElement("Password", wsseNS);

 

  OMText unameTxt = factory.createOMText(unameElem, userName);

  OMText pwTxt = factory.createOMText(pwElem, password);

  unameElem.addChild(unameTxt);

  pwElem.addChild(pwTxt);

 

  securityElement.addChild(untElem);

 

  untElem.addChild(unameElem);

  untElem.addChild(pwElem);

 

  stub._getServiceClient().addHeader(securityElement);

 

  Dequeue dequeue = new OTSWebSvcsServiceStub.Dequeue();

  dequeue.setBlockCount(10);

  dequeue.setSubscriberId(new Integer(subId));

  dequeue.setTransactionId(new Integer(transId));

 

  DequeueResponse resp = stub.dequeue(dequeue);

 

  TransactionBlock tb = resp.getDequeueReturn();

 

  DataHandler handler = tb.getTransactions();

 

  ByteArrayInputStream bais = (ByteArrayInputStream) handler.getContent();

  ByteArrayOutputStream baos = new ByteArrayOutputStream();

 

  int b;

  while ((b = bais.read()) >= 0) {

   baos.write(b);

  }

 

  return new String(baos.toByteArray());

 }

This code results in a string containing an xml document.

Note that this is not the proper way to use Axis2 with WS-Security. In theory, one should use rampart 1.1 (the Apache WS-Security package), but I had no success in getting this to work. See http://ws.apache.org/axis2/modules/rampart/1_1/security-module.html for details.

  • Was this article helpful?