Monday, November 4, 2013

Using Java tools,
wscompile for RPC
wsimport for Document
I can use WSDL to generate the stub and Classes required to hit the SOAP Web Service.
But I have no idea how I can do the same in REST. How can I get the Java classes required for hitting the REST Web Service. What is the way to hit the service anyway?
Can anyone show me the way?
share|improve this question
Guys... I don't want to hit the Web Service using URLs. I want to hit using my Java Classes. Is there a way? – Mawia Oct 18 '12 at 9:14

5 Answers

You can use HttpURLConnection. Below is an example of calling a RESTful service using the Java SE APIs including JAXB:
String uri =
URL url = new URL(uri);
HttpURLConnection connection =
    (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept", "application/xml");

JAXBContext jc = JAXBContext.newInstance(Customer.class);
InputStream xml = connection.getInputStream();
Customer customer =
    (Customer) jc.createUnmarshaller().unmarshal(xml);

You can find the complete example here
share|improve this answer
From your question its not clear whether you are using any frameworks.For REST you will be getting an WADL & Apache CXF recently added support for WADL-first development of REST services.Please go through
share|improve this answer
Do you mean I can get the Java Classes from WADL? –  Mawia Oct 18 '12 at 5:54

No comments: