• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to Implement POST Method in RESTFul web services using Jersey

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you share your java code and the raw HTTP request ?
 
Maya sekar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
Hibernate Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic