aspose file tools*
The moose likes Web Services and the fly likes Send PUT to different RESTful webservice running on the same local Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Send PUT to different RESTful webservice running on the same local Tomcat?" Watch "Send PUT to different RESTful webservice running on the same local Tomcat?" New topic
Author

Send PUT to different RESTful webservice running on the same local Tomcat?

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Hello, I am trying to send a HTTP PUT to a webapp (which supports REST) using my webservice which is on the same local tomcat instance.

Am new to RESTful Web Services and am using JDK 1.6, Tomcat 7, Jersey, and JSON.

I have my POJOs defined like this:





Using a PersonUtil class, I hardcoded the POJOs as follows:



Am able to create a JSON response per a GET request:



This yields this when deploying the war to tomcat and pointing the browser to http://localhost:8080/personservice/:



So far, so good, however, I have a different app which is running on the same tomcat instance (and has support for REST) at this URL:



While tomcat is running, I can issue a PUT like this:



When I "GET" it like this:



It yields:


Hello World


What I need to do is create a PUT which will put my entire Person generated JSON to this:

http://localhost:8080/differentservice/rest/person

and when I do a "GET" on this previous URL, it should look like this:



So, far, this is what my PUT looks like:



Is this the correct way to write the PUT using CURL?

Thanks for taking the time to read this...
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
what happens when you invoke put?


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Thank you for responding, Prakful!

After I wrote this posting, I figured out that I indeed was quite vague in my @PUT method. I revised it and added a comment.

Checked out my revised sendPerson() method and let me know what you think?

What I am seeking to do is something like this, invoke the @PUT method like this (from the command line):

curl -X PUT http://localhost:8080/personservice/differentservice/rest/person

However, this is also confusing because the my JSON file is generated by my webservice... Should I use HTTP Client?

I never thought it was so hard to use a PUT method in a CURL -X or even setup Restful Web Service in Jersey to send a JSON to a different service.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
okay, if I understand you correctly, you have 2 different services one gives you some data that you want to send to different service.
so obviously here we have two different requests 1) get data 2) send same data. so you need some kind of client that holds the response for input for next request.

there are many options like, Soap UI, firefox's restclient, groovy script etc.

i would say take it step by step. call your put service by manually sending data. if you use restclient plugin from firefox then just past json data in body.

btw, why is it a put and not post?
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Praful,

Thank you so much for the response! You are right... Its supposed to be a POST method. I decided to use Jersey Client and created a simpler new post to the forum located here.

Thank you for your support...

-James

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
great, I hope you have changed @PUT to @Post in your service class
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Yeah... But it didn't do me any good... Please check out that link and let me know your feedback (if you have available time).
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
yeah I did see your link,nothing looks wrong, I would suggest try once with Rest client a firefox plugin, its very simple and fast way to test rest calls.
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Yeah, but its needs to be automated... If there was nothing wrong than why did it throw an exception?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
won't be able to comment on that unless I get it running locally which I cannot till weekend.
well I understand the requirement is to automate it but using tools like RestClient for development and testing helps to speed the process.
for instance changing method, data, contenttype is just matter of clicks where as in java code you have to modify code,compile,deploy etc...

Also if it works with client tools then you are assured that server setup is correct and you need to work with fixing the client code.
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Thanks
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
These web services are going to be utilized by Unix Shell Scripts (using CURL) for automation purposes. Its against my requirements to use tools such as restclient.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
:-) sorry if I confused you, I am suggesting to use it for production , its just helpful to use it during development phase as its faster and if things work with such tool then you are 100% sure your server code is fine.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Send PUT to different RESTful webservice running on the same local Tomcat?