juzu

## Class Response

- java.lang.Object
- - juzu.Response

- Direct Known Subclasses:
    Response.Error, Response.Redirect, Response.Status, Response.View

      public abstract class Response
      extends Object

  A response object signalling to the framework the action to take after an interaction. This object is usually returned after the invocation of a controller method and instructs the action to perform.

  ## Action response

  ### Redirection response

  A `Response.Process.Action.Redirect` response instructs Juzu to make a redirection to a valid URL after the interaction, this kind of response is created using the factory method `redirect(String)`: ``

          return Response.redirect("http://www.exoplatform.org");

  ### Proceed to render phase

  A `Response.View` response instructs Juzu to proceed to the render phase of a valid view controller, this kind of response can be created using an `juzu.request.ActionContext`, however the best way is to use a controller companion class that carries method factories for creating render responses.

  Type safe `Response.View` factory method are generated for each view or resource controller methods. The signature of an render factory is obtained by using the same signature of the controller method.

  `

          public class MyController {

             @Action
             public Response.View myAction() {
                return MyController_.myView("hello");
             }

             @View
             public void myView(String param) {
             }
          }

  `

  ## Mime response

  Mime response are used by the `Phase.VIEW` and the `Phase.RESOURCE` phases. Both contains a content to be streamed to the client but still they have some noticeable differences.

  The `Response.Content` class is the base response class which will work well for the two phases. However the `Phase.VIEW` can specify an optional title and the `Phase.RESOURCE` can specify an optional status code for the user agent response.

  Responses are created using the `Response` factory methods such as

  - `ok()` creates an ok response
  - `notFound()` creates a not found response

  Response can also created from `Template` directly:

  `

          public class MyController {

             @Inject @Path("index.gtmpl") Template index;

             @View
             public Response.Content myView() {
                return index.ok();
             }

             @Inject @Path("error.gtmpl")  Template error;

             @Resource
             public Response.Content myView() {
                return error.notFound();
             }
          }

  `

  The `Template.Builder` can also create responses:

  `

          public class MyController {

             @Inject @Path("index.gtmpl") index index;

             @View
             public Response.Content myView() {
                return index.with().label("hello").ok();
             }
          }

  `
  Author:
    Julien Viet

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Response.Body`
    `static class` | `Response.Content`
    `static class` | `Response.Error`
    `static class` | `Response.Redirect` A response instructing to execute an HTTP redirection after the current interaction.
    `static class` | `Response.Status`
    `static class` | `Response.View` A response instructing to execute a render phase of a controller method after the current interaction.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Response.Content` | `content(int code, byte[] content)`
    `static Response.Content` | `content(int code, CharSequence content)`
    `static Response.Content` | `content(int code, InputStream content)`
    `static Response.Content` | `content(int code, Readable content)`
    `static Response.Content` | `content(int code, Streamable content)`
    `static Response.Error` | `error(String msg)`
    `static Response.Error` | `error(Throwable t)`
    `PropertyMap` | `getProperties()`
    `static Response.Status` | `notFound()`
    `static Response.Content` | `notFound(byte[] content)`
    `static Response.Content` | `notFound(CharSequence content)`
    `static Response.Content` | `notFound(InputStream content)`
    `static Response.Content` | `notFound(Readable content)`
    `static Response.Status` | `ok()`
    `static Response.Content` | `ok(byte[] content)`
    `static Response.Content` | `ok(CharSequence content)`
    `static Response.Content` | `ok(InputStream content)`
    `static Response.Content` | `ok(Readable content)`
    `static Response.Redirect` | `redirect(String location)`
    `static Response.Status` | `status(int code)`
    `Response` | `with(PropertyType<Boolean> propertyType)` Set a boolean property to true.
    `<T> Response` | `with(PropertyType<T> propertyType, T propertyValue)` Set a property, if the value is null, the property is removed.
    `Response` | `withHeader(String name, String... value)`
    `Response` | `withNo(PropertyType<Boolean> propertyType)` Set a boolean property to false.
    `<T> Response` | `without(PropertyType<T> propertyType)` Removes a property.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### with

          public <T> Response with(PropertyType<T> propertyType,
                          T propertyValue)
                        throws NullPointerException

      Set a property, if the value is null, the property is removed.
      Parameters:
        `propertyType` - the property type
        `propertyValue` - the property value
      Throws:
        `NullPointerException` - if the property type is null

    - #### without

          public <T> Response without(PropertyType<T> propertyType)
                           throws NullPointerException

      Removes a property.
      Parameters:
        `propertyType` - the property type
      Throws:
        `NullPointerException` - if the property type is null

    - #### with

          public Response with(PropertyType<Boolean> propertyType)
                        throws NullPointerException

      Set a boolean property to true.
      Parameters:
        `propertyType` - the property type
      Throws:
        `NullPointerException` - if the property type is null

    - #### withNo

          public Response withNo(PropertyType<Boolean> propertyType)
                          throws NullPointerException

      Set a boolean property to false.
      Parameters:
        `propertyType` - the property type
      Throws:
        `NullPointerException` - if the property type is null

    - #### getProperties

          public final PropertyMap getProperties()

    - #### withHeader

          public Response withHeader(String name,
                            String... value)

    - #### redirect

          public static Response.Redirect redirect(String location)

    - #### status

          public static Response.Status status(int code)

    - #### ok

          public static Response.Status ok()

    - #### notFound

          public static Response.Status notFound()

    - #### ok

          public static Response.Content ok(InputStream content)

    - #### ok

          public static Response.Content ok(byte[] content)

    - #### ok

          public static Response.Content ok(Readable content)

    - #### ok

          public static Response.Content ok(CharSequence content)

    - #### notFound

          public static Response.Content notFound(byte[] content)

    - #### notFound

          public static Response.Content notFound(InputStream content)

    - #### notFound

          public static Response.Content notFound(Readable content)

    - #### notFound

          public static Response.Content notFound(CharSequence content)

    - #### content

          public static Response.Content content(int code,
                                 byte[] content)

    - #### content

          public static Response.Content content(int code,
                                 InputStream content)

    - #### content

          public static Response.Content content(int code,
                                 Readable content)

    - #### content

          public static Response.Content content(int code,
                                 CharSequence content)

    - #### content

          public static Response.Content content(int code,
                                 Streamable content)

    - #### error

          public static Response.Error error(Throwable t)

    - #### error

          public static Response.Error error(String msg)

Copyright © 2018 eXo Platform SAS. All rights reserved.