Class Action

java.lang.Object
com.xebialabs.restito.semantics.Action
All Implemented Interfaces:
Applicable

public class Action extends Object implements Applicable
Action is a modifier for Response
See Also:
  • Response
  • Method Details

    • apply

      public org.glassfish.grizzly.http.server.Response apply(org.glassfish.grizzly.http.server.Response r)
      Perform the action with response
      Specified by:
      apply in interface Applicable
    • success

      public static Action success()
      Sets HTTP status 200 to response. Consider using ok() as more concise and less ambiguous option.
      See Also:
    • ok

      public static Action ok()
      Sets HTTP status 200 to response
    • noContent

      public static Action noContent()
      Sets HTTP status 204 to response
    • status

      public static Action status(org.glassfish.grizzly.http.util.HttpStatus status)
      Sets HTTP status to response
    • resourceContent

      public static Action resourceContent(String resourcePath)
      Writes content and content-type of resource file to response. Tries to detect content type based on file extension. If can not detect - content-type is not set. For now there are following bindings:
      • .xml - `application/xml`
      • .json - `application/xml`
    • resourceContent

      public static Action resourceContent(String resourcePath, String charset)
    • resourceContent

      public static Action resourceContent(URL resourceUrl)
      Writes content using the specified encoding and content-type of resource file to response. Tries to detect content type based on file extension. If can not detect, content-type is not set. For now there are following bindings:
      • .xml - `application/xml`
      • .json - `application/xml`
    • resourceContent

      public static Action resourceContent(URL resourceUrl, Charset charset)
    • bytesContent

      public static Action bytesContent(byte[] content)
      Writes bytes content to response
    • stringContent

      public static Action stringContent(String content)
      Writes string content into response. Important: when using this method, the string gets encoded into a sequence of bytes using the platform's default charset. Please use stringContent(String, Charset) if you need to be specific about the encoding.
    • stringContent

      public static Action stringContent(String content, Charset charset)
      Writes string content into response. The passed charset is used: - To encoded the string into bytes; - As character set of the response. The latter will result in a
      charset=XXX
      part of
      Content-Type
      header if and only if the header has been set in some way (e.g. by using contentType(String) action. See `integration.CharsetAndEncodingTest` for more details.
    • header

      public static Action header(String key, String value)
      Sets key-value header on response
    • contentType

      public static Action contentType(String contentType)
      Sets content type to the response
    • charset

      public static Action charset(String charset)
      Sets charset of the response (must come before stringContent/resourceContent Action)
    • charset

      public static Action charset(Charset charset)
      Sets charset of the response (must come before stringContent/resourceContent Action)
    • unauthorized

      public static Action unauthorized()
      Returns unauthorized response with default realm name
    • unauthorized

      public static Action unauthorized(String realm)
      Returns unauthorized response
    • custom

      public static Action custom(Function<org.glassfish.grizzly.http.server.Response,org.glassfish.grizzly.http.server.Response> f)
      Perform set of custom actions on response
    • composite

      public static Action composite(Applicable... actions)
      Creates a composite action which contains all passed actions and executes them in the same order.
    • composite

      public static Action composite(Collection<Applicable> applicables)
      Creates a composite action which contains all passed actions and executes them in the same order.
    • composite

      public static Action composite(Action... actions)
      Creates a composite action which contains all passed actions and executes them in the same order.
    • noop

      public static Action noop()
      Doing nothing. To be used in DSLs for nicer syntax.
    • delay

      public static Action delay(Integer delay)
      Sleeps so many milliseconds, emulating slow requests.