active_coder
active_coder

Reputation: 79

Consuming a REST Webservice in JAVA which gives output as XML

I need to access a thirdparty REST Webservice via my java class which gives the response in xml format.

How can i write a sample java class to consume this thirdparty REST service?

After googling for several days, I came to an observation that i can consume webservice using Jersey. But still am not sure how can i use Jersey in my scenario as I just need to read the response from a thirdyparty webservice. Please help.

EDIT: I tried using the website http://pojo.sodhanalibrary.com/ to convert the xml response obtained by the webservice to POJO classes. But still am not sure what exactly I need to do to proceed further.

Upvotes: 0

Views: 11906

Answers (1)

Justinas Jakavonis
Justinas Jakavonis

Reputation: 8798

You need REST client for Java. There are several ways to implement it, more details can be found at:

Execute request, get response and parse it to your data structure. Jersey client example:

Client client = Client.create();

WebResource webResource = client.resource("http://localhost:8080/example/rest/service");

ClientResponse clientResponse = webResource.accept("application/xml").post(ClientResponse.class, yourRequestObject);

YourResponseType yourResponse = clientResponse.getEntity(YourResponseType.class);

Upvotes: 2

Related Questions