Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Services and the fly likes RestFul web services with Axis 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "RestFul web services with Axis 2" Watch "RestFul web services with Axis 2" New topic
Author

RestFul web services with Axis 2

yash wardhan
Ranch Hand

Joined: Jan 22, 2008
Posts: 46
Hi All,

I am new to web service and I have to implement RESTFul web service using Axis2.
I have created the service and it is working fine when tested with normal http client.
But when I am trying to call it through other client getting error saying content-type required. When set the content type in client code getting other error which says can not create SOAPEnvelop for REST.

Has enyone faced the same issue ever and able to resolve? If so please tell me how to do it?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by yash wardhan:
I am new to web service and I have to implement RESTFul web service using Axis2.


Both Axis 2 and JAX-WS claim to support RESTful web services - in my opinion they are not ideal for the development of RESTful web services.
That is why JAX-RS (JSR-311) was developed which is currently implemented in Jersey and then there is also Restlet.

I'm not expecting the REST support under JAX-WS (and Axis2) to develop any further and wouldn't be surprised if it was deprecated in the future. So it may make more sense for you to switch to an alternative framework whose main focus is the development of RESTful web services.

How NOT to do RESTful Web Services (2007 Jun)
yash wardhan
Ranch Hand

Joined: Jan 22, 2008
Posts: 46
Hi Peer,
Can you please point me to an article or tutorial of creating RESTFul web services which will have end to end steps of developing a sample application?
I googled but didn't find anything helpful(may be I haven't searched it properly).
It would be really nice if that application doesn't use any IDE or just eclipse.

Thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
Not sure about articles, but the Jersey library Peer linked to comes with a number of examples, some of which are pretty basic. The "Get Started" section on its "Learn" page has a number of useful links to introductory material. No IDE is required, and the services can be deployed in a standard servlet container such as Tomcat.


Ping & DNS - my free Android networking tools app
yash wardhan
Ranch Hand

Joined: Jan 22, 2008
Posts: 46
Thanks for Reply,

Actually what I am trying to do is create the RESTFul web service.
It is working fine from java http client.
When tried to call it with j2me client it is working for GET but not for POST.
When the content-type is set through setRequestProperty() method, at the server side getting an error as
"Error in creating a SOAPEnvelope from the REST request".
When I set the content-type from my java http client, then also getting the same error.

Please help me in solving this problem.
Thanks
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by yash wardhan:
"Error in creating a SOAPEnvelope from the REST request".


RESTful web services usually don't choose SOAP envelopes as a representation. This leads me to believe that there is a much more fundamental error at work here - one that cannot be uncovered from the limited information that you are giving here.

Originally posted by yash wardhan:
It is working fine from java http client.
When tried to call it with j2me client it is working for GET but not for POST.


How does the code between the two differ?
What do the HTTP requests/responses look like for both the java http client and the j2me client? (and what is the difference?)

(Use something like Apache TCPMon (Tutorial) or java.net tcpmon to capture/view the HTTP request/response pairs)
[ December 23, 2008: Message edited by: Peer Reynders ]
yash wardhan
Ranch Hand

Joined: Jan 22, 2008
Posts: 46
Hi Peer,


How does the code between the two differ?
What do the HTTP requests/responses look like for both the java http client and the j2me client? (and what is the difference?)


The http client for java and j2me is same. And there is a normal class with reader and writer. Java's client uses HttpUrlConnection and that of j2me uses the HttpConnection object.
When the request is made from java client I am getting the response.
But when requested from j2me getting an error like
"ContentType should be given to proceed,according to WSDL 2.0 HTTP binding rules".
When the content type is set explicitly, getting the exception as .
Error in creating a SOAPEnvelope from the REST request
This is happening for both java client and j2me client when content-type is set explicitly.

One more question.
Till now I was taking help of IDE to do all the stuff for me. But I don't want that. So I decided to create the aar manually using build file. I am able to create the aar with the same structure as that of the one created by the IDE, but when I deploy it and try from my client(java client which is working well) getting an exception as
"SEVERE: org.apache.axis2.AxisFault: Required element null defined in the schema can not be found in the request".
Can you please tell me what am I missing?

Sorry for the long reply Peer,the exceptions may be basic but I am facing problems to resolve them. Thanks for your reply Peer.

Regards,
Yash
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by yash wardhan:

When the request is made from java client I am getting the response.
But when requested from j2me getting an error like
"ContentType should be given to proceed,according to WSDL 2.0 HTTP binding rules".
When the content type is set explicitly, getting the exception as .
Error in creating a SOAPEnvelope from the REST request
This is happening for both java client and j2me client when content-type is set explicitly.


  • What is the difference in the actual HTTP requests?
  • While it makes sense to use a RESTful web service for a J2ME client it makes no sense to still use SOAP. The is something very wrong with this approach. If you want SOAP, use JAX-RPC through JSR 172, J2ME Web Services Specification. If you want RESTful forget about SOAP and WSDL.

  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: RestFul web services with Axis 2
     
    Similar Threads
    New to webservice
    RESTful Web Services:About the book
    could not find writer for content-type application/xml type:
    New to web service
    Flex UI and Restful Web Service Wars deployed on the same Tomcat