Class ClientResponse
- All Implemented Interfaces:
ClientResponseContext,InjectionManagerSupplier
- Author:
- Marek Potociar
-
Field Summary
Fields inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
runtimeDelegateDecorator -
Constructor Summary
ConstructorsConstructorDescriptionClientResponse(Response.StatusType status, ClientRequest requestContext) Create a new Jersey client response context.ClientResponse(Response.StatusType status, ClientRequest requestContext, URI resolvedRequestUri) Create a new Jersey client response context.ClientResponse(ClientRequest requestContext, Response response) Create new Jersey client response context initialized from a JAX-RSresponse. -
Method Summary
Modifier and TypeMethodDescriptionGet the message entity Java instance.Get injection manager.getLinks()Get the links attached to the message as header.protected Iterable<ReaderInterceptor>Get reader interceptors bound to this context.Get the associated client request context paired with this response context.Get the absolute URI of the ultimate request made to receive this response.int<T> TreadEntity(GenericType<T> entityType) Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<T> TreadEntity(GenericType<T> entityType, Annotation[] annotations) Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<T> TreadEntity(Class<T> entityType) Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<T> TreadEntity(Class<T> entityType, Annotation[] annotations) Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.voidsetResolvedRequestUri(URI uri) Set the absolute URI of the ultimate request that was made to receive this response.voidsetStatus(int code) voidsetStatusInfo(Response.StatusType status) toString()Methods inherited from class org.glassfish.jersey.message.internal.InboundMessageContext
bufferEntity, close, getConfiguration, getEntityStream, getHeaders, getHeaderString, getHeaderValueExceptionContext, getIfMatch, getIfNoneMatch, getMediaType, getQualifiedAcceptableLanguages, getQualifiedAcceptableMediaTypes, getQualifiedAcceptCharset, getQualifiedAcceptEncoding, getWorkers, hasEntity, header, headers, headers, headers, headers, readEntity, readEntity, readEntity, readEntity, remove, setEntityStream, setWorkersMethods inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
containsHeaderString, containsHeaderString, exception, getAllowedMethods, getDate, getEntityTag, getLanguage, getLastModified, getLength, getLengthLong, getLink, getLinkBuilder, getLocation, getRequestCookies, getResponseCookies, hasLink, singleHeader, singleHeaderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jakarta.ws.rs.client.ClientResponseContext
getAllowedMethods, getDate, getEntityStream, getEntityTag, getHeaders, getHeaderString, getLanguage, getLastModified, getLength, getLink, getLinkBuilder, getLocation, getMediaType, hasEntity, hasLink, setEntityStream
-
Constructor Details
-
ClientResponse
Create new Jersey client response context initialized from a JAX-RSresponse.- Parameters:
requestContext- associated request context.response- JAX-RS response to be used to initialize the response context.
-
ClientResponse
Create a new Jersey client response context.- Parameters:
status- response status.requestContext- associated client request context.
-
ClientResponse
public ClientResponse(Response.StatusType status, ClientRequest requestContext, URI resolvedRequestUri) Create a new Jersey client response context.- Parameters:
status- response status.requestContext- associated client request context.resolvedRequestUri- resolved request URI (seegetResolvedRequestUri()).
-
-
Method Details
-
getStatus
public int getStatus()- Specified by:
getStatusin interfaceClientResponseContext
-
setStatus
public void setStatus(int code) - Specified by:
setStatusin interfaceClientResponseContext
-
setStatusInfo
- Specified by:
setStatusInfoin interfaceClientResponseContext
-
getStatusInfo
- Specified by:
getStatusInfoin interfaceClientResponseContext
-
getResolvedRequestUri
Get the absolute URI of the ultimate request made to receive this response.The returned URI points to the ultimate location of the requested resource that provided the data represented by this response instance. Because Jersey client connectors may be configured to
automatically follow redirect responses, the value of the URI returned by this method may be different from the value of theoriginal request URIthat can be retrieved usingresponse.getRequestContext().getUri()chain of method calls.- Returns:
- absolute URI of the ultimate request made to receive this response.
- Since:
- 2.6
- See Also:
-
setResolvedRequestUri
Set the absolute URI of the ultimate request that was made to receive this response.If the original request URI has been modified (e.g. due to redirections), the absolute URI of the ultimate request being made to receive the response should be set by the caller on the response instance using this method.
- Parameters:
uri- absolute URI of the ultimate request made to receive this response. Must not benull.- Throws:
NullPointerException- in case the passeduriparameter is null.IllegalArgumentException- in case the passeduriparameter does not represent an absolute URI.- Since:
- 2.6
- See Also:
-
getRequestContext
Get the associated client request context paired with this response context.- Returns:
- associated client request context.
-
getCookies
- Specified by:
getCookiesin interfaceClientResponseContext
-
getLinks
Description copied from class:InboundMessageContextGet the links attached to the message as header.- Specified by:
getLinksin interfaceClientResponseContext- Overrides:
getLinksin classInboundMessageContext- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
toString
-
getEntity
Get the message entity Java instance. Returnsnullif the message does not contain an entity body.If the entity is represented by an un-consumed
input streamthe method will return the input stream.- Returns:
- the message entity or
nullif message does not contain an entity body (i.e. whenInboundMessageContext.hasEntity()returnsfalse). - Throws:
IllegalStateException- if the entity was previously fully consumed as aninput stream, or if the response has beenclosed.- Since:
- 2.5
- See Also:
-
readEntity
Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Type Parameters:
T- entity instance Java type.- Parameters:
entityType- the type of entity.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - Throws:
ProcessingException- if the content of the message cannot be mapped to an entity of the requested type.IllegalStateException- if the entity is not backed by an input stream, the response has beenclosedalready, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.- Since:
- 2.5
- See Also:
-
readEntity
public <T> T readEntity(GenericType<T> entityType) throws ProcessingException, IllegalStateException Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Type Parameters:
T- entity instance Java type.- Parameters:
entityType- the type of entity; may be generic.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - Throws:
ProcessingException- if the content of the message cannot be mapped to an entity of the requested type.IllegalStateException- if the entity is not backed by an input stream, the response has beenclosedalready, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.- Since:
- 2.5
- See Also:
-
readEntity
public <T> T readEntity(Class<T> entityType, Annotation[] annotations) throws ProcessingException, IllegalStateException Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Type Parameters:
T- entity instance Java type.- Parameters:
entityType- the type of entity.annotations- annotations that will be passed to theMessageBodyReader.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - Throws:
ProcessingException- if the content of the message cannot be mapped to an entity of the requested type.IllegalStateException- if the entity is not backed by an input stream, the response has beenclosedalready, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.- Since:
- 2.5
- See Also:
-
readEntity
public <T> T readEntity(GenericType<T> entityType, Annotation[] annotations) throws ProcessingException, IllegalStateException Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Type Parameters:
T- entity instance Java type.- Parameters:
entityType- the type of entity; may be generic.annotations- annotations that will be passed to theMessageBodyReader.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - Throws:
ProcessingException- if the content of the message cannot be mapped to an entity of the requested type.IllegalStateException- if the entity is not backed by an input stream, the response has beenclosedalready, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.- Since:
- 2.5
- See Also:
-
getInjectionManager
Description copied from interface:InjectionManagerSupplierGet injection manager.- Specified by:
getInjectionManagerin interfaceInjectionManagerSupplier- Returns:
- injection manager.
-
getReaderInterceptors
Description copied from class:InboundMessageContextGet reader interceptors bound to this context.Interceptors will be used when one of the
readEntitymethods is invoked.- Specified by:
getReaderInterceptorsin classInboundMessageContext- Returns:
- reader interceptors bound to this context.
-