org.restlet

## Class Response

- java.lang.Object
- - org.restlet.Message
  - - org.restlet.Response

Direct Known Subclasses:
  HttpResponse, WrapperResponse

    public class Response
    extends Message

Generic response sent by server connectors. It is then received by client connectors. Responses are uniform across all types of connectors, protocols and components.

Author:
  Jerome Louvel
See Also:
  `Request`, `Uniform`

### Constructor Summary

Constructors
Constructor and Description
`Response(Request request)` Constructor.

### Method Summary

Methods
`void` `abort()` Ask the connector to abort the related network connection, for example immediately closing the socket.
`void` `commit()` Asks the server connector to immediately commit the given response, making it ready to be sent back to the client.
`int` `getAge()` Returns the estimated amount of time since a response was generated or revalidated by the origin server.
`java.util.Set<Method>` `getAllowedMethods()` Returns the modifiable set of methods allowed on the requested resource.
`AuthenticationInfo` `getAuthenticationInfo()` Returns information sent by an origin server related to an successful authentication attempt.
`java.util.List<ChallengeRequest>` `getChallengeRequests()` Returns the list of authentication requests sent by an origin server to a client.
`Series<CookieSetting>` `getCookieSettings()` Returns the modifiable series of cookie settings provided by the server.
`static Response` `getCurrent()` Returns the response associated to the current thread.
`java.util.Set<Dimension>` `getDimensions()` Returns the modifiable set of selecting dimensions on which the response entity may vary.
`Reference` `getLocationRef()` Returns the location reference.
`java.util.List<ChallengeRequest>` `getProxyChallengeRequests()` Returns the list of authentication requests sent by an origin server to a client.
`Request` `getRequest()` Returns the associated request
`java.util.Date` `getRetryAfter()` Indicates how long the service is expected to be unavailable to the requesting client.
`ServerInfo` `getServerInfo()` Returns the server-specific information.
`Status` `getStatus()` Returns the status.
`boolean` `isAutoCommitting()` Indicates if the response should be automatically committed.
`boolean` `isCommitted()` Indicates if the response has already been committed.
`boolean` `isConfidential()` Indicates if the message was or will be exchanged confidentially, for example via a SSL-secured connection.
`void` `redirectPermanent(Reference targetRef)` Permanently redirects the client to a target URI.
`void` `redirectPermanent(java.lang.String targetUri)` Permanently redirects the client to a target URI.
`void` `redirectSeeOther(Reference targetRef)` Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource.
`void` `redirectSeeOther(java.lang.String targetUri)` Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource.
`void` `redirectTemporary(Reference targetRef)` Temporarily redirects the client to a target URI.
`void` `redirectTemporary(java.lang.String targetUri)` Temporarily redirects the client to a target URI.
`void` `setAge(int age)` Sets the estimated amount of time since a response was generated or revalidated by the origin server.
`void` `setAllowedMethods(java.util.Set<Method> allowedMethods)` Sets the set of methods allowed on the requested resource.
`void` `setAuthenticationInfo(AuthenticationInfo authenticationInfo)` Sets the authentication information sent by an origin server to a client after a successful authentication attempt. Note that when used with HTTP connectors, this property maps to the "Authentication-Info" header.
`void` `setAutoCommitting(boolean autoCommitting)` Indicates if the response should be automatically committed.
`void` `setChallengeRequest(ChallengeRequest request)` Deprecated. Add request to `getChallengeRequests()` method result instead or use `setChallengeRequests(List)`.
`void` `setChallengeRequests(java.util.List<ChallengeRequest> challengeRequests)` Sets the list of authentication requests sent by an origin server to a client.
`void` `setCommitted(boolean committed)` Indicates if the response has already been committed.
`void` `setCookieSettings(Series<CookieSetting> cookieSettings)` Sets the modifiable series of cookie settings provided by the server.
`static void` `setCurrent(Response response)` Sets the response associated with the current thread.
`void` `setDimensions(java.util.Set<Dimension> dimensions)` Sets the set of dimensions on which the response entity may vary.
`void` `setLocationRef(Reference locationRef)` Sets the reference that the client should follow for redirections or resource creations.
`void` `setLocationRef(java.lang.String locationUri)` Sets the reference that the client should follow for redirections or resource creations.
`void` `setProxyChallengeRequests(java.util.List<ChallengeRequest> proxyChallengeRequests)` Sets the modifiable list of authentication requests sent by a proxy to a client.
`void` `setRequest(Request request)` Sets the associated request.
`void` `setRetryAfter(java.util.Date retryAfter)` Indicates how long the service is expected to be unavailable to the requesting client.
`void` `setServerInfo(ServerInfo serverInfo)` Sets the server-specific information.
`void` `setStatus(Status status)` Sets the status.
`void` `setStatus(Status status, java.lang.String message)` Sets the status.
`void` `setStatus(Status status, java.lang.Throwable throwable)` Sets the status.
`void` `setStatus(Status status, java.lang.Throwable throwable, java.lang.String message)` Sets the status.
`java.lang.String` `toString()` Displays a synthesis of the response like an HTTP status line.

### Methods inherited from class org.restlet.Message

`getAttributes, getCacheDirectives, getDate, getEntity, getEntityAsForm, getEntityAsText, getOnSent, getRecipientsInfo, getWarnings, isEntityAvailable, release, setAttributes, setCacheDirectives, setDate, setEntity, setEntity, setOnSent, setRecipientsInfo, setWarnings`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Response

    public Response(Request request)

Constructor.

Parameters:
  `request` - The request associated to this response.

### Method Detail

#### getCurrent

    public static Response getCurrent()

Returns the response associated to the current thread. Warning: this method should only be used under duress. You should by default prefer obtaining the current context using methods such as `Handler.getResponse()`. This variable is stored internally as a thread local variable and updated each time a call is handled by a Restlet via the `Restlet.handle(org.restlet.Request, org.restlet.Response)` method.

Returns:
  The current context.

#### setCurrent

    public static void setCurrent(Response response)

Sets the response associated with the current thread.

Parameters:
  `response` - The thread's response.

#### abort

    public void abort()

Ask the connector to abort the related network connection, for example immediately closing the socket.

#### commit

    public void commit()

Asks the server connector to immediately commit the given response, making it ready to be sent back to the client. Note that all server connectors don't necessarily support this feature.

#### getAge

    public int getAge()

Returns the estimated amount of time since a response was generated or revalidated by the origin server. Origin servers should leave the 0 default value. Only caches are expected to set this property.
Note that when used with HTTP connectors, this property maps to the "Age" header.

Returns:
  The response age.

#### getAllowedMethods

    public java.util.Set<Method> getAllowedMethods()

Returns the modifiable set of methods allowed on the requested resource. This property only has to be updated when a status CLIENT_ERROR_METHOD_NOT_ALLOWED is set. Creates a new instance if no one has been set.
Note that when used with HTTP connectors, this property maps to the "Allow" header.

Returns:
  The set of allowed methods.

#### getAuthenticationInfo

    public AuthenticationInfo getAuthenticationInfo()

Returns information sent by an origin server related to an successful authentication attempt. If none is available, null is returned.
Note that when used with HTTP connectors, this property maps to the "Authentication-Info" header.

Returns:
  The authentication information provided by the server.

#### getChallengeRequests

    public java.util.List<ChallengeRequest> getChallengeRequests()

Returns the list of authentication requests sent by an origin server to a client. If none is available, an empty list is returned.
Note that when used with HTTP connectors, this property maps to the "WWW-Authenticate" header.

Returns:
  The list of authentication requests.

#### getCookieSettings

    public Series<CookieSetting> getCookieSettings()

Returns the modifiable series of cookie settings provided by the server. Creates a new instance if no one has been set.
Note that when used with HTTP connectors, this property maps to the "Set-Cookie" and "Set-Cookie2" headers.

Returns:
  The cookie settings provided by the server.

#### getDimensions

    public java.util.Set<Dimension> getDimensions()

Returns the modifiable set of selecting dimensions on which the response entity may vary. If some server-side content negotiation is done, this set should be properly updated, other it can be left empty. Creates a new instance if no one has been set.
Note that when used with HTTP connectors, this property maps to the "Vary" header.

Returns:
  The set of dimensions on which the response entity may vary.

#### getLocationRef

    public Reference getLocationRef()

Returns the location reference. This is the reference that the client should follow for redirections or resource creations.
Note that when used with HTTP connectors, this property maps to the "Location" header.

Returns:
  The redirection reference.

#### getProxyChallengeRequests

    public java.util.List<ChallengeRequest> getProxyChallengeRequests()

Returns the list of authentication requests sent by an origin server to a client. If none is available, an empty list is returned.
Note that when used with HTTP connectors, this property maps to the "Proxy-Authenticate" header.

Returns:
  The list of authentication requests.

#### getRequest

    public Request getRequest()

Returns the associated request

Returns:
  The associated request

#### getRetryAfter

    public java.util.Date getRetryAfter()

Indicates how long the service is expected to be unavailable to the requesting client. Default value is null.
Note that when used with HTTP connectors, this property maps to the "Retry-After" header.

Returns:
  Date after with a retry attempt could occur.

#### getServerInfo

    public ServerInfo getServerInfo()

Returns the server-specific information. Creates a new instance if no one has been set.

Returns:
  The server-specific information.

#### getStatus

    public Status getStatus()

Returns the status.

Returns:
  The status.

#### isAutoCommitting

    public boolean isAutoCommitting()

Indicates if the response should be automatically committed. When processing a request on the server-side, setting this property to 'false' let you ask to the server connector to wait before sending the response back to the client when the initial calling thread returns. This will let you do further updates to the response and manually calling `commit()` later on, using another thread.

Returns:
  True if the response should be automatically committed.

#### isCommitted

    public boolean isCommitted()

Indicates if the response has already been committed.

Returns:
  True if the response has already been committed.

#### isConfidential

    public boolean isConfidential()

Description copied from class: `Message`
Indicates if the message was or will be exchanged confidentially, for example via a SSL-secured connection.

Specified by:
  `isConfidential` in class `Message`
Returns:
  True if the message is confidential.

#### redirectPermanent

    public void redirectPermanent(Reference targetRef)

Permanently redirects the client to a target URI. The client is expected to reuse the same method for the new request.

Parameters:
  `targetRef` - The target URI reference.

#### redirectPermanent

    public void redirectPermanent(java.lang.String targetUri)

Permanently redirects the client to a target URI. The client is expected to reuse the same method for the new request.
If you pass a relative target URI, it will be resolved with the current base reference of the request's resource reference (see `Request.getResourceRef()` and `Reference.getBaseRef()`.

Parameters:
  `targetUri` - The target URI.

#### redirectSeeOther

    public void redirectSeeOther(Reference targetRef)

Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource.

Parameters:
  `targetRef` - The target reference.

#### redirectSeeOther

    public void redirectSeeOther(java.lang.String targetUri)

Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource.
If you pass a relative target URI, it will be resolved with the current base reference of the request's resource reference (see `Request.getResourceRef()` and `Reference.getBaseRef()`.

Parameters:
  `targetUri` - The target URI.

#### redirectTemporary

    public void redirectTemporary(Reference targetRef)

Temporarily redirects the client to a target URI. The client is expected to reuse the same method for the new request.

Parameters:
  `targetRef` - The target reference.

#### redirectTemporary

    public void redirectTemporary(java.lang.String targetUri)

Temporarily redirects the client to a target URI. The client is expected to reuse the same method for the new request.
If you pass a relative target URI, it will be resolved with the current base reference of the request's resource reference (see `Request.getResourceRef()` and `Reference.getBaseRef()`.

Parameters:
  `targetUri` - The target URI.

#### setAge

    public void setAge(int age)

Sets the estimated amount of time since a response was generated or revalidated by the origin server. Origin servers should leave the 0 default value. Only caches are expected to set this property.
Note that when used with HTTP connectors, this property maps to the "Age" header.

Parameters:
  `age` - The response age.

#### setAllowedMethods

    public void setAllowedMethods(java.util.Set<Method> allowedMethods)

Sets the set of methods allowed on the requested resource. The set instance set must be thread-safe (use `CopyOnWriteArraySet` for example.
Note that when used with HTTP connectors, this property maps to the "Allow" header.

Parameters:
  `allowedMethods` - The set of methods allowed on the requested resource.

#### setAuthenticationInfo

    public void setAuthenticationInfo(AuthenticationInfo authenticationInfo)

Sets the authentication information sent by an origin server to a client after a successful authentication attempt.
Note that when used with HTTP connectors, this property maps to the "Authentication-Info" header.

Parameters:
  `authenticationInfo` - The data returned by the server in response to successful authentication.

#### setAutoCommitting

    public void setAutoCommitting(boolean autoCommitting)

Indicates if the response should be automatically committed.

Parameters:
  `autoCommitting` - True if the response should be automatically committed

#### setChallengeRequest

    @Deprecated
    public void setChallengeRequest(ChallengeRequest request)

Deprecated. Add request to `getChallengeRequests()` method result instead or use `setChallengeRequests(List)`.
Sets the authentication request sent by an origin server to a client.

Parameters:
  `request` - The authentication request sent by an origin server to a client.

#### setChallengeRequests

    public void setChallengeRequests(java.util.List<ChallengeRequest> challengeRequests)

Sets the list of authentication requests sent by an origin server to a client. Note that when used with HTTP connectors, this property maps to the "WWW-Authenticate" header. This method clears the current list and adds all entries in the parameter list.

Parameters:
  `challengeRequests` - A list of authentication requests sent by an origin server to a client.

#### setCommitted

    public void setCommitted(boolean committed)

Indicates if the response has already been committed.

Parameters:
  `committed` - True if the response has already been committed.

#### setCookieSettings

    public void setCookieSettings(Series<CookieSetting> cookieSettings)

Sets the modifiable series of cookie settings provided by the server. Note that when used with HTTP connectors, this property maps to the "Set-Cookie" and "Set-Cookie2" headers. This method clears the current series and adds all entries in the parameter series.

Parameters:
  `cookieSettings` - A series of cookie settings provided by the server.

#### setDimensions

    public void setDimensions(java.util.Set<Dimension> dimensions)

Sets the set of dimensions on which the response entity may vary. Note that when used with HTTP connectors, this property maps to the "Vary" header. This method clears the current set and adds all entries in the parameter set.

Parameters:
  `dimensions` - The set of dimensions on which the response entity may vary.

#### setLocationRef

    public void setLocationRef(Reference locationRef)

Sets the reference that the client should follow for redirections or resource creations. Note that when used with HTTP connectors, this property maps to the "Location" header.

Parameters:
  `locationRef` - The reference to set.

#### setLocationRef

    public void setLocationRef(java.lang.String locationUri)

Sets the reference that the client should follow for redirections or resource creations. If you pass a relative location URI, it will be resolved with the current base reference of the request's resource reference (see `Request.getResourceRef()` and `Reference.getBaseRef()`.
Note that when used with HTTP connectors, this property maps to the "Location" header.

Parameters:
  `locationUri` - The URI to set.
See Also:
  `setLocationRef(Reference)`

#### setProxyChallengeRequests

    public void setProxyChallengeRequests(java.util.List<ChallengeRequest> proxyChallengeRequests)

Sets the modifiable list of authentication requests sent by a proxy to a client. The list instance set must be thread-safe (use `CopyOnWriteArrayList` for example. Note that when used with HTTP connectors, this property maps to the "Proxy-Authenticate" header. This method clears the current list and adds all entries in the parameter list.

Parameters:
  `proxyChallengeRequests` - A list of authentication requests sent by a proxy to a client.

#### setRequest

    public void setRequest(Request request)

Sets the associated request.

Parameters:
  `request` - The associated request

#### setRetryAfter

    public void setRetryAfter(java.util.Date retryAfter)

Indicates how long the service is expected to be unavailable to the requesting client. Default value is null.
Note that when used with HTTP connectors, this property maps to the "Retry-After" header.

Parameters:
  `retryAfter` - Date after with a retry attempt could occur.

#### setServerInfo

    public void setServerInfo(ServerInfo serverInfo)

Sets the server-specific information.

Parameters:
  `serverInfo` - The server-specific information.

#### setStatus

    public void setStatus(Status status)

Sets the status.

Parameters:
  `status` - The status to set.

#### setStatus

    public void setStatus(Status status,
                 java.lang.String message)

Sets the status.

Parameters:
  `status` - The status to set.
  `message` - The status message.

#### setStatus

    public void setStatus(Status status,
                 java.lang.Throwable throwable)

Sets the status.

Parameters:
  `status` - The status to set.
  `throwable` - The related error or exception.

#### setStatus

    public void setStatus(Status status,
                 java.lang.Throwable throwable,
                 java.lang.String message)

Sets the status.

Parameters:
  `status` - The status to set.
  `throwable` - The related error or exception.
  `message` - The status message.

#### toString

    public java.lang.String toString()

Displays a synthesis of the response like an HTTP status line.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  A synthesis of the response like an HTTP status line.