Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.jersey.api
Class JResponse<E>

    java.lang.Object
      com.sun.jersey.api.JResponse<E>

Type Parameters:
  `E` - The entity type

    public class JResponse<E>

extends java.lang.Object

Defines the contract between a returned instance and the runtime when an application needs to provide metadata to the runtime.

JResponse is a type safe alternative to `Response` that preserves the type information of response entity thus it is not necessary to utilize `GenericEntity`. It provides equivalent functionality to `Response`.

JResponse may be extended in combination with `JResponse.AJResponseBuilder` specialization when building responses.

Several methods have parameters of type URI, `UriBuilder` provides convenient methods to create such values as does URI.create().

Author:
  Paul.Sandoz@Sun.Com
See Also:
  `JResponse.JResponseBuilder`, `Response`

Nested Class Summary
`static class` | `JResponse.AJResponseBuilder<E,B extends JResponse.AJResponseBuilder>` An abstract response builder that may be utilized to extend response building and the construction of `JResponse` instances.
`static class` | `JResponse.JResponseBuilder<E>` A class used to build `JResponse` instances that contain metadata instead of or in addition to an entity.

Constructor Summary
`` | `JResponse(int status, OutBoundHeaders headers, E entity)` Construct given a status, entity and metadata.
`protected` | `JResponse(JResponse.AJResponseBuilder<E,?> b)` Construct from a `JResponse.AJResponseBuilder`.
`` | `JResponse(JResponse<E> that)` Construct a shallow copy.
`` | `JResponse(Response.StatusType statusType, OutBoundHeaders headers, E entity)` Construct given a status type, entity and metadata.

Method Summary
`static
`<E> JResponse.JResponseBuilder<E>`
` | `created(java.net.URI location)` Create a new `JResponse.JResponseBuilder` for a created resource, set the location header using the supplied value.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `fromResponse(JResponse<E> response)` Create a new `JResponse.JResponseBuilder` by performing a shallow copy of an existing `JResponse`.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `fromResponse(Response response)` Create a new `JResponse.JResponseBuilder` by performing a shallow copy of an existing `Response`.
`E` | `getEntity()` Get the response entity.
`OutBoundHeaders` | `getMetadata()` Get metadata associated with the response as a map.
`int` | `getStatus()` Get the status code associated with the response.
`Response.StatusType` | `getStatusType()` Get the status type associated with the response.
`java.lang.reflect.Type` | `getType()` Get the type of the entity.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `noContent()` Create a new `JResponse.JResponseBuilder` for an empty response.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `notAcceptable(java.util.List<Variant> variants)` Create a new `JResponse.JResponseBuilder` for a not acceptable response.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `notModified()` Create a new `JResponse.JResponseBuilder` with a not-modified status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `notModified(EntityTag tag)` Create a new `JResponse.JResponseBuilder` with a not-modified status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `notModified(java.lang.String tag)` Create a new `JResponse.JResponseBuilder` with a not-modified status and a strong entity tag.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `ok()` Create a new `JResponse.JResponseBuilder` with an OK status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `ok(E entity)` Create a new `JResponse.JResponseBuilder` that contains a representation.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `ok(E entity, MediaType type)` Create a new `JResponse.JResponseBuilder` that contains a representation.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `ok(E entity, java.lang.String type)` Create a new `JResponse.JResponseBuilder` that contains a representation.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `ok(E entity, Variant variant)` Create a new `JResponse.JResponseBuilder` that contains a representation.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `seeOther(java.net.URI location)` Create a new `JResponse.JResponseBuilder` for a redirection.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `serverError()` Create a new `JResponse.JResponseBuilder` with an server error status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `status(int status)` Create a new `JResponse.JResponseBuilder` with the supplied status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `status(Response.Status status)` Create a new `JResponse.JResponseBuilder` with the supplied status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `status(Response.StatusType status)` Create a new `JResponse.JResponseBuilder` with the supplied status.
`static
`<E> JResponse.JResponseBuilder<E>`
` | `temporaryRedirect(java.net.URI location)` Create a new `JResponse.JResponseBuilder` for a temporary redirection.
`JResponseAsResponse` | `toResponse()` Convert to a `Response` compatible instance.
`JResponseAsResponse` | `toResponse(java.lang.reflect.Type type)` Convert to a `Response` compatible instance.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JResponse

    public JResponse(Response.StatusType statusType,
                     OutBoundHeaders headers,
                     E entity)

  Construct given a status type, entity and metadata.

  Parameters:
    `statusType` - the status type
    `headers` - the metadata, it is the callers responsibility to copy the metadata if necessary.
    `entity` - the entity

### JResponse

    public JResponse(int status,
                     OutBoundHeaders headers,
                     E entity)

  Construct given a status, entity and metadata.

  Parameters:
    `status` - the status
    `headers` - the metadata, it is the callers responsibility to copy the metadata if necessary.
    `entity` - the entity

### JResponse

    public JResponse(JResponse<E> that)

  Construct a shallow copy. The metadata map will be copied but not the key/value references.

  Parameters:
    `that` - the JResponse to copy from.

### JResponse

    protected JResponse(JResponse.AJResponseBuilder<E,?> b)

  Construct from a `JResponse.AJResponseBuilder`.

  Parameters:
    `b` - the builder.

Method Detail

### toResponse

    public JResponseAsResponse toResponse()

  Convert to a `Response` compatible instance.

  Returns:
    the `Response` compatible instance.

### toResponse

    public JResponseAsResponse toResponse(java.lang.reflect.Type type)

  Convert to a `Response` compatible instance.

  Parameters:
    `type` - the entity type
  Returns:
    the `Response` compatible instance.

### getStatusType

    public Response.StatusType getStatusType()

  Get the status type associated with the response.

  Returns:
    the response status type.

### getStatus

    public int getStatus()

  Get the status code associated with the response.

  Returns:
    the response status code.

### getMetadata

    public OutBoundHeaders getMetadata()

  Get metadata associated with the response as a map. The returned map may be subsequently modified by the JAX-RS runtime. Values will be serialized using a `RuntimeDelegate.HeaderDelegate` if one is available via `RuntimeDelegate.createHeaderDelegate(java.lang.Class)` for the class of the value or using the values `toString` method if a header delegate is not available.

  Returns:
    response metadata as a map

### getEntity

    public E getEntity()

  Get the response entity. The response will be serialized using a MessageBodyWriter for the class and type the entity `E`.

  Returns:
    the response entity.
  See Also:
    `MessageBodyWriter`

### getType

    public java.lang.reflect.Type getType()

  Get the type of the entity.

  Returns:
    the type of the entity.

### fromResponse

    public static <E> JResponse.JResponseBuilder<E> fromResponse(Response response)

  Create a new `JResponse.JResponseBuilder` by performing a shallow copy of an existing `Response`. The returned builder has its own metadata map but entries are simply references to the keys and values contained in the supplied Response metadata map.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `response` - a Response from which the status code, entity and metadata will be copied
  Returns:
    a new JResponseBuilder

### fromResponse

    public static <E> JResponse.JResponseBuilder<E> fromResponse(JResponse<E> response)

  Create a new `JResponse.JResponseBuilder` by performing a shallow copy of an existing `JResponse`. The returned builder has its own metadata map but entries are simply references to the keys and values contained in the supplied Response metadata map.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `response` - a JResponse from which the status code, entity and metadata will be copied
  Returns:
    a new JResponseBuilder

### status

    public static <E> JResponse.JResponseBuilder<E> status(Response.StatusType status)

  Create a new `JResponse.JResponseBuilder` with the supplied status.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `status` - the response status
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if status is null

### status

    public static <E> JResponse.JResponseBuilder<E> status(Response.Status status)

  Create a new `JResponse.JResponseBuilder` with the supplied status.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `status` - the response status
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if status is null

### status

    public static <E> JResponse.JResponseBuilder<E> status(int status)

  Create a new `JResponse.JResponseBuilder` with the supplied status.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `status` - the response status
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if status is less than 100 or greater than 599.

### ok

    public static <E> JResponse.JResponseBuilder<E> ok()

  Create a new `JResponse.JResponseBuilder` with an OK status.

  Type Parameters:
    `E` - The entity type
  Returns:
    a new JResponseBuilder

### ok

    public static <E> JResponse.JResponseBuilder<E> ok(E entity)

  Create a new `JResponse.JResponseBuilder` that contains a representation.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `entity` - the representation entity data
  Returns:
    a new JResponseBuilder

### ok

    public static <E> JResponse.JResponseBuilder<E> ok(E entity,
                                                       MediaType type)

  Create a new `JResponse.JResponseBuilder` that contains a representation.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `entity` - the representation entity data
    `type` - the media type of the entity
  Returns:
    a new JResponseBuilder

### ok

    public static <E> JResponse.JResponseBuilder<E> ok(E entity,
                                                       java.lang.String type)

  Create a new `JResponse.JResponseBuilder` that contains a representation.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `entity` - the representation entity data
    `type` - the media type of the entity
  Returns:
    a new JResponseBuilder

### ok

    public static <E> JResponse.JResponseBuilder<E> ok(E entity,
                                                       Variant variant)

  Create a new `JResponse.JResponseBuilder` that contains a representation.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `entity` - the representation entity data
    `variant` - representation metadata
  Returns:
    a new JResponseBuilder

### serverError

    public static <E> JResponse.JResponseBuilder<E> serverError()

  Create a new `JResponse.JResponseBuilder` with an server error status.

  Type Parameters:
    `E` - The entity type
  Returns:
    a new JResponseBuilder

### created

    public static <E> JResponse.JResponseBuilder<E> created(java.net.URI location)

  Create a new `JResponse.JResponseBuilder` for a created resource, set the location header using the supplied value.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `location` - the URI of the new resource. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the request URI (see `UriInfo#getRequestUri`).
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if location is null

### noContent

    public static <E> JResponse.JResponseBuilder<E> noContent()

  Create a new `JResponse.JResponseBuilder` for an empty response.

  Type Parameters:
    `E` - The entity type
  Returns:
    a new JResponseBuilder

### notModified

    public static <E> JResponse.JResponseBuilder<E> notModified()

  Create a new `JResponse.JResponseBuilder` with a not-modified status.

  Type Parameters:
    `E` - The entity type
  Returns:
    a new JResponseBuilder

### notModified

    public static <E> JResponse.JResponseBuilder<E> notModified(EntityTag tag)

  Create a new `JResponse.JResponseBuilder` with a not-modified status.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `tag` - a tag for the unmodified entity
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if tag is null

### notModified

    public static <E> JResponse.JResponseBuilder<E> notModified(java.lang.String tag)

  Create a new `JResponse.JResponseBuilder` with a not-modified status and a strong entity tag. This is a shortcut for `notModified(new EntityTag(value))`.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `tag` - the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header.
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if tag is null

### seeOther

    public static <E> JResponse.JResponseBuilder<E> seeOther(java.net.URI location)

  Create a new `JResponse.JResponseBuilder` for a redirection. Used in the redirect-after-POST (aka POST/redirect/GET) pattern.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `location` - the redirection URI. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see `UriInfo#getBaseUri`).
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if location is null

### temporaryRedirect

    public static <E> JResponse.JResponseBuilder<E> temporaryRedirect(java.net.URI location)

  Create a new `JResponse.JResponseBuilder` for a temporary redirection.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `location` - the redirection URI. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see `UriInfo#getBaseUri`).
  Returns:
    a new JResponseBuilder
  Throws:
    `java.lang.IllegalArgumentException` - if location is null

### notAcceptable

    public static <E> JResponse.JResponseBuilder<E> notAcceptable(java.util.List<Variant> variants)

  Create a new `JResponse.JResponseBuilder` for a not acceptable response.

  Type Parameters:
    `E` - The entity type
  Parameters:
    `variants` - list of variants that were available, a null value is equivalent to an empty list.
  Returns:
    a new JResponseBuilder

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 Oracle Corporation. All Rights Reserved.