You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Kumar, Amit Z (Compliance Tech)" <am...@gs.com> on 2006/08/08 23:10:28 UTC

Struggling with Axis2

> 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, "amit@email.com"));
>     
>     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(OutInAxi
> sOperation.java:287)
> 
> 
> Any help will be appreciated. Thanks.
> 
> 
> Regards
> Amit
> "Willing to learn what you are willing to share."
> 

Re: Struggling with Axis2

Posted by Saminda Abeyruwan <sa...@opensource.lk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Your scenario can be achieved with RPCMessageReceiver.

Ex; Your web service

class Foo {

    public String foo(String a, String b) {
          return a + b ;
    }
}

Create an .aar out of this with the message receiver as
RPCMessageReceiver. Deploy this aar. ?wsdl shows you the generated wsdl.
Use wsdl2Java tool to generate the stubs. That's it.

http://www.wso2.net/kb/83 for more Info.

Thank you

Saminda

Kumar, Amit Z (Compliance Tech) wrote:
> 
>       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, "amit@email.com"));
>          
>           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."*
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFE2YtRYmklbLuW6wYRAhoAAKC//J907nzWSMwt2i8RUFxNHCfaawCfWuOX
BfKJ2k6CHZLJj2RMnLWY9w8=
=rAuZ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org