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?
Just make an http request to the required URL with correct query string, or request body.
For example you could use
java.net.HttpURLConnection
and then consume viaconnection.getInputStream()
, and then covnert to your objects.In spring there is a
restTemplate
that makes it all a bit easier.JAX-RS but you can also use regular DOM that comes with standard Java
Apache Http Client APIs are very commonly used for calling HTTP Rest services.
Here is one of example of consuming HTTP GET call.
Use following maven dependency if using Maven project.
If you also need to convert that xml string that comes as a response to the service call, an x object you need can do it as follows:
Note that the xml structure that I expected in the example was as follows: