aspose file tools*
The moose likes Web Services and the fly likes Jersey RESTful web service - How to post XML file using jersey framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Jersey RESTful web service - How to post XML file using jersey framework" Watch "Jersey RESTful web service - How to post XML file using jersey framework" New topic
Author

Jersey RESTful web service - How to post XML file using jersey framework

Rudra Narayan Garnaik
Ranch Hand

Joined: May 05, 2006
Posts: 39
Hi All,

I am writing a RESTful web service which will take a XML file as input and process the same, and save it into database. I am new to RESTful web services(jersey), can anybody please help me how to achieve the things using jersey.

1- Please give any link if you have?
2- Sample code which will help me to undersatnd how I ll post xml to jersey.
3- May be any API where I can learn and do.
4- If we cant not achieve that or not good to do that way please suggest what is the best way to send XML file to my app using webservice.
5- Keep in mind I need a secure web service, I may send user credential with the xml file as a header/element.

Waiting for quick response as it is little urgent for me.


Many thanks in advance for your help.



Regards, Rudra Narayan
www.garnaik.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
If I understand you correctly, your problem is to create a client program to send a document to a RESTful service as a POST request, right?

You can use the standard library HttpURLConnection to do that - the fact that the document is formatted as XML makes no difference. This has come up before in this forum so do some searching. Doesn't the Jersey download include some client examples?

Bill

Rudra Narayan Garnaik
Ranch Hand

Joined: May 05, 2006
Posts: 39
Thanks for your quick response, exactly I want to know how my jersey client lwill post a XML file. Can you please give here some sample code or link for quick reference? I will try my best to search but i am completely new to webservices as well as jersey.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
A major point about using RESTful style is that the methods used are exactly HTTP methods as used all over in the web clients and servers. So all you really need to learn is the way a HTTP POST works.

See this wikipedia discussion for background.

Here is a bare-bones example in which the body of the request was available as a String.

Rudra Narayan Garnaik
Ranch Hand

Joined: May 05, 2006
Posts: 39
Thanks a lot William.

Nice link and code, I have saved huge time due to your help.
Rudra Narayan Garnaik
Ranch Hand

Joined: May 05, 2006
Posts: 39
Anybody Interested- Please refere:

http://download.oracle.com/javaee/6/tutorial/doc/gkoib.html


Sample Code:
======================
Server code:



URL for this in local machine :

http://localhost:8080/RESTful/test/xmltest/


Client Program :




Happy Jersey coding.
R Patel
Greenhorn

Joined: May 24, 2010
Posts: 13


Thanks for this post and code snippets ,,, it really helped me a lot,,, and m sure will show the way to many others.....

Thanks
Ronak.
Michael Munsey
Greenhorn

Joined: Feb 08, 2012
Posts: 2
Bumping an old thread...

There is a good example of how to do this at http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-jersey-client/

String input = "{\"singer\":\"Metallica\",\"title\":\"Fade To Black\"}";
ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jersey RESTful web service - How to post XML file using jersey framework