Interface Response

All Known Subinterfaces:
SelfResponseFactory
All Known Implementing Classes:
NopResponse, PathArgumentParseException, StandardErrorResponse, StatusOnlyResponse

public interface Response
An object that knows how to express itself via HTTP to the client. In other words, this interface is implemented by objects that can transmit themselves to the client using a ResponseTransmitter.

Most application-level objects do not implement this interface because they are defined on a higher level than HTTP. These objects do not even know how to express themselves as JSON, but they do have a JsonSerializer registered in the JsonRegistries, so at least that can be used to generate JSON. However, this is not by itself sufficient to express via HTTP.

Instead, on a lower level, a ResponseFactory is selected that further converts the JSON to a Response. Likewise, other values such as uncaught exceptions are also converted to a Response, either by an appropriate factory or by the framework itself. The result is that no matter what happens, in the end an instance of this interface is the result, and that instance is asked to transmit itself to the client.

The response transmitter used here is simply an abstraction of the HttpServletResponse that we use to decouple our code from unnecessary parts of the servlet spec.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    transmit(ResponseTransmitter responseTransmitter)
    Transmits this response using the specified response transmitter.
  • Method Details

    • transmit

      void transmit(ResponseTransmitter responseTransmitter) throws IOException
      Transmits this response using the specified response transmitter.

      Note: This method only takes the response transmitter. If the implementation has to access other things from the RequestCycle to transmit itself, e.g. access request parameters on-the-fly, then these things have to be passed to the implementation by another mechanism. This interface tries to keep the dependency between the two minimal.

      Parameters:
      responseTransmitter - the response transmitter that is used to actually send data to the client
      Throws:
      IOException - on I/O errors