Package org.restlet
Class Response
- java.lang.Object
-
- org.restlet.Message
-
- org.restlet.Response
-
- Direct Known Subclasses:
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Ask the connector to abort the related network connection, for example immediately closing the socket.voidcommit()Asks the server connector to immediately commit the given response, making it ready to be sent back to the client.voidflushBuffers()Asks the server connector to immediately flush the network buffers.java.lang.BooleangetAccessControlAllowCredentials()When used as part of a response to a preflight CORS request, this indicates whether or not the actual request can be made using credentials.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Credentials" header.java.util.Set<java.lang.String>getAccessControlAllowHeaders()Returns the modifiable set of headers allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header.java.util.Set<Method>getAccessControlAllowMethods()Returns the modifiable set of methods allowed by the actual request on the current resource when used as part of a response to a preflight CORS request
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Methods" header.java.lang.StringgetAccessControlAllowOrigin()When used in the context of CORS support, it returns the URI an origin server allows for the requested resource.java.util.Set<java.lang.String>getAccessControlExposeHeaders()Returns a modifiable whitelist of headers an origin server allows for the requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header.intgetAccessControlMaxAge()Indicates how long the results of a preflight CORS request can be cached in a preflight result cache.
In case of a negative value, the results of a preflight request is not meant to be cached.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Max-Age" header.intgetAge()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.AuthenticationInfogetAuthenticationInfo()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 ResponsegetCurrent()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.ReferencegetLocationRef()Returns the location reference.java.util.List<ChallengeRequest>getProxyChallengeRequests()Returns the list of authentication requests sent by an origin server to a client.RequestgetRequest()Returns the associated requestjava.util.DategetRetryAfter()Indicates how long the service is expected to be unavailable to the requesting client.ServerInfogetServerInfo()Returns the server-specific information.StatusgetStatus()Returns the status.booleanisAutoCommitting()Indicates if the response should be automatically committed.booleanisCommitted()Indicates if the response has already been committed.booleanisConfidential()Indicates if the message was or will be exchanged confidentially, for example via a SSL-secured connection.booleanisFinal()Indicates if the response is final or provisional.booleanisProvisional()Indicates if the response is provisional or final.voidredirectPermanent(java.lang.String targetUri)Permanently redirects the client to a target URI.voidredirectPermanent(Reference targetRef)Permanently redirects the client to a target URI.voidredirectSeeOther(java.lang.String targetUri)Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource.voidredirectSeeOther(Reference targetRef)Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource.voidredirectTemporary(java.lang.String targetUri)Temporarily redirects the client to a target URI.voidredirectTemporary(Reference targetRef)Temporarily redirects the client to a target URI.voidsetAccessControlAllowCredentials(java.lang.Boolean accessControlAllowCredentials)When used as part of a response to a preflight CORS request, indicates whether or not the actual request can be made using credentials.voidsetAccessControlAllowHeaders(java.util.Set<java.lang.String> accessControlAllowHeaders)Sets the set of headers allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header.voidsetAccessControlAllowMethods(java.util.Set<Method> accessControlAllowMethods)Sets the set of methods allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Methods" header.voidsetAccessControlAllowOrigin(java.lang.String accessControlAllowOrigin)When used in the context of CORS support, it sets the URI an origin server allows for the requested resource.voidsetAccessControlExposeHeaders(java.util.Set<java.lang.String> accessControlExposeHeaders)Sets the list of headers an origin server allows for the requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header.voidsetAccessControlMaxAge(int accessControlMaxAge)When used as part of a response to a preflight CORS request, indicates how long (in seconds) the results of a preflight request can be cached in a preflight result cache.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Max-Age" header.
In case of negative value, the header is not set.voidsetAge(int age)Sets the estimated amount of time since a response was generated or revalidated by the origin server.voidsetAllowedMethods(java.util.Set<Method> allowedMethods)Sets the set of methods allowed on the requested resource.voidsetAuthenticationInfo(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.voidsetAutoCommitting(boolean autoCommitting)Indicates if the response should be automatically committed.voidsetChallengeRequests(java.util.List<ChallengeRequest> challengeRequests)Sets the list of authentication requests sent by an origin server to a client.voidsetCommitted(boolean committed)Indicates if the response has already been committed.voidsetCookieSettings(Series<CookieSetting> cookieSettings)Sets the modifiable series of cookie settings provided by the server.static voidsetCurrent(Response response)Sets the response associated with the current thread.voidsetDimensions(java.util.Set<Dimension> dimensions)Sets the set of dimensions on which the response entity may vary.voidsetLocationRef(java.lang.String locationUri)Sets the reference that the client should follow for redirections or resource creations.voidsetLocationRef(Reference locationRef)Sets the reference that the client should follow for redirections or resource creations.voidsetProxyChallengeRequests(java.util.List<ChallengeRequest> proxyChallengeRequests)Sets the modifiable list of authentication requests sent by a proxy to a client.voidsetRequest(Request request)Sets the associated request.voidsetRetryAfter(java.util.Date retryAfter)Indicates how long the service is expected to be unavailable to the requesting client.voidsetServerInfo(ServerInfo serverInfo)Sets the server-specific information.voidsetStatus(Status status)Sets the status.voidsetStatus(Status status, java.lang.String description)Sets the status.voidsetStatus(Status status, java.lang.Throwable throwable)Sets the status.voidsetStatus(Status status, java.lang.Throwable throwable, java.lang.String message)Sets the status.java.lang.StringtoString()Displays a synthesis of the response like an HTTP status line.-
Methods inherited from class org.restlet.Message
bufferEntity, getAttributes, getCacheDirectives, getDate, getEntity, getEntityAsText, getHeaders, getOnError, getOnSent, getRecipientsInfo, getWarnings, isEntityAvailable, release, setAttributes, setCacheDirectives, setDate, setEntity, setEntity, setOnError, setOnSent, setRecipientsInfo, setWarnings
-
-
-
-
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 asResource.getResponse(). This variable is stored internally as a thread local variable and updated each time a call is handled by a Restlet via theRestlet.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.
When the response is in autoCommit mode (see related property), then calling this method isn't necessary. Also, be aware that committing the response doesn't necessarily means that is will be immediately be written on the network as some buffering can occurs. If you want to ensure that response buffers are flushed,
Note that this calls backRequest.commit(Response)on the parent request which holds the link with the underlying network connection.
-
flushBuffers
public void flushBuffers() throws java.io.IOExceptionAsks the server connector to immediately flush the network buffers. Note that this calls backMessage.flushBuffers()on the parent request which holds the link with the underlying network connection.- Overrides:
flushBuffersin classMessage- Throws:
java.io.IOException
-
getAccessControlAllowCredentials
public java.lang.Boolean getAccessControlAllowCredentials()
When used as part of a response to a preflight CORS request, this indicates whether or not the actual request can be made using credentials.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Credentials" header.- Returns:
- True if the requested resource allows credential.
-
getAccessControlAllowHeaders
public java.util.Set<java.lang.String> getAccessControlAllowHeaders()
Returns the modifiable set of headers allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header.- Returns:
- The set of headers allowed by the actual request on the current resource.
-
getAccessControlAllowMethods
public java.util.Set<Method> getAccessControlAllowMethods()
Returns the modifiable set of methods allowed by the actual request on the current resource when used as part of a response to a preflight CORS request
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Methods" header.- Returns:
- The set of methods allowed by the actual request on the current resource.
-
getAccessControlAllowOrigin
public java.lang.String getAccessControlAllowOrigin()
When used in the context of CORS support, it returns the URI an origin server allows for the requested resource. Use "*" as a wildcard character.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Origin" header.- Returns:
- The origin allowed by the requested resource.
-
getAccessControlExposeHeaders
public java.util.Set<java.lang.String> getAccessControlExposeHeaders()
Returns a modifiable whitelist of headers an origin server allows for the requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header.- Returns:
- The set of headers an origin server allows for the requested resource.
-
getAccessControlMaxAge
public int getAccessControlMaxAge()
Indicates how long the results of a preflight CORS request can be cached in a preflight result cache.
In case of a negative value, the results of a preflight request is not meant to be cached.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Max-Age" header.- Returns:
- Indicates how long the results of a preflight request can be cached in a preflight result cache.
-
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 callingcommit()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:MessageIndicates if the message was or will be exchanged confidentially, for example via a SSL-secured connection.- Specified by:
isConfidentialin classMessage- Returns:
- True if the message is confidential.
-
isFinal
public boolean isFinal()
Indicates if the response is final or provisional. It relies on theStatus.isInformational()method.- Returns:
- True if the response is final.
-
isProvisional
public boolean isProvisional()
Indicates if the response is provisional or final. It relies on theStatus.isInformational()method.- Returns:
- True if the response is provisional.
-
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 (seeRequest.getResourceRef()andReference.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 (seeRequest.getResourceRef()andReference.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 (seeRequest.getResourceRef()andReference.getBaseRef().- Parameters:
targetUri- The target URI.
-
setAccessControlAllowCredentials
public void setAccessControlAllowCredentials(java.lang.Boolean accessControlAllowCredentials)
When used as part of a response to a preflight CORS request, indicates whether or not the actual request can be made using credentials.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Credentials" header.- Parameters:
accessControlAllowCredentials- True if the requested resource allows credential.
-
setAccessControlMaxAge
public void setAccessControlMaxAge(int accessControlMaxAge)
When used as part of a response to a preflight CORS request, indicates how long (in seconds) the results of a preflight request can be cached in a preflight result cache.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Max-Age" header.
In case of negative value, the header is not set.- Parameters:
accessControlMaxAge- How long the results of a preflight request can be cached in a preflight result cache.
-
setAccessControlAllowHeaders
public void setAccessControlAllowHeaders(java.util.Set<java.lang.String> accessControlAllowHeaders)
Sets the set of headers allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header.- Parameters:
accessControlAllowHeaders- The set of headers allowed by the actual request on the current resource.
-
setAccessControlAllowMethods
public void setAccessControlAllowMethods(java.util.Set<Method> accessControlAllowMethods)
Sets the set of methods allowed by the actual request on the current resource when used as part of a response to a preflight CORS request.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Methods" header.- Parameters:
accessControlAllowMethods- The set of methods allowed by the actual request on the current resource.
-
setAccessControlAllowOrigin
public void setAccessControlAllowOrigin(java.lang.String accessControlAllowOrigin)
When used in the context of CORS support, it sets the URI an origin server allows for the requested resource. Use "*" as a wildcard character.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Origin" header.- Parameters:
accessControlAllowOrigin- The origin allowed by the requested resource.
-
setAccessControlExposeHeaders
public void setAccessControlExposeHeaders(java.util.Set<java.lang.String> accessControlExposeHeaders)
Sets the list of headers an origin server allows for the requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header.- Parameters:
accessControlExposeHeaders- The set of headers an origin server allows for the requested resource.
-
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 (useCopyOnWriteArraySetfor 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
-
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 (seeRequest.getResourceRef()andReference.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 (useCopyOnWriteArrayListfor 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 description)
Sets the status.- Parameters:
status- The status to set (code and reason phrase).description- The longer status description.
-
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:
toStringin classjava.lang.Object- Returns:
- A synthesis of the response like an HTTP status line.
-
-