Package org.restlet.ext.json
Class JsonpRepresentation
- java.lang.Object
-
public class JsonpRepresentation extends WriterRepresentation
Wrappers that adds a JSONP header and footer to JSON representations. The goal is to make them accessible to web browser without restriction from single origin policies.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringcallbackThe name of the JavaScript callback method.private StatusstatusThe actual status code.private RepresentationwrappedRepresentationThe wrapped JSON representation.-
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description JsonpRepresentation(java.lang.String callback, Status status, Representation wrappedRepresentation)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetCallback()Returns the name of the JavaScript callback method.longgetSize()Returns the total size in bytes if known, UNKNOWN_SIZE (-1) otherwise.StatusgetStatus()Returns the actual status code.voidwrite(java.io.Writer writer)Writes the representation to a characters 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, 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, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
-
-
-
Field Detail
-
callback
private final java.lang.String callback
The name of the JavaScript callback method.
-
status
private final Status status
The actual status code.
-
wrappedRepresentation
private final Representation wrappedRepresentation
The wrapped JSON representation.
-
-
Constructor Detail
-
JsonpRepresentation
public JsonpRepresentation(java.lang.String callback, Status status, Representation wrappedRepresentation)Constructor.- Parameters:
callback- The name of the JavaScript callback method.status- The actual status code.wrappedRepresentation-
-
-
Method Detail
-
getCallback
public java.lang.String getCallback()
Returns the name of the JavaScript callback method.- Returns:
- The name of the JavaScript callback method.
-
getSize
public long getSize()
Description copied from class:RepresentationReturns the total size in bytes if known, UNKNOWN_SIZE (-1) otherwise. When ranges are used, this might not be the actual size available. For this purpose, you can use theRepresentation.getAvailableSize()method.
Note that when used with HTTP connectors, this property maps to the "Content-Length" header.- Overrides:
getSizein classRepresentation- Returns:
- The size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
- See Also:
Representation.isEmpty()
-
getStatus
public Status getStatus()
Returns the actual status code.- Returns:
- The actual status code.
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionDescription copied from class:RepresentationWrites the representation to a characters writer. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.
Note that the class implementing this method shouldn't flush or close the givenWriterafter writing to it as this will be handled by the Restlet connectors automatically.- Specified by:
writein classRepresentation- Parameters:
writer- The characters writer.- Throws:
java.io.IOException
-
-