• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot William.

Nice link and code, I have saved huge time due to your help.
 
Rudra Narayan Garnaik
Ranch Hand
Posts: 39
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
reply
    Bookmark Topic Watch Topic
  • New Topic