I am trying to write a client application to connect to a restlet that I did
not write. It is a POST method using json. I have it working when the restlet
returns successfully but when an error code is returned say 422 Unprocessable
Entity, I can detect that the error code was returned but I also need to get
the Representation of the response since this contains details of the error
that I need. A sample of my code is below. The ResourceException is caught
and I see that it is an error code of 422 but as I said, I need to get the
response to see what happened.
cr = new ClientResource("https://url.domain.com/object.json");
cr.setRequestEntityBuffering(true);
request = new JsonRepresentation(json);
request.setMediaType(MediaType.APPLICATION_JSON);
request.setCharacterSet(CharacterSet.UTF_8);
Representation response = cr.post(request);
request.release();
JsonRepresentation returned = new JsonRepresentation(response);
JSONObject responseObject = returned.getJsonObject();
// Clean-up
returned.release();
response.release();
cr.release();
return responseObject;
} catch (ResourceException e) {
Representation response = cr.getResponseEntity();
}
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2900539