Java Code Examples for org.restlet.Response.toString()

The following are Jave code examples for showing how to use toString() of the org.restlet.Response class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Camel   File: RestletProducer.java   Source Code and License Vote up 5 votes
protected RestletOperationException populateRestletProducerException(Exchange exchange, Response response, int responseCode) {
    RestletOperationException exception;
    String uri = response.getRequest().getResourceRef().toString();
    String statusText = response.getStatus().getDescription();
    Map<String, String> headers = parseResponseHeaders(response, exchange);
    String copy;
    if (response.getEntity() != null) {
        try {
            copy = response.getEntity().getText();
        } catch (Exception ex) {
            copy = ex.toString();
        }
    } else {
        copy = response.toString();
    }
    if (responseCode >= 300 && responseCode < 400) {
        String redirectLocation;
        if (response.getStatus().isRedirection()) {
            redirectLocation = response.getLocationRef().getHostIdentifier();
            exception = new RestletOperationException(uri, responseCode, statusText, redirectLocation, headers, copy);
        } else {
            //no redirect location
            exception = new RestletOperationException(uri, responseCode, statusText, null, headers, copy);
        }
    } else {
        //internal server error(error code 500)
        exception = new RestletOperationException(uri, responseCode, statusText, null, headers, copy);
    }

    return exception;
}