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

The following are Jave code examples for showing how to use getEntity() 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;
}
 
Example 2
Project: polygene-java   File: ResponseReaderDelegator.java   Source Code and License Vote up 5 votes
@Override
public Object readResponse( Response response, Class<?> resultType )
{
   if (resultType.equals(Representation.class))
      return response.getEntity();

   for (ResponseReader responseReader : responseReaders)
   {
      Object result = responseReader.readResponse( response, resultType );
      if (result != null)
         return result;
   }

   return null;
}
 
Example 3
Project: prudence   File: DelegatedStatusService.java   Source Code and License Vote up 4 votes
@Override
public Representation toRepresentation( Status status, Request request, Response response )
{
	if( isEnabled() )
	{
		ConcurrentMap<String, Object> attributes = response.getAttributes();

		Object passthrough = attributes.get( PASSTHROUGH_ATTRIBUTE );
		if( ( passthrough != null ) && (Boolean) passthrough )
			// Pass through
			return response.getEntity();

		Restlet handler = handlers.get( status.getCode() );
		if( handler != null )
		{
			// Reset the response
			response.setStatus( Status.SUCCESS_OK );
			response.setEntity( null );

			// Clean up saved information
			CachingUtil.clearExistingValidDocumentName( request );

			// Delegate
			handler.handle( request, response );

			// Return the status
			response.setStatus( status );

			Representation representation = response.getEntity();
			if( representation != null )
			{
				// Avoid client caching, which would require other
				// interchanges with the client that we can't handle from
				// here
				representation.setExpirationDate( null );
				representation.setModificationDate( null );
				representation.setTag( null );
			}

			attributes.put( PASSTHROUGH_ATTRIBUTE, true );
			return representation;
		}

		if( isFallback )
			// Fallbacks don't override the entity if there are no handlers
			return response.getEntity();

		if( isDebugging() && ( status.getThrowable() != null ) )
		{
			// Use the debug representation for exceptions
			attributes.put( PASSTHROUGH_ATTRIBUTE, true );
			if( debugHeader != null )
				RestletUtil.getResponseHeaders( response ).set( debugHeader, "error" );
			return createDebugRepresentation( status, request, response );
		}
	}

	return super.toRepresentation( status, request, response );
}