org.glassfish.jersey.message.internal
Class WriterInterceptorExecutor

java.lang.Object
  extended by org.glassfish.jersey.message.internal.WriterInterceptorExecutor
All Implemented Interfaces:
InterceptorContext, WriterInterceptorContext

public final class WriterInterceptorExecutor
extends Object
implements WriterInterceptorContext

Represents writer interceptor chain executor for both client and server side. It constructs wrapped interceptor chain and invokes it. At the end of the chain a message body writer execution interceptor is inserted, which writes entity to the output stream provided by the chain.

Author:
Miroslav Fuksa (miroslav.fuksa at oracle.com), Jakub Podlesak (jakub.podlesak at oracle.com)

Constructor Summary
WriterInterceptorExecutor(Object entity, Class<?> rawType, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,Object> headers, PropertiesDelegate propertiesDelegate, OutputStream entityStream, MessageBodyWorkers workers, Iterable<WriterInterceptor> writerInterceptors)
          Constructs a new executor to write given type to provided entityStream.
 
Method Summary
 Annotation[] getAnnotations()
          Get an array of the annotations formally declared on the artifact that initiated the intercepted entity provider invocation.
 Object getEntity()
          Get object to be written as HTTP entity.
 Type getGenericType()
          Get the type of the object to be produced or written.
 MultivaluedMap<String,Object> getHeaders()
          Get mutable map of HTTP headers.
 MediaType getMediaType()
          Get media type of HTTP entity.
 WriterInterceptor getNextInterceptor()
          Returns next interceptor in the chain.
 OutputStream getOutputStream()
          Get the output stream for the object to be written.
 Object getProperty(String name)
          Returns the property with the given name registered in the current request/response exchange context, or null if there is no property by that name.
 Collection<String> getPropertyNames()
          Returns an immutable collection containing the property names available within the context of the current request/response exchange context.
 Class getType()
          Get Java type supported by corresponding message body provider.
 void proceed()
          Starts the interceptor chain execution.
 void removeProperty(String name)
          Removes a property with the given name from the current request/response exchange context.
 void setAnnotations(Annotation[] annotations)
          Update annotations on the formal declaration of the artifact that initiated the intercepted entity provider invocation.
 void setEntity(Object entity)
          Update object to be written as HTTP entity.
 void setGenericType(Type genericType)
          Update type of the object to be produced or written.
 void setMediaType(MediaType mediaType)
          Update media type of HTTP entity.
 void setOutputStream(OutputStream os)
          Set a new output stream for the object to be written.
 void setProperty(String name, Object object)
          Binds an object to a given property name in the current request/response exchange context.
 void setType(Class type)
          Update Java type before calling message body provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ws.rs.ext.InterceptorContext
getAnnotations, getGenericType, getMediaType, getProperty, getPropertyNames, getType, removeProperty, setAnnotations, setGenericType, setMediaType, setProperty, setType
 

Constructor Detail

WriterInterceptorExecutor

public WriterInterceptorExecutor(Object entity,
                                 Class<?> rawType,
                                 Type type,
                                 Annotation[] annotations,
                                 MediaType mediaType,
                                 MultivaluedMap<String,Object> headers,
                                 PropertiesDelegate propertiesDelegate,
                                 OutputStream entityStream,
                                 MessageBodyWorkers workers,
                                 Iterable<WriterInterceptor> writerInterceptors)
Constructs a new executor to write given type to provided entityStream.

Parameters:
entity - entity object to be processed.
rawType - raw Java entity type.
type - generic Java entity type.
annotations - array of annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
mediaType - media type of the HTTP entity.
headers - mutable HTTP headers associated with HTTP entity.
propertiesDelegate - request-scoped properties delegate.
entityStream - InputStream from which an entity will be read. The stream is not closed after reading the entity.
workers - Message body workers.
writerInterceptors - Writer interceptor that are to be used to intercept the writing of an entity. The interceptors will be executed in the same order as given in this parameter.
Method Detail

getNextInterceptor

public WriterInterceptor getNextInterceptor()
Returns next interceptor in the chain. Stateful method.

Returns:
Next interceptor.

proceed

public void proceed()
             throws IOException
Starts the interceptor chain execution.

Specified by:
proceed in interface WriterInterceptorContext
Throws:
IOException - if an IO error arises or is thrown by the wrapped MessageBodyWriter.writeTo method.

getEntity

public Object getEntity()
Description copied from interface: WriterInterceptorContext
Get object to be written as HTTP entity.

Specified by:
getEntity in interface WriterInterceptorContext
Returns:
object to be written as HTTP entity.

setEntity

public void setEntity(Object entity)
Description copied from interface: WriterInterceptorContext
Update object to be written as HTTP entity.

Specified by:
setEntity in interface WriterInterceptorContext
Parameters:
entity - new object to be written.

getOutputStream

public OutputStream getOutputStream()
Description copied from interface: WriterInterceptorContext
Get the output stream for the object to be written. The JAX-RS runtime is responsible for closing the output stream.

Specified by:
getOutputStream in interface WriterInterceptorContext
Returns:
output stream for the object to be written.

setOutputStream

public void setOutputStream(OutputStream os)
Description copied from interface: WriterInterceptorContext
Set a new output stream for the object to be written. For example, by wrapping it with another output stream. The JAX-RS runtime is responsible for closing the output stream that is set.

Specified by:
setOutputStream in interface WriterInterceptorContext
Parameters:
os - new output stream for the object to be written.

getHeaders

public MultivaluedMap<String,Object> getHeaders()
Description copied from interface: WriterInterceptorContext
Get mutable map of HTTP headers.

Specified by:
getHeaders in interface WriterInterceptorContext
Returns:
map of HTTP headers.

getProperty

public Object getProperty(String name)
Description copied from interface: InterceptorContext
Returns the property with the given name registered in the current request/response exchange context, or null if there is no property by that name.

A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

A list of supported properties can be retrieved using InterceptorContext.getPropertyNames(). Custom property names should follow the same convention as package names.

In a Servlet container, on the server side, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Specified by:
getProperty in interface InterceptorContext
Parameters:
name - a String specifying the name of the property.
Returns:
an Object containing the value of the property, or null if no property exists matching the given name.
See Also:
InterceptorContext.getPropertyNames()

getPropertyNames

public Collection<String> getPropertyNames()
Description copied from interface: InterceptorContext
Returns an immutable collection containing the property names available within the context of the current request/response exchange context.

Use the InterceptorContext.getProperty(java.lang.String) method with a property name to get the value of a property.

In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest.

Specified by:
getPropertyNames in interface InterceptorContext
Returns:
an immutable collection of property names.
See Also:
InterceptorContext.getProperty(java.lang.String)

setProperty

public void setProperty(String name,
                        Object object)
Description copied from interface: InterceptorContext
Binds an object to a given property name in the current request/response exchange context. If the name specified is already used for a property, this method will replace the value of the property with the new value.

A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

A list of supported properties can be retrieved using InterceptorContext.getPropertyNames(). Custom property names should follow the same convention as package names.

If a null value is passed, the effect is the same as calling the InterceptorContext.removeProperty(String) method.

In a Servlet container, on the server side, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Specified by:
setProperty in interface InterceptorContext
Parameters:
name - a String specifying the name of the property.
object - an Object representing the property to be bound.

removeProperty

public void removeProperty(String name)
Description copied from interface: InterceptorContext
Removes a property with the given name from the current request/response exchange context. After removal, subsequent calls to InterceptorContext.getProperty(java.lang.String) to retrieve the property value will return null.

In a Servlet container, on the server side, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Specified by:
removeProperty in interface InterceptorContext
Parameters:
name - a String specifying the name of the property to be removed.

getAnnotations

public Annotation[] getAnnotations()
Description copied from interface: InterceptorContext
Get an array of the annotations formally declared on the artifact that initiated the intercepted entity provider invocation. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations(); if the server-side response entity instance is to be converted into an output stream, this will be the annotations on the matched resource method returned by Method.getAnnotations(). This method may return an empty array in case the interceptor is not invoked in a context of any particular resource method (e.g. as part of the client API), but will never return null.

Specified by:
getAnnotations in interface InterceptorContext
Returns:
annotations declared on the artifact that initiated the intercepted entity provider invocation.

setAnnotations

public void setAnnotations(Annotation[] annotations)
Description copied from interface: InterceptorContext
Update annotations on the formal declaration of the artifact that initiated the intercepted entity provider invocation. Calling this method has no effect in the client API.

Specified by:
setAnnotations in interface InterceptorContext
Parameters:
annotations - updated annotations declarataion of the artifact that initiated the intercepted entity provider invocation. Must not be null.

getType

public Class getType()
Description copied from interface: InterceptorContext
Get Java type supported by corresponding message body provider.

Specified by:
getType in interface InterceptorContext
Returns:
java type supported by provider

setType

public void setType(Class type)
Description copied from interface: InterceptorContext
Update Java type before calling message body provider.

Specified by:
setType in interface InterceptorContext
Parameters:
type - java type for provider

getGenericType

public Type getGenericType()
Description copied from interface: InterceptorContext
Get the type of the object to be produced or written.

Specified by:
getGenericType in interface InterceptorContext
Returns:
type of object produced or written

setGenericType

public void setGenericType(Type genericType)
Description copied from interface: InterceptorContext
Update type of the object to be produced or written.

Specified by:
setGenericType in interface InterceptorContext
Parameters:
genericType - new type for object

getMediaType

public MediaType getMediaType()
Description copied from interface: InterceptorContext
Get media type of HTTP entity.

Specified by:
getMediaType in interface InterceptorContext
Returns:
media type of HTTP entity

setMediaType

public void setMediaType(MediaType mediaType)
Description copied from interface: InterceptorContext
Update media type of HTTP entity.

Specified by:
setMediaType in interface InterceptorContext
Parameters:
mediaType - new type for HTTP entity


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.