Restlet Framework 2.2.2
OSGi Environments

org.restlet.ext.xstream
Class XstreamRepresentation<T>

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.CharacterRepresentation
                  extended by org.restlet.representation.WriterRepresentation
                      extended by org.restlet.ext.xstream.XstreamRepresentation<T>
Type Parameters:
T - The type to wrap.

public class XstreamRepresentation<T>
extends WriterRepresentation

Representation based on the XStream library. It can serialize and deserialize automatically in XML. It also supports a bridge to JSON leveraging the Jettison library.

SECURITY WARNING: XStream applies various techniques under the hood to ensure it is able to handle all types of objects. This includes using undocumented Java features and reflection. The XML generated by XStream includes all information required to build objects of almost any type. This introduces a potential security problem.
The XML provided to XStream for conversion to a Java object can be manipulated to inject objects into the unmarshalled object graph, which were not present at marshalling time. An attacker could exploit this to execute arbitrary code or shell commands in the context of the server running the XStream process.
You can configure the Xstream object used by this representation (cf #createXstream() or getXstream()) and apply security permissions. You can find more documentation about the security fix and how to configure the XStream object from here: XStream security enhancements.

Author:
Jerome Louvel
See Also:
XStream project

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
XstreamRepresentation(MediaType mediaType, T object)
          Constructor.
XstreamRepresentation(Representation representation, Class<T> targetClass)
          Constructor.
XstreamRepresentation(T object)
          Constructor.
 
Method Summary
protected  XStream createXstream(MediaType mediaType)
          Creates an XStream object based on a media type.
 Class<? extends HierarchicalStreamDriver> getJsonDriverClass()
          Returns the XStream JSON driver class.
 T getObject()
          Returns the wrapped object, deserializing the representation with XStream if necessary.
 Class<? extends HierarchicalStreamDriver> getXmlDriverClass()
          Returns the XStream XML driver class.
 XStream getXstream()
          Returns the modifiable XStream object.
 void setJsonDriverClass(Class<? extends HierarchicalStreamDriver> jsonDriverClass)
          Sets the XStream JSON driver class.
 void setXmlDriverClass(Class<? extends HierarchicalStreamDriver> xmlDriverClass)
          Sets the XStream XML driver class.
 void setXstream(XStream xstream)
          Sets the XStream object.
 void write(Writer writer)
           
 
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
 
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
 
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XstreamRepresentation

public XstreamRepresentation(MediaType mediaType,
                             T object)
Constructor.

Parameters:
mediaType - The target media type.
object - The object to format.

XstreamRepresentation

public XstreamRepresentation(Representation representation,
                             Class<T> targetClass)
Constructor.

Parameters:
representation - The representation to parse.
targetClass - The target class of the object to serialize.

XstreamRepresentation

public XstreamRepresentation(T object)
Constructor. Uses the MediaType.APPLICATION_XML media type by default.

Parameters:
object - The object to format.
Method Detail

createXstream

protected XStream createXstream(MediaType mediaType)
                         throws IOException
Creates an XStream object based on a media type. By default, it creates a HierarchicalStreamDriver or a DomDriver.

Parameters:
mediaType - The serialization media type.
Returns:
The XStream object.
Throws:
IOException

getJsonDriverClass

public Class<? extends HierarchicalStreamDriver> getJsonDriverClass()
Returns the XStream JSON driver class.

Returns:
TXStream JSON driver class.

getObject

public T getObject()
            throws IOException
Returns the wrapped object, deserializing the representation with XStream if necessary.

Returns:
The wrapped object.
Throws:
IOException

getXmlDriverClass

public Class<? extends HierarchicalStreamDriver> getXmlDriverClass()
Returns the XStream XML driver class.

Returns:
The XStream XML driver class.

getXstream

public XStream getXstream()
                   throws IOException
Returns the modifiable XStream object. Useful to customize mappings.

Returns:
The modifiable XStream object.
Throws:
IOException

setJsonDriverClass

public void setJsonDriverClass(Class<? extends HierarchicalStreamDriver> jsonDriverClass)
Sets the XStream JSON driver class.

Parameters:
jsonDriverClass - The XStream JSON driver class.

setXmlDriverClass

public void setXmlDriverClass(Class<? extends HierarchicalStreamDriver> xmlDriverClass)
Sets the XStream XML driver class.

Parameters:
xmlDriverClass - The XStream XML driver class.

setXstream

public void setXstream(XStream xstream)
Sets the XStream object.

Parameters:
xstream - The XStream object.

write

public void write(Writer writer)
           throws IOException
Specified by:
write in class Representation
Throws:
IOException

Restlet Framework 2.2.2
OSGi Environments

Copyright © 2005-2014 Restlet.