I am a complete beginner at REST services but I need to access some information via REST from a web site. The service has some sample code to show how to login that I have used. The sample code uses Jettison as a JSON parser but when I try to run the following code snippet I get an Exception:
JSONObject post = baseResource.path("login")
.queryParam("service", "ABC").queryParam("auth", authParam)
.accept(MediaType.APPLICATION_JSON_TYPE).post(JSONObject.class);
baseResourse is a WebResource object. The code fails with the following exception:
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException:
A message body reader for Java class org.codehaus.jettison.json.JSONObject, and
Java type class org.codehaus.jettison.json.JSONObject, and MIME media type
application/json; character=utf-8 was not found
The sample code does not suggest that I should need to add any "message body readers" to handle the response? Or do I need to add or do anything obvious to parse the response? Thanks.
You need to include jersey-json module on your classpath. See http://jersey.java.net/nonav/documentation/latest/chapter_deps.html#d4e1817