Hi all,

In the past, i used Axis v1.4 WSDLtoJava to generate web service client
classes.

Now, I upgraded to Axis2 and used wsdltojava but only two classes were
generated - the stub and interface. Looks like the data types/params
related classes did not genertae that the STUB refers to?? If so, which
wsdltojava command need to be used to generate the classes related to the
params and returnt ypes of a business method??


I have compilation errors with the Stub and need help. I looked at the stub
code and I see that there are many SOAP envelope related code UNLIKE in the
stub generated in Axis 1.4. Also, the retun type and params of a business
method are treated as classes. Why is that? I want a simple webservice
client? How to accomplish it? - Do I need to use CXF instead of Axis2?

The steps followed are below:

1) Excerpt of the WSDL:

< <http://10.5.20.126:8206/cds-wsclient/cds-service?wsdl#>
<?xml version="1.0"?>
<wsdl:definitions targetNamespace="http://client.xyz"; name="TestInterface"
xmlns:ns1="http://schemas.xmlsoap.org/soap/http"; xmlns:soap="
http://schemas.xmlsoap.org/wsdl/soap/"; xmlns:tns="
http://client.cds.med.va.gov"; xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<http://10.5.20.126:8206/cds-wsclient/cds-service?wsdl#><wsdl:message name="
readData"> <http://10.5.20.126:8206/cds-wsclient/cds-service?wsdl#><
wsdl:part type="xsd:string" name="in0"/><wsdl:part type="xsd:string" name="
in1"/><wsdl:part type="xsd:string" name="in2"/></wsdl:message><wsdl:message
name="readDataResponse">
<http://10.5.20.126:8206/cds-wsclient/cds-service?wsdl#><wsdl:part type="
xsd:string" name="out"/></wsdl:message>

2a) To generate client classes from wsdl:

%AXIS2_HOME%\bin\WSDL2Java -uri <wsdl file path> -p <package name> -u -s

This created a interface and a stub.

2b) I had to add the following dependenicesin maven pom to avoid some of
the compilation errors in the stub:

   <dependency>
    <groupId>axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.6.2</version>
   </dependency>
   <dependency>
    <groupId>org.apache.ws.commons.axiom</groupId>
    <artifactId>axiom-api</artifactId>
    <version>1.2.8</version>
   </dependency>
   <dependency>
    <groupId>org.apache.ws.commons.axiom</groupId>
    <artifactId>axiom-impl</artifactId>
    <version>1.2.8</version>
   </dependency>

3) The stub has still issues:

The auto generated stub had the following signature for the business method:
public readDataResponse readData(readData) throws java.rmi.RemoteException

I changed it to:
public String readData(String in0, String in1, String int2) throws
java.rmi.RemoteException

Now it still has compilation issues since toenvelope() is expecting a
readData object insted of the in params list.
Below is the business method and toenvelope method:

  private  org.apache.axiom.soap.SOAPEnvelope
toEnvelope(org.apache.axiom.soap.SOAPFactory factory, ReadData param,
boolean optimizeContent, javax.xml.namespace.QName methodQName)
                                throws org.apache.axis2.AxisFault{

                                            try{

org.apache.axiom.soap.SOAPEnvelope emptyEnvelope =
factory.getDefaultEnvelope();

emptyEnvelope.getBody().addChild(param.getOMElement(gov.va.med.cds.client.ReadClinicalData.MY_QNAME,factory));
                                                    return emptyEnvelope;
                                                }
catch(org.apache.axis2.databinding.ADBException e){
                                                    throw
org.apache.axis2.AxisFault.makeFault(e);
                                                }

                                }



public String readData(String in0, String in1, String int2) throws
java.rmi.RemoteException
      org.apache.axis2.context.MessageContext _messageContext = null;
      try{
       org.apache.axis2.client.OperationClient _operationClient =
_serviceClient.createClient(_operations[0].getName());
      _operationClient.getOptions().setAction("http://xyz/readData";);
      _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);



addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");

      // create a message context
      _messageContext = new org.apache.axis2.context.MessageContext();

      // create SOAP envelope with that payload
      org.apache.axiom.soap.SOAPEnvelope env = null;


                                            env =
toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
                                            in0, in1, in2,
                                            optimizeContent(new
javax.xml.namespace.QName("http://client.xyz";,
                                            "readData")), new
javax.xml.namespace.QName("http://client.xyz";,
                                            "readData"));

//adding SOAP soap_headers
 _serviceClient.addHeadersToEnvelope(env);
// set the message context with that soap envelope
_messageContext.setEnvelope(env);
// add the message contxt to the operation client
_operationClient.addMessageContext(_messageContext);
//execute the operation client
_operationClient.execute(true);

       org.apache.axis2.context.MessageContext _returnMessageContext =
_operationClient.getMessageContext(

org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        org.apache.axiom.soap.SOAPEnvelope _returnEnv =
_returnMessageContext.getEnvelope();


                        java.lang.Object object = fromOM(
                                     _returnEnv.getBody().getFirstElement()
,
                                     String.class,
                                      getEnvelopeNamespaces(_returnEnv));

                                return (String)object;

 }catch(org.apache.axis2.AxisFault f){
    org.apache.axiom.om.OMElement faultElt = f.getDetail();
    if (faultElt!=null){
        if (faultExceptionNameMap.containsKey(new
org.apache.axis2.client.FaultMapKey(faultElt.getQName(),"readData"))){
            //make the fault by reflection
            try{
                java.lang.String exceptionClassName =
(java.lang.String)faultExceptionClassNameMap.get(new
org.apache.axis2.client.FaultMapKey(faultElt.getQName(),"readData"));
                java.lang.Class exceptionClass =
java.lang.Class.forName(exceptionClassName);
                java.lang.reflect.Constructor constructor =
exceptionClass.getConstructor(String.class);
                java.lang.Exception ex = (java.lang.Exception)
constructor.newInstance(f.getMessage());
                //message class
                java.lang.String messageClassName =
(java.lang.String)faultMessageMap.get(new
org.apache.axis2.client.FaultMapKey(faultElt.getQName(),"readData"));
                java.lang.Class messageClass =
java.lang.Class.forName(messageClassName);
                java.lang.Object messageObject =
fromOM(faultElt,messageClass,null);
                java.lang.reflect.Method m =
exceptionClass.getMethod("setFaultMessage",
                           new java.lang.Class[]{messageClass});
                m.invoke(ex,new java.lang.Object[]{messageObject});

}

4) Could you provide the client exmaple to invoke the stub andits business
methods?


Thanks in advance.

Reply via email to