Re: problem in invoke the webservice using REST Style by client program
Hi Bansal, There is a basic problem here as you are trying to pass the parameters also with your endpoint address. Change your code to the following and try : EndpointReference targetEPR = new EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname";); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); ServiceClient client = new ServiceClient(); client.setOptions(options); OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement payload factory.createOMElement(methodName, null); OMElement parameter = factory.createOMElement("param0", null, methodName); parameter.setText("47"); OMElement result= call.sendReceive(payload); The reason we want to do like this is we do everything the way as you invoke with SOAP. Just a simple switch turns that to a REST call. Please do not use RESTCall class anymore, its crap :). -- Chinthaka P.S. : I didn't write this code in an IDE. Compile errors are expected features of this code ;) Bansal, Vimal wrote: > Hi All, > I am trying to invoke my webservice which having a method take one > parameter using REST my client code snippets is > > >public class RestClient > { > > private static EndpointReference targetEPR = new > EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname?param0=47";); > > public static void main(String[] args) { > try { > > RESTCall call = new RESTCall(); > Options options = new Options(); > options.setTo(targetEPR); > options.setTransportInProtocol(Constants.TRANSPORT_HTTP); > options.setProperty(Constants.Configuration.ENABLE_REST, > Constants.VALUE_TRUE); > > options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); > call.setOptions(options); > OMElement result= call.sendReceive(); > System.out.println(result.getFirstElement().getText()); >} >catch (AxisFault axisFault) { > System.out.println(axisFault+":"+axisFault.getMessage()); > } > catch (Exception axisFault) { > System.out.println(axisFault+":"+axisFault.getMessage()); > } > } > I am able to call the method by browser by the same url that has-been > passed as a argument in EndPointReference() >but when I am calling this by client I am getting following error in > log file. > > >org.apache.axis2.AxisFault: For input string: "47?"; nested exception > is: > java.lang.NumberFormatException: For input string: "47?"; nested > exception is: > org.apache.axis2.AxisFault: For input string: "47?"; nested exception > is: > java.lang.NumberFormatException: For input string: "47?" > at > org.apache.axis2.transport.http.util.RESTUtil.processGetRequest(RESTUtil.java:141) > at > org.apache.axis2.transport.http.AxisRESTServlet.doGet(AxisRESTServlet.java:36) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) > at > org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) > at > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) > at > org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) > at > org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) > at > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) > at > org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) > at > org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) > at > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) > at > org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) > at > org.apache.catalina.core.Standard
RE: problem in invoke the webservice using REST Style by client program
Hi All, I am trying to invoke my webservice which having a method take one parameter using REST my client code snippets is public class RestClient { private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname?param0=47";); public static void main(String[] args) { try { RESTCall call = new RESTCall(); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); call.setOptions(options); OMElement result= call.sendReceive(); System.out.println(result.getFirstElement().getText()); } catch (AxisFault axisFault) { System.out.println(axisFault+":"+axisFault.getMessage()); } catch (Exception axisFault) { System.out.println(axisFault+":"+axisFault.getMessage()); } } I am able to call the method by browser by the same url that has-been passed as a argument in EndPointReference() but when I am calling this by client I am getting following error in log file. org.apache.axis2.AxisFault: For input string: "47?"; nested exception is: java.lang.NumberFormatException: For input string: "47?"; nested exception is: org.apache.axis2.AxisFault: For input string: "47?"; nested exception is: java.lang.NumberFormatException: For input string: "47?" at org.apache.axis2.transport.http.util.RESTUtil.processGetRequest(RESTUtil.java:141) at org.apache.axis2.transport.http.AxisRESTServlet.doGet(AxisRESTServlet.java:36) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534) as you can sea the "?" is add automaticaly I am not able to find why it is so is this any bug in axis2 or I am missing something. Thanks Vimal Kumar Bansal -Original Message- From: Bansal, Vimal [mailto:[EMAIL PROTECTED] Sent: Monday, July 17, 2006 12:38 PM To: axis-user@ws.apache.org Subject: RE: problem in invoke the webservice using REST Style by client program Hi All, now i am using latest nightly build axis2.war at server side but problem is same as i am using RESTCall at client side but in nightly build axis2.war API i did'nt find any RESTCall class.can any one send me the clien
RE: problem in invoke the webservice using REST Style by client program
Hi All, now i am using latest nightly build axis2.war at server side but problem is same as i am using RESTCall at client side but in nightly build axis2.war API i did'nt find any RESTCall class.can any one send me the client code for access my webservice. using RESTCall. -Original Message- From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] Sent: Friday, July 14, 2006 4:29 PM To: axis-user@ws.apache.org Subject: RE: problem in invoke the webservice using REST Style by client program Hi, Vimal. Could you try latest nightly build axis2.war in server side, please ? --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > Hi kinichiro, > as per my earlier mail I am getting the access for my service using > following url by browser > http://localhost:8080/Axis2/rest/servicename/methodname?param0=23 > output is:- > - http://org.apache.axis2/xsd";> > hfdj > dfds > Andrews > pvcv > 21 > > this is nice . > now I am writing the client program for same my code snippets is > following: > > public class RestClient > { > private static EndpointReference targetEPR = new > EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname?param0=34";); > > public static void main(String[] args) { > try { > > > //ServiceClient sender = null; > RESTCall call = new RESTCall(); > Options options = new Options(); > options.setTo(targetEPR); > options.setTransportInProtocol(Constants.TRANSPORT_HTTP); > options.setProperty(Constants.Configuration.ENABLE_REST, > Constants.VALUE_TRUE); > > options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); > call.setOptions(options); > System.out.println("$$$ B4 sendReceive ... $$$ "); > OMElement result= call.sendReceive(); > System.out.println("$$$ After sendReceive ... "); > System.out.println(result.getFirstElement().getText()); > } > catch (AxisFault axisFault) { > > System.out.println(axisFault+":"+axisFault.getMessage()); > } > catch (Exception axisFault) { > > System.out.println(axisFault+":"+axisFault.getMessage()); > } > } >but i am not getting output I am getting following error message > at dos prompt. >org.apache.axis2.AxisFault: Incoming message input stream is > null:Incoming message input stream is null >what I am missing.url is same for both cases. > Thanks > Vimal Bansal > > -Original Message- > From: Bansal, Vimal [mailto:[EMAIL PROTECTED] > Sent: Friday, July 14, 2006 9:32 AM > To: axis-user@ws.apache.org > Subject: RE: problem to invoke the webservice using REST Style > > > Hi kinichiro, > Thanks for your response, now problem is fix and i am getting the > expected output.one can use RPCMessageReceiver for any > cases,the men thing is that i realize one shoud have only one method > define in your service class,in case of more than one > method you would'nt get the excees of all the method. > you can access your method via following url:- > http://localhost:8080/Axis2/rest/servicename/methodname?paramo=23 > remember parameter other than param0 in url is not allowed. > thanks > Vimal Bansal. > > > -Original Message- > From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] > Sent: Thursday, July 13, 2006 10:26 AM > To: axis-user@ws.apache.org > Subject: RE: problem to invoke the webservice using REST Style > > > Hi Bansal, > > Test class is like this. > > package test; > public class MyService1 { > public void ping(int element) { > System.out.println("value of input value = "+ element); > } > > public int echo(int element) { > return element * element; > } > } > > services.xml is like this. > > test service. > locked="false">test.MyService1 > > class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> > > > class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> > > > > You can call this by REST. > http://localhost:8080/axis2/rest/MyService1/ping?element=15 > > I could see this log message in tomcat stdout.log > value of input value = 15 > > It worked fine. > > Regards, > kinichiro > > --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > > > Hi kinichiro, > > I have t
RE: problem in invoke the webservice using REST Style by client program
Hi, Vimal. Could you try latest nightly build axis2.war in server side, please ? --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > Hi kinichiro, > as per my earlier mail I am getting the access for my service using > following url by browser > http://localhost:8080/Axis2/rest/servicename/methodname?param0=23 > output is:- > - http://org.apache.axis2/xsd";> > hfdj > dfds > Andrews > pvcv > 21 > > this is nice . > now I am writing the client program for same my code snippets is > following: > > public class RestClient > { > private static EndpointReference targetEPR = new > EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname?param0=34";); > > public static void main(String[] args) { > try { > > > //ServiceClient sender = null; > RESTCall call = new RESTCall(); > Options options = new Options(); > options.setTo(targetEPR); > options.setTransportInProtocol(Constants.TRANSPORT_HTTP); > options.setProperty(Constants.Configuration.ENABLE_REST, > Constants.VALUE_TRUE); > > options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); > call.setOptions(options); > System.out.println("$$$ B4 sendReceive ... $$$ "); > OMElement result= call.sendReceive(); > System.out.println("$$$ After sendReceive ... "); > System.out.println(result.getFirstElement().getText()); > } > catch (AxisFault axisFault) { > > System.out.println(axisFault+":"+axisFault.getMessage()); > } > catch (Exception axisFault) { > > System.out.println(axisFault+":"+axisFault.getMessage()); > } > } >but i am not getting output I am getting following error message > at dos prompt. >org.apache.axis2.AxisFault: Incoming message input stream is > null:Incoming message input stream is null >what I am missing.url is same for both cases. > Thanks > Vimal Bansal > > -Original Message- > From: Bansal, Vimal [mailto:[EMAIL PROTECTED] > Sent: Friday, July 14, 2006 9:32 AM > To: axis-user@ws.apache.org > Subject: RE: problem to invoke the webservice using REST Style > > > Hi kinichiro, > Thanks for your response, now problem is fix and i am getting the > expected output.one can use RPCMessageReceiver for any > cases,the men thing is that i realize one shoud have only one method > define in your service class,in case of more than one > method you would'nt get the excees of all the method. > you can access your method via following url:- > http://localhost:8080/Axis2/rest/servicename/methodname?paramo=23 > remember parameter other than param0 in url is not allowed. > thanks > Vimal Bansal. > > > -Original Message- > From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] > Sent: Thursday, July 13, 2006 10:26 AM > To: axis-user@ws.apache.org > Subject: RE: problem to invoke the webservice using REST Style > > > Hi Bansal, > > Test class is like this. > > package test; > public class MyService1 { > public void ping(int element) { > System.out.println("value of input value = "+ element); > } > > public int echo(int element) { > return element * element; > } > } > > services.xml is like this. > > test service. > locked="false">test.MyService1 > > class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> > > > class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> > > > > You can call this by REST. > http://localhost:8080/axis2/rest/MyService1/ping?element=15 > > I could see this log message in tomcat stdout.log > value of input value = 15 > > It worked fine. > > Regards, > kinichiro > > --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > > > Hi kinichiro, > > I have tried for this also but problem is same. can you check the > > link below, > > > > > http://ws.apache.org/axis2/0_95/api/org/apache/axis2/rpc/receivers/class-use/RPCInOnlyMessageReceiver.html > > > > in this it is clearly mention that there is no use of > > RpcInOnlyMessageReceiver.finding the method in service may be the > > problem. > > http://localhost:8080/axis2/rest/ServiceName/setData?num=10 > > can you send me the running sample code including > service.xml,client > > and service if you have. > > Thanks > > Vimal Bansal. > > > > -Original Message- > > From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, July 12, 2006 7:32 PM > > To: axis-user@ws.apache.org > > Subject: RE: problem to invoke the webservice using RESTt Style > > > > > > Hi Bansal, > > > > You must use RPCInOnlyMessageReceiver instead of > RPCMessageReceiver, > > because your method is void. > > > > Regards, > > kinichiro > > > > --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > > > > > Hi kinichiro, > > > Thanks again, tried my all st
RE: problem in invoke the webservice using REST Style by client program
Hi kinichiro, as per my earlier mail I am getting the access for my service using following url by browser http://localhost:8080/Axis2/rest/servicename/methodname?param0=23 output is:- - http://org.apache.axis2/xsd";> hfdj dfds Andrews pvcv 21 this is nice . now I am writing the client program for same my code snippets is following: public class RestClient { private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/Axis2/rest/servicename/methodname?param0=34";); public static void main(String[] args) { try { //ServiceClient sender = null; RESTCall call = new RESTCall(); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); options.setProperty(Constants.Configuration.HTTP_METHOD,Constants.Configuration.HTTP_METHOD_GET); call.setOptions(options); System.out.println("$$$ B4 sendReceive ... $$$ "); OMElement result= call.sendReceive(); System.out.println("$$$ After sendReceive ... "); System.out.println(result.getFirstElement().getText()); } catch (AxisFault axisFault) { System.out.println(axisFault+":"+axisFault.getMessage()); } catch (Exception axisFault) { System.out.println(axisFault+":"+axisFault.getMessage()); } } but i am not getting output I am getting following error message at dos prompt. org.apache.axis2.AxisFault: Incoming message input stream is null:Incoming message input stream is null what I am missing.url is same for both cases. Thanks Vimal Bansal -Original Message- From: Bansal, Vimal [mailto:[EMAIL PROTECTED] Sent: Friday, July 14, 2006 9:32 AM To: axis-user@ws.apache.org Subject: RE: problem to invoke the webservice using REST Style Hi kinichiro, Thanks for your response, now problem is fix and i am getting the expected output.one can use RPCMessageReceiver for any cases,the men thing is that i realize one shoud have only one method define in your service class,in case of more than one method you would'nt get the excees of all the method. you can access your method via following url:- http://localhost:8080/Axis2/rest/servicename/methodname?paramo=23 remember parameter other than param0 in url is not allowed. thanks Vimal Bansal. -Original Message- From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] Sent: Thursday, July 13, 2006 10:26 AM To: axis-user@ws.apache.org Subject: RE: problem to invoke the webservice using REST Style Hi Bansal, Test class is like this. package test; public class MyService1 { public void ping(int element) { System.out.println("value of input value = "+ element); } public int echo(int element) { return element * element; } } services.xml is like this. test service. test.MyService1 You can call this by REST. http://localhost:8080/axis2/rest/MyService1/ping?element=15 I could see this log message in tomcat stdout.log value of input value = 15 It worked fine. Regards, kinichiro --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > Hi kinichiro, > I have tried for this also but problem is same. can you check the > link below, > > http://ws.apache.org/axis2/0_95/api/org/apache/axis2/rpc/receivers/class-use/RPCInOnlyMessageReceiver.html > > in this it is clearly mention that there is no use of > RpcInOnlyMessageReceiver.finding the method in service may be the > problem. > http://localhost:8080/axis2/rest/ServiceName/setData?num=10 > can you send me the running sample code including service.xml,client > and service if you have. > Thanks > Vimal Bansal. > > -Original Message- > From: Kinichiro Inoguchi [mailto:[EMAIL PROTECTED] > Sent: Wednesday, July 12, 2006 7:32 PM > To: axis-user@ws.apache.org > Subject: RE: problem to invoke the webservice using RESTt Style > > > Hi Bansal, > > You must use RPCInOnlyMessageReceiver instead of RPCMessageReceiver, > because your method is void. > > Regards, > kinichiro > > --- "Bansal, Vimal" <[EMAIL PROTECTED]> wrote: > > > Hi kinichiro, > > Thanks again, tried my all stuff now I have just created one method > > in my service Say setdata(in num) my code snippets is below just > for > > testing purpose > > > >public void setData(int num) { > > System.out.println("Entry in setData"); > > System.out.println("value of num ="+ num); > > System.out.println("Exit from setData"); > > } > > and i am passing parameter via REST like this, > > http://localhost:8080/axis2/rest/ServiceName/setData?num=10 > > but i have the same problem i am not getting access of setdata() > > method. > > i have also c