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 
(https://url.domain.com/object.json)");
            cr.setRequestEntityB​​uffering(true);
            request = new JsonRepresentation(json);
            request.setMediaType​​(MediaType.APPLICAT​I​ON_JSON);
            request.setCharacter​​Set(CharacterSet.UT​F​_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();
                }  
Sorry for the multiple postings if this goes out multiple times.  Couldn't get 
the posting to go out before so tried multiple times.
--  

Reply via email to