How can I access a Restful webservice using servlet?
Is there any way I can access 开发者_StackOverflowRESTful webservice using a servlet. I dont want to use Jersey client?
EDIT: How can I pass object in the url and make sure that marshalling/unmarshalling is done properly?You can use the commons-httpclient library (http://hc.apache.org/httpcomponents-client-ga/) to make a request to your REST service, and gson (http://code.google.com/p/google-gson/) to serialize/deserialize java objects to JSON
You could code your own HTTP requests e.g. using HTTPURLConnection. Here you can set the request method and change the URL or/and body as appropiate e.g.
URL url = new URL("http://www.example.com/resource");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// etc
This way you're just using the standard java.net
API.
You don't need to use jersey client, it's just a URL, you can use:
new URL("http://locationofservice").openConnection();
精彩评论