I wanted to create a simple web service(RPC like) which can accept few params(String) and can return object(bean like or at least a string) like below:
class MyWebService() {
public String search( String a, String b) {
return "x";
}
}
Q1: I couldn't find any way to pass direct arguments to webservice instead I had to wrap all of them in OMElement object like below.
Is is right way of passing arguments to a webservice in Axis2?
Q2: To keep my testing continue, I changed my service to look like below. I changed arguments by wrapping it up in OMElement but return type is still "String". When I test it using my test client. I got "AxisFault: java.lang.String".
So Is there any simple way to return java objects?
class MyWebService() {
public String search( OMElement params ) {
return "x";
}
}
BTW, My services.xml looks like below:
<service>
<description>
Client WebService
</description>
<parameter name="ServiceClass" locked="false">MyWebService</parameter>
<operation name="search">
<messageReceiver class="org.apache.axis2.receivers.RPCMessageReceiver"/>
<actionMapping>urn:search</actionMapping>
</operation>
</service>
And Client class looks like below:
public class TestClient {
public static void main(String [] args) throws Exception {
System.out.println("Creating request...");
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://webservice.fw.com/xsd", "request");
OMElement email = fac.createOMElement("email", omNs);
email.addChild(fac.createOMText(email, "[EMAIL PROTECTED]"));
OMElement fname = fac.createOMElement("firstName", omNs);
fname.addChild(fac.createOMText(fname, "amit"));
OMElement method = fac.createOMElement("search", omNs);
method.addChild(email);
method.addChild(fname);
EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/MyWebService");
Options options = new Options();
options.setTo(targetEPR);
System.out.println("sending request...");
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMElement responseElement = sender.sendReceive(method);
System.out.println("got response...");
System.out.println(responseElement);
BufferedInputStream input = new BufferedInputStream(System.in);
input.read();
}
}
Q3: Again to keep my testing continue, I changed return type also to OMElement( As it was given in Axis2 Examples)
class MyWebService() {
public OMElement search( OMElement params ) {
OMElement responseElement = null
...
return responseElement;
}
}
And modified my services.xml as per below:
<service>
<description>
Client WebService
</description>
<parameter name="ServiceClass" locked="false">MyWebService</parameter>
<operation name="search">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
<actionMapping>urn:search</actionMapping>
</operation>
</service>
NOW biggest problem is if I return "params" which is same OMElement object reference what I receive from client side then this service works fine but if create any other OMElement object (in similar way I create "params" object at client side ) and return it from webservice then I get ClassCastException. Why?
Exception in thread "main" org.apache.axis2.AxisFault: java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl
at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:287)
Any help will be appreciated. Thanks.
Regards
Amit
"Willing to learn what you are willing to share."