Class BodyHandler<B>

java.lang.Object
dev.relism.flash.models.RequestHandler
dev.relism.flash.models.BodyHandler<B>
Type Parameters:
B - the body type

public abstract class BodyHandler<B> extends RequestHandler
A handler whose request carries a body of a known type.

The type is the class's own type argument, so it is written once, in the signature:


 @POST("/users")
 public final class CreateUser extends JsonHandler<NewUser> {
     @Override protected Object handle(Request req, Response res, NewUser body) {
         return users.create(body);
     }
 }
 

Reading the body is the format's job: a subclass such as JsonHandler implements body(dev.relism.flash.models.Request) and declares its media type with @Consumes. Documentation tools read both off the class, which is what lets a request body be described without saying its type a second time.

  • Constructor Details

    • BodyHandler

      public BodyHandler()
  • Method Details

    • bodyTypeOf

      public static Class<?> bodyTypeOf(Class<?> handlerClass)
      The body type a handler class declares, or null when it leaves it open.

      Resolved through the whole chain, so an intermediate base class that passes its own type argument along answers with the type its subclass fixed.

    • bodyType

      protected final Class<B> bodyType()
      This handler's body type, for the reader in body(dev.relism.flash.models.Request). Null only on a handler left generic.
    • body

      protected abstract B body(Request request) throws Exception
      Reads the body in the format this handler speaks.
      Throws:
      Exception
    • handle

      protected abstract Object handle(Request request, Response response, B body) throws Exception
      Throws:
      Exception
    • handle

      public final Object handle(Request request, Response response) throws Exception
      Description copied from class: RequestHandler
      Handles an incoming request. The return value determines the response body: return a Response to replace the whole response, any other non-null value to set it as the body, or null to leave the response as-is.
      Specified by:
      handle in class RequestHandler
      Throws:
      Exception