Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post an XML file using a REST Client in Jersey

Tags:

jersey

I want to send an XML file and receive the response back as an XML file. The code that I am trying throws an exception, please could someone help. I am not sure what is going wrong here

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
String response = service.type(MediaType.APPLICATION_XML).accept(MediaType.TEXT_XML).post(String.class, new File("post.xml"));
    System.out.println(response);
like image 846
Monika Avatar asked Mar 09 '10 00:03

Monika


1 Answers

try it

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
String response = service.type(MediaType.APPLICATION_XML)
                         .accept(MediaType.TEXT_XML)
                         .entity(new File("post.xml"))
                         .post(String.class);
System.out.println(response);
like image 93
Rodrigo Araujo Avatar answered Sep 19 '22 17:09

Rodrigo Araujo