Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to call a service from another service using axis2

 
Rangan Iyengar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a POJO exposed as a Webservice using Axis2. I have tested this service using RPCServiceClient and it works fine. This service needs to talk to other services which are also POJO's exposed as Webservices using Axis2. The other services also work fine when invoked by RPCServiceClient mechanism. But if I invoke those services from my Axis2 service using the same mechanism of RPCServiceClient mechanism, it gives me the following exception.
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:118)
> at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:39)
> at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:493)
> at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:319)
> at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:247)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
> at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
> at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
> at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
> at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
> at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.NullPointerException
> at org.apache.axis2.context.MessageContext.isHeaderPresent(MessageContext.java:1054)
> at org.apache.axis2.handlers.addressing.AddressingInHandler.invoke(AddressingInHandler.java:72)
> at org.apache.axis2.engine.Phase.invoke(Phase.java:381)
> at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:518)
> at org.apache.axis2.engine.AxisEngine.receiveFault(AxisEngine.java:596)
> at org.apache.axis2.description.RobustOutOnlyAxisOperation$RobustOperationClient.send(RobustOutOnlyAxisOperation.java:99)
> at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:295)
> at org.apache.axis2.client.ServiceClient.sendRobust(ServiceClient.java:453)
> at org.apache.axis2.client.ServiceClient.sendRobust(ServiceClient.java:380)
> at org.apache.axis2.rpc.client.RPCServiceClient.invokeRobust(RPCServiceClient.java:131)
> at sample.pojo.service.JaguarService.meth2(Unknown Source)
> ... 25 more



here, i am calling meth2(the first service) from the client using RPCServiceClient.
from meth2 i am calling meth3(the second service) using RPCServiceClient again.
the services work fine independently, when invoked from within a client.
the exception is only when the second service is invoked from within another service.

any help in this regard would be of great help.

Thanks,
Rangan
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRancg.

What does the source code to invoke meth3 from a non-WS client look like, and what source code do you use for invoking it from meth2?
 
Rangan Iyengar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

here is the code:

client:

RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/Jaguar?wsdl");
options.setTo(targetEPR);
QName opmeth2 = new QName("http://service.pojo.sample/xsd", "meth2");
int intparam = 78;

Object[] opmeth2Args = new Object[] { intparam };
Class[] returnTypes = new Class[] { int.class };
Object[] response = serviceClient.invokeBlocking(opmeth2,opmeth2Args, returnTypes);
Integer in2 = (Integer) response[0];

service1:
..meth2() { ..
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/SecondService?wsdl");
options.setTo(targetEPR);
QName opmeth2 = new QName("http://service.pojo.sample/xsd", "meth3");

Object[] opmeth2Args = new Object[] { };
serviceClient.invokeRobust(opmeth2, opmeth2Args);

service2:
.. meth3() { ..
System.out.println("in meth3 of SecondService ");

i get the exception when the call is made to the second service.

thanks,
Rangan
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only see one invovation of meth3, apparently the one from inside meth2.

If you actually meant "meth3" instead of "meth2" in the "client:" section, then the codes are not identical - one uses a parameter, the other doesn't; one uses invokeRobust, the other uses invokeBlocking. Try to use identical code in both cases, and see what happens.

I'd also advise not to use variable names like "opmeth2" pointing to method "meth3" - it's quite confusing to read.
[ February 26, 2007: Message edited by: Ulf Dittmer ]
 
Rangan Iyengar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry for the confusion.
here is my code:

client:

System.out.println("in main of client\n");

RPCServiceClient serviceClient1 = new RPCServiceClient();
Options options1 = serviceClient1.getOptions();

EndpointReference targetEPR1 = new EndpointReference("http://localhost:8080/axis2/services/SecondService?wsdl");
options1.setTo(targetEPR1);
QName op1meth3 = new QName("http://service.pojo.sample/xsd", "meth3");
Object[] op1meth3Args = new Object[] { };
System.out.println("calling meth3 directly from client ");
serviceClient1.invokeRobust(op1meth3, op1meth3Args);

System.out.println("calling meth3 through meth2 \n");

RPCServiceClient serviceClient2 = new RPCServiceClient();
Options options2 = serviceClient2.getOptions();

EndpointReference targetEPR2 = new EndpointReference("http://localhost:8080/axis2/services/Jaguar?wsdl");
options2.setTo(targetEPR2);
QName op2meth2 = new QName("http://service.pojo.sample/xsd", "meth2");
int intparam = 78;

Object[] op2meth2Args = new Object[] { intparam };
Class[] returnTypes = new Class[] { int.class };
Object[] response = serviceClient2.invokeBlocking(op2meth2,op2meth2Args, returnTypes);
Integer in2 = (Integer) response[0];
System.out.println("Return Value from meth2 " +in2.intValue());


service1:

System.out.println("in method 2 ");

RPCServiceClient serviceClient1 = new RPCServiceClient();
Options options1 = serviceClient1.getOptions();

EndpointReference targetEPR1 = new EndpointReference("http://localhost:8080/axis2/services/SecondService?wsdl");
options1.setTo(targetEPR1);
QName op1meth3 = new QName("http://service.pojo.sample/xsd", "meth3");

Object[] op1meth3Args = new Object[] { };
System.out.println("in meth2... calling meth3..... ");
serviceClient1.invokeRobust(op1meth3, op1meth3Args);
int temp=a;
temp=temp+2;
System.out.println("int a= "+temp);
return(temp+1);


service2:

int temp=45;
System.out.println("in meth3 of SecondService int a= "+temp);


i hope i have been more clear this time.
i do not understand as to why the same piece of code throws an exception when used within another service.

thanks,
Rangan

[ February 27, 2007: Message edited by: Rangan Iyengar ]
[ February 27, 2007: Message edited by: Rangan Iyengar ]
 
Rangan Iyengar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i could not get it working...
i found a work around though.
i used a message queue to send a message from the first service, which in turn causes the second service to be invoked.

if anyone can solve the service-service call please post it up here.

thanks,
Rangan
 
Arthur Ford
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this -
EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/Jaguar");

Remove the ?WSDL
 
Rangan Iyengar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arthur,

I did try that as well.....
but, of no use...
the results are still the same....

Regards,
Rangan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic