my dog learned polymorphism*
The moose likes Web Services and the fly likes How to Implement POST Method in  RESTFul web services using Jersey Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to Implement POST Method in  RESTFul web services using Jersey " Watch "How to Implement POST Method in  RESTFul web services using Jersey " New topic
Author

How to Implement POST Method in RESTFul web services using Jersey

Maya sekar
Ranch Hand

Joined: Sep 22, 2011
Posts: 70
Hi Everyone

I have been working on simple RESTFul Web Services lately, with jersey on Eclipse, Apache Tomcat Server v 6.0.32. I can get the GET Functions to work just fine. But when I try POST Methods, using the Post annotation and deploy it, I get the "method not allowed" msg. I can't seem to figure out why. Any idea on how I can get it to work?

Thank you
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Can you share your java code and the raw HTTP request ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Maya sekar
Ranch Hand

Joined: Sep 22, 2011
Posts: 70



accessed through the link, http://localhost:9090/RestSample/login?username=maya
Something as simple as this does not work.

Thank you
John M Brown
Ranch Hand

Joined: Nov 29, 2001
Posts: 62
Not sure what is specifically wrong based on the code and request supplied, but it may be a configuration problem. I remember getting this error before when I did not have the docroot base URI configured right and the URI hierarchy was one level deeper than I expected when implementing a Restbucks sample application.

You might want to check where the base URI is configured in the project.


<a href="mailto:JBROWN2002@cfl.rr.com" rel="nofollow">JBROWN2002@cfl.rr.com</a>
Nikhil Das Nomula
Greenhorn

Joined: Jun 10, 2011
Posts: 26
Can you add the @Consumes annotation too and try it. Something like the one shown below

Maya sekar
Ranch Hand

Joined: Sep 22, 2011
Posts: 70
Hi Nikhil,

I gave your suggestion a try, but the result is still the same. 405 Method Not Allowed.



Thank you
Subodh Ray
Greenhorn

Joined: Dec 01, 2011
Posts: 16

Try to use this way,

@POST
@Path("/create")
@Produces("text/plain")
public String sayHello(@QueryParam("username") String username)
{
return "Hello "+username;
}



and call the Uri by using Poster plugin of Mozilla or etc.
Maya sekar
Ranch Hand

Joined: Sep 22, 2011
Posts: 70
Hi Subodh ,


Took your advice. Added Poster add ons to the FireFox browser and pasted the url on the pop up window and clicked on POST . I now get a 403 Forbidden Error.

Subodh Ray
Greenhorn

Joined: Dec 01, 2011
Posts: 16

Are you using transaction or any filter interceptor in your application. If not then please post your exact signature of method in resource layer, and how will you call it on your poster.
and if you are using transaction management with configuration then please check the methods type you allowed for it or if any interceptor then please check the interceptor configuration.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Implement POST Method in RESTFul web services using Jersey