Class JsonpRepresentation


  • 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 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: Representation
        Returns 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 the Representation.getAvailableSize() method.

        Note that when used with HTTP connectors, this property maps to the "Content-Length" header.
        Overrides:
        getSize in class Representation
        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.IOException
        Description copied from class: Representation
        Writes 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 given Writer after writing to it as this will be handled by the Restlet connectors automatically.
        Specified by:
        write in class Representation
        Parameters:
        writer - The characters writer.
        Throws:
        java.io.IOException