Reputation: 20571
In this
tutorial written how to create REST service and how to consume it. I confused by consuming example. There we need to have on client side jersey.jar
and write like this:
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
Why client need to know how web-service implemented(jersey or may be ohter implementation)? Why client side don't consume it by using simple InputStream
?
Upvotes: 0
Views: 6402
Reputation: 117
Simplest way to consume Restful web services is using Spring RestTemplate. http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/client/RestTemplate.html
Upvotes: 0
Reputation: 309
String URL ="http://localhost:8080/MyWServices/REST/WebService/";
String ws_method_name = "getManagerListByRoleID";
String WS_METHOD_PARAMS = "";
HttpClient httpClient = new DefaultHttpClient();
HttpContext httpContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(URL + ws_method_name + WS_METHOD_PARAMS);
String text = null;
try {
HttpResponse httpResponse = httpClient
.execute(httpGet, httpContext);
HttpEntity entity = httpResponse.getEntity();
text = getASCIIContentFromEntity(entity);
}catch(Exception e){
e.printStackTrace();
}
Upvotes: 0
Reputation: 26
In this particular tutorial you are using the jersey CLIENT to interact with a RESTful Service.
You could also just interact with the service directly by just manually creating an HTTP request and receiving the response and parsing accordingly(http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html).
The Jersey client is ultimately is just an abstraction of this to make it easier to work with.
Upvotes: 1