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.c​om/object.json";);
            cr.setRequestEntityB​uffering(true);
            request = new JsonRepresentation(json);
            request.setMediaType​(MediaType.APPLICATI​ON_JSON);
            request.setCharacter​Set(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

Reply via email to