Interface ResponseProcessor

All Known Implementing Classes:
HttpEntityProcessor, HttpResourceProcessor, HttpResponseProcessor, InputStreamProcessor, PlainTextPojoProcessor, ReaderProcessor, ResponseBeanProcessor, SerializedPojoProcessor, ThrowableProcessor

public interface ResponseProcessor
Defines the interface for processors that convert POJOs to appropriate HTTP responses.

The REST Server API uses the concept of registered response processors for converting objects returned by REST methods or set through RestResponse.setContent(Object) into appropriate HTTP responses.

Response processors can be associated with REST resources via the following:

Response processors can be used to process POJOs that cannot normally be handled through Juneau serializers, or because it's simply easier to define response processors for special cases.

The following example shows how to create a response processor to handle special Foo objects outside the normal Juneau architecture.

@Rest( path="/example", responseProcessors=FooProcessor.class ) public class Example extends BasicRestServlet { @RestGet("/") public Foo test1() { return new Foo("123"); } public static class FooProcessor implements ResponseProcessor { @Override public int process(RestOpSession opSession) { RestResponse res = opSession.getRestResponse(); Foo foo = res.getOutput(Foo.class); if (foo == null) return NEXT; // Let the next processor handle it. // Set some headers and content. res.setHeader("Foo-ID", foo.getId()); res.getWriter().write("foo.id=" + foo.getId()); return FINISHED; // We handled it. } } }

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Return code indicating that processing is complete and to exit the chain.
    static final int
    Return code indicating to proceed to the next response processor in the chain.
    static final int
    Return code indicating to restart processing the chain from the beginning.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Process this response if possible.
  • Field Details

    • NEXT

      static final int NEXT
      Return code indicating to proceed to the next response processor in the chain.
      See Also:
    • FINISHED

      static final int FINISHED
      Return code indicating that processing is complete and to exit the chain.
      See Also:
    • RESTART

      static final int RESTART
      Return code indicating to restart processing the chain from the beginning.
      See Also:
  • Method Details

    • process

      Process this response if possible.
      Parameters:
      opSession - The HTTP call.
      Returns:
      One of the following codes:
      • 0 - The processor could not handle the request.
      • 1 - The processor was able to fully handle the request.
      • 2 - The processor was able to partially handle the request by replacing the output. The response processors should start over.
      Throws:
      IOException - If low-level exception occurred on output stream.
      Results in a HttpServletResponse.SC_INTERNAL_SERVER_ERROR error.
      BasicHttpException - If some other exception occurred.
      Can be used to provide an appropriate HTTP response code and message.