Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Implement POST Method in RESTFul web services using Jersey

 
Maya sekar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share your java code and the raw HTTP request ?
 
Maya sekar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nikhil Das Nomula
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you add the @Consumes annotation too and try it. Something like the one shown below

 
Maya sekar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikhil,

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



Thank you
 
Subodh Ray
Greenhorn
Posts: 16
Eclipse IDE Hibernate Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Hibernate Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic