| Author |
Populate a mysql database using POST method of RESTful Web Services
|
Jack Rooney
Greenhorn
Joined: Dec 04, 2012
Posts: 14
|
|
I am trying to create a restful webservice with Hibernate3/JPA that will be used populate a mysql db. I want to know how the post annotation will look like. I am new to Rest web services. I appreciate all your help and time.
This is my Stock class.
This is my HibernateUtil class .
This is my hibernate.cfg.xml file.
Here is my App class which will have the POST annotation.I know my implementation of the App class is incorrect. But I have been trying to look at a lot of tutorials,but couldnt understand what to do to post to the database.
Kindly help me out.
Thanks.
|
 |
Praful Thakare
Ranch Hand
Joined: Feb 10, 2001
Posts: 613
|
|
so whats is happening with this code? are you able to hit the webservice but record is not saved? are you getting any error? which framework are you using?
should @Path("/save") be @Path(value ="/save") and [b] @Produces(MediaType.APPLICATION_JSON) be [b] @Produces({ MediaType.APPLICATION_JSON) }) [b] ?
how have you defined your rest handler in web.xml? what is the url used to invoke this service?
|
All desirable things in life are either illegal, banned, expensive or married to someone else !!!
|
 |
Jack Rooney
Greenhorn
Joined: Dec 04, 2012
Posts: 14
|
|
Hello Praful,
Thanks for responding. In my code, I dont know if the POST annotation that I have written is correct or not. My URI is this : http://localhost:8080/HibernateApp/rest/save. When i run this on the localhost:8080, it gives me an error saying that "The specified HTTP method is not allowed for the requested resource." I am developing this using Hibernate3/JPA. Here is my web.xml .
Thanks for you time.
Regards,
Achal
|
 |
Praful Thakare
Ranch Hand
Joined: Feb 10, 2001
Posts: 613
|
|
okay can you send complete error line? I suspect it says something like
The specified HTTP method is not allowed for the requested resource for content type application/xml, application/bla bla bla
also try to invoke the rest call with setting header value of Content-Type to application/json or application/xml
I think your configuration is correct since you are not getting 404 which mean url is mapped to service but its just problem with mapping correct method.
how are you invoking the serivce? just pasting url in browser? to add headers I would suggest use RestClient a add-on for firefox.
let me know how it goes.
-P
|
 |
Jack Rooney
Greenhorn
Joined: Dec 04, 2012
Posts: 14
|
|
Hi Praful,
Here is the complete error :
HTTP Status 405 - Method Not Allowed
type Status report
message Method Not Allowed
description The specified HTTP method is not allowed for the requested resource.
I dont understand what you mean by the content type. Kindly let me know.
Thanks,
Regards,
Jack
|
 |
Praful Thakare
Ranch Hand
Joined: Feb 10, 2001
Posts: 613
|
|
do you mean you simply paste the above url in browser? if so then it will request for get method you have to mention that you want to invoke post.
again, try firefox restclient where you can select method before sending the request.
|
 |
 |
|
|
subject: Populate a mysql database using POST method of RESTful Web Services
|
|
|