Using Java tools,
wscompile for RPC
wsimport for Document
etc..
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?
解决方案
You can use HttpURLConnection.
Below is an example of calling a RESTful service using the Java SE APIs including JAXB:
String uri =
"http://localhost:8080/CustomerService/rest/customers/1";
URL url = new URL(uri);
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
JAXBContext jc = JAXBContext.newInstance(Customer.class);
InputStream xml = connection.getInputStream();
Customer customer =
(Customer) jc.createUnmarshaller().unmarshal(xml);
connection.disconnect();
You can find the complete example here