Hi Neha,

Please see my comments inline:

[email protected] wrote:
Hi,

I am trying to access OFBiz webservice from external java client.
I have successfully accessed OFBiz web service with primitive types as parameters from external client and vice versa but i am stuck up with accessing a service having Map or List as arguments... For this;
I made an OFBiz service and defined it in services.xml :

<service name="ComplexInputService" engine="java" export="true" location="org.ofbiz.ExtWebServiceClient.ComplexInputService" invoke="callWebService">
        <description>web service with complex params</description>
        <attribute type="List" mode="IN" name="inputList" optional="true"
/>
        <attribute type="List" mode="OUT" name="result" optional="true"/>
</service>
Make below given modification in you service definition:

<service name="ComplexInputService" engine="java" export="true"
            location="org.ofbiz.ExtWebServiceClient.ComplexInputService"
invoke="callWebService">
       <description>web service with complex params</description>
       <attribute type="List" mode="IN" name="inputList" optional="true"
/>
<attribute type="List" mode="OUT" name="outputList" optional="true"/>
</service>


The web service inside OFBiz is :

public class ComplexInputService {

    public static Map callWebService(DispatchContext ctx, Map context) {
        System.out.println("inside call web service.........");
        Map<String, Object> result = ServiceUtil.returnSuccess();
        List inputList = (List)context.get("inputList");
        result.put("result", inputList);
        System.out.println("service finished......");
        return result;
    }
}

Make below given modification in your service implementation:

public class ComplexInputService {

   public static Map callWebService(DispatchContext ctx, Map context) {
       System.out.println("inside call web service.........");
       Map<String, Object> result= FastMap.newInstance();
       List<String> outputList= FastList.newInstance();
List<String> inputList= UtilGenerics.checkList(context.get("inputList"));
       result.put("outputList", inputList);
       result = ServiceUtil.returnSuccess();
       System.out.println("service finished......");
       return result;
   }
}

OFBiz framework restricted the wsdl file from being generated, due to the fact that the input and output parameters for the service are List. I modified ModelParam.java (framework/service/src/org/ofbiz/service/ModelParam.java), to support complx parameters also..

public class ModelParam implements Serializable {
.
.
   protected String java2wsdlType() throws WSDLException {
// If statements to support primitive types as arguments to web service
        if (ObjectType.instanceOf(java.lang.Character.class, this.type)) {
            return "string";
        } else if (ObjectType.instanceOf(java.lang.String.class, this.type
)) {
            return "string";
} .
.
.         // added more if statements to support Map and List
        else if (ObjectType.instanceOf(java.util.AbstractMap.class, this.
type)) {
            System.out.println("service takes map as input param.......");
return "anyType"; // i am not getting any idea what to return so that client can read the wsdl properly
        }
        else if (ObjectType.instanceOf(java.util.AbstractList.class, this.
type)) {
            System.out.println("service takes List as input param......."
);
            return "anyType";
        }
throw new WSDLException(WSDLException.OTHER_ERROR, "Service cannot be described with WSDL (" + this.name + " / " + this.type + ")")
    }
}

Discard this changes. These are useless, when you use above given improved code.

The wsdl hence generated is :
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; xmlns:tns="http://ofbiz.apache.org/service/"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; targetNamespace="http://ofbiz.apache.org/service/";>
    <wsdl:message name="ComplexInputServiceRequest">
        <wsdl:part name="inputList" type="xsd:anyType"/>
    </wsdl:message>
    <wsdl:message name="ComplexInputServiceResponse">
        <wsdl:part name="result" type="xsd:anyType"/>
    </wsdl:message>
    <wsdl:portType name="ComplexInputServicePortType">
        <wsdl:operation name="ComplexInputService">
            <wsdl:input message="tns:ComplexInputServiceRequest"/>
            <wsdl:output message="tns:ComplexInputServiceResponse"/>
        </wsdl:operation>
    </wsdl:portType>
<wsdl:binding name="ComplexInputServiceSoapBinding" type="tns:ComplexInputServicePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="ComplexInputService">
            <soap:operation soapAction=""/>
            <wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; namespace="http://ofbiz.apache.org/service/"; use="literal"/>
            </wsdl:input>
            <wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; namespace="http://ofbiz.apache.org/service/"; use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="ComplexInputService">
<wsdl:port binding="tns:ComplexInputServiceSoapBinding" name="ComplexInputServicePort"> <soap:address location="http://localhost:8088/webtools/control/SOAPService"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
Change your wsdl part's  name according to above given modifications


I have created a java client in eclipse outside OFBiz

public static void main(String[] args) {
        try
        {
String endPoint = "http://localhost:8088/webtools/control/SOAPService";;
            Call call = (Call)new Service().createCall();
            call.setTargetEndpointAddress(new URL(endPoint));
call.setOperationName(new QName("http://ofbiz.apache.org/service/","ComplexInputService";));
            System.out.println("*******call.add parameterl********");
            List inputList = new Vector();
            inputList.add("neha");
            inputList.add("mehta");
call.addParameter("inputList",org.apache.axis.Constants.SOAP_VECTOR, javax.xml.rpc.ParameterMode.IN); call.addParameter("outputList",org.apache.axis.Constants.SOAP_VECTOR, javax.xml.rpc.ParameterMode.OUT);
            call.setReturnType(org.apache.axis.Constants.SOAP_VECTOR);
            System.out.println("*******call invoking********");
            Object responseWS=call.invoke(new Object[]{inputList});
            Map output = call.getOutputParams();
            System.out.println("call invoked...");
        }
        catch(Exception exp)
        {
            exp.printStackTrace();
        }
    }

I get an exception on running the client :
AxisFault
 faultCode: {
http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: faultString: org.xml.sax.SAXParseException: Premature end of file. faultActor: faultNode: faultDetail: { http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: Premature end of file.


org.xml.sax.SAXParseException: Premature end of file.
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(
MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:2443)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at MyClient.main(MyClient.java:37)

On OFbiz server, i get an exception as: Request SOAPService caused an error with the following message: Error calling event: org.ofbiz.webapp.event.EventHandlerException: org.xml.sax.SAXException cannot be cast to java.lang.String (org.xml.sax.SAXException cannot be cast to java.lang.String).


I am not able to understand how to go ahead... I am stuck up completely... Kindly help me out














Thanks & Regards,
Neha Mehta
Software Engineer (A-1-1)
Larsen & Toubro Infotech Ltd.
Email-id: [email protected]
EL-200, TTC Electronic Zone,
Shil Mahape Road, Navi Mumbai, 400710
India +0530 UTC/GMT

**********************************************************************************************************************
The most beautiful thing is to see a person smiling… And even more beautiful is knowing that you are the reason behind it!!! Be a reason for others to smile HAVE A NICE DAY AHEAD......
**********************************************************************************************************************





Larsen & Toubro Infotech Ltd.
www.Lntinfotech.com

This Document is classified as: L&T Infotech Proprietary L&T Infotech Confidential L&T Infotech Internal Use Only L&T Infotech General Business This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
Hope this will help you.

Thanks
--
Divesh Dutta

Reply via email to