Class ActeurFactory

java.lang.Object
com.mastfrog.acteur.ActeurFactory

public class ActeurFactory extends Object
Factory for standard Acteur implementations, mainly used to determine if a request is valid (matches a URL, is using a supported HTTP method, etc.). Usage model: Ask for this in your Page constructor and use it to add acteurs. Almost all methods on this class can be used via annotations, so using this class directly is rare post Acteur 1.4.
Author:
Tim Boudreau
  • Constructor Details

    • ActeurFactory

      @Inject public ActeurFactory()
  • Method Details

    • matchMethods

      @Deprecated public Acteur matchMethods(Method... methods)
      Deprecated.
      Use &#064Methods instead - it is self-documenting
      Reject the request if it is not one of the passed HTTP methods
      Parameters:
      methods - Methods
      Returns:
      An Acteur that can be used in a page
    • matchMethods

      public Acteur matchMethods(boolean notSupp, Method... methods)
      Reject the request if it is not an allowed HTTP method, optionally including information in the response, or simply rejecting the request and allowing the next page a crack at it.
      Parameters:
      notSupp - If true, respond with METHOD_NOT_ALLOWED and the ALLOW header set
      methods - The http methods which are allowed
      Returns:
      An Acteur
    • exactPathLength

      public Acteur exactPathLength(int length)
    • minimumPathLength

      public Acteur minimumPathLength(int length)
    • maximumPathLength

      public Acteur maximumPathLength(int length)
    • redirect

      public Acteur redirect(String location) throws URISyntaxException
      Throws:
      URISyntaxException
    • redirect

      public Acteur redirect(String location, io.netty.handler.codec.http.HttpResponseStatus status) throws URISyntaxException
      Throws:
      URISyntaxException
    • injectRequestBodyAsJSON

      public <T> Acteur injectRequestBodyAsJSON(Class<T> type)
      Creates an Acteur which will read the request body, construct an object from it, and include it for injection into later Acteurs in the chain.
      Type Parameters:
      T -
      Parameters:
      type - The object type
      Returns:
      An acteur
    • injectRequestParametersAs

      public <T> Acteur injectRequestParametersAs(Class<T> type)
      Create an acteur which will take the request parameters, turn them into an implementation of some interface and include that in the set of objects later Acteurs in the chain can request for injection.

      Note that you may need to include the type in your application's @ImplicitBindings annotation for Guice to allow your type to be injected.

      The type must be an interface type, and its methods should correspond exactly to the parameter names desired.

    • responseCode

      public Acteur responseCode(io.netty.handler.codec.http.HttpResponseStatus status)
      Create an Acteur which simply always responds with the given HTTP status.
      Parameters:
      status - A status
      Returns:
      An acteur
    • requireParameters

      public Acteur requireParameters(String... names)
      Reject the request unless certain URL parameters are present
      Parameters:
      names - The parameter names
      Returns:
      An acteur
    • parametersMayNotBeCombined

      public Acteur parametersMayNotBeCombined(String... names)
    • parametersMustBeNumbersIfTheyArePresent

      public Acteur parametersMustBeNumbersIfTheyArePresent(boolean allowDecimal, boolean allowNegative, String... names)
    • banParameters

      public Acteur banParameters(String... names)
      Reject request which contain the passed parameters
      Parameters:
      names - A list of parameter names for the URL
      Returns:
      An acteur
    • requireAtLeastOneParameter

      public Acteur requireAtLeastOneParameter(String... names)
      Reject the request if none of the passed parameter names are present
      Parameters:
      names -
      Returns:
    • matchPath

      @Deprecated public Acteur matchPath(String... regexen)
      Deprecated.
      Use &#064PathRegex instead - it is self-documenting
      Reject the request if HttpEvent.path().toString() does not match one of the passed regular expressions
      Parameters:
      regexen - Regexen
      Returns:
      An acteur
    • matchPath

      @Deprecated public Acteur matchPath(boolean decode, String... regexen)
      Deprecated.
    • sendNotModifiedIfETagHeaderMatches

      public Acteur sendNotModifiedIfETagHeaderMatches()
      Checks the IF_NONE_MATCH header and compares it with the value from the current Page's getETag() method. If it matches, forces a NOT_MODIFIED http response and ends processing of the chain of Acteurs.
      Returns:
      An acteur
    • sendNotModifiedIfETagHeaderMatchesType

      public Class<? extends Acteur> sendNotModifiedIfETagHeaderMatchesType()
    • globPathMatch

      public Acteur globPathMatch(String... patterns)
    • globPathMatch

      public Acteur globPathMatch(boolean decode, String... patterns)
    • sendNotModifiedIfIfModifiedSinceHeaderMatches

      public Acteur sendNotModifiedIfIfModifiedSinceHeaderMatches()
      Check the "If-Modified-Since" header and compares it to the current Page's getLastModified (rounding milliseconds down). If the condition is met, responds with NOT_MODIFIED.
      Returns:
      an Acteur
    • sendNotModifiedIfIfModifiedSinceHeaderMatchesType

      public Class<? extends Acteur> sendNotModifiedIfIfModifiedSinceHeaderMatchesType()
    • preconditionFailedIfUnmodifiedSinceMatches

      public Acteur preconditionFailedIfUnmodifiedSinceMatches()
      Check the "If-Unmodified-Since" header
      Returns:
      an Acteur
    • preconditionFailedIfUnmodifiedSinceMatchesType

      public Class<? extends Acteur> preconditionFailedIfUnmodifiedSinceMatchesType()
    • respondWith

      public Acteur respondWith(int status)
    • respondWith

      public Acteur respondWith(int status, String msg)
    • respondWith

      public Acteur respondWith(io.netty.handler.codec.http.HttpResponseStatus status, String msg)
    • respondWith

      public Acteur respondWith(io.netty.handler.codec.http.HttpResponseStatus status)
    • minimumBodyLength

      public Acteur minimumBodyLength(int length)
    • maximumBodyLength

      public Acteur maximumBodyLength(int length)
    • requireParametersIfMethodMatches

      public Acteur requireParametersIfMethodMatches(Method method, String... params)
    • redirectEmptyPath

      public Acteur redirectEmptyPath(String to) throws URISyntaxException
      Throws:
      URISyntaxException
    • redirectEmptyPath

      public Acteur redirectEmptyPath(Path to) throws URISyntaxException
      Throws:
      URISyntaxException
    • branch

      public Acteur branch(Class<? extends Acteur> ifTrue, Class<? extends Acteur> ifFalse, ActeurFactory.Test test)