Class OHttpResponseWrapper

java.lang.Object
com.orientechnologies.orient.server.network.protocol.http.OHttpResponseWrapper

public class OHttpResponseWrapper extends Object
Wrapper to use the HTTP response in functions and scripts. This class mimics the J2EE HTTPResponse class.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Constructor Details

    • OHttpResponseWrapper

      public OHttpResponseWrapper(OHttpResponse iResponse)
      Parameters:
      iResponse -
  • Method Details

    • getResponse

      public OHttpResponse getResponse()
    • getHeader

      public String getHeader()
      Returns the response's additional headers.
      Returns:
      The additional headers in form of String
    • setHeader

      public OHttpResponseWrapper setHeader(String iHeader)
      Sets the response's additional headers to send back. To specify multiple headers use the line breaks.
      Parameters:
      iHeader - String containing the header
      Returns:
      The object itself for fluent chained calls
    • getCharacterSet

      public String getCharacterSet()
      Returns the response's character set used.
      Returns:
      The character set in form of String
    • setCharacterSet

      public OHttpResponseWrapper setCharacterSet(String iCharacterSet)
      Sets the response's character set.
      Parameters:
      iCharacterSet - String containing the charset to use
      Returns:
      The object itself for fluent chained calls
    • getHttpVersion

      public String getHttpVersion()
    • getAdditionalResponseHeaders

      public String[] getAdditionalResponseHeaders()
    • getOutputStream

      public OutputStream getOutputStream()
    • writeStatus

      public OHttpResponseWrapper writeStatus(int iHttpCode, String iReason) throws IOException
      Sets the response's status as HTTP code and reason.
      Parameters:
      iHttpCode - Response's HTTP code
      iReason - Response's reason
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeHeaders

      public OHttpResponseWrapper writeHeaders(String iContentType) throws IOException
      Sets the response's headers using the keep-alive.
      Parameters:
      iContentType - Response's content type
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeHeaders

      public OHttpResponseWrapper writeHeaders(String iContentType, boolean iKeepAlive) throws IOException
      Sets the response's headers specifying when using the keep-alive or not.
      Parameters:
      iContentType - Response's content type
      iKeepAlive - Use the keep-alive of the connection
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeLine

      public OHttpResponseWrapper writeLine(String iContent) throws IOException
      Writes a line in the response. A line feed will be appended at the end of the content.
      Parameters:
      iContent - Content to send as string
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeContent

      public OHttpResponseWrapper writeContent(String iContent) throws IOException
      Writes content directly to the response.
      Parameters:
      iContent - Content to send as string
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeRecords

      public OHttpResponseWrapper writeRecords(List<OIdentifiable> iRecords) throws IOException
      Writes records as response. The records are serialized in JSON format.
      Parameters:
      iRecords - List of records to serialize
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeRecords

      public OHttpResponseWrapper writeRecords(Object iRecords, String iFetchPlan) throws IOException
      Writes records as response specifying a fetch-plan to serialize nested records. The records are serialized in JSON format.
      Parameters:
      iRecords - List of records to serialize
      iFetchPlan - Fetch plan to specify nested records
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeRecord

      public OHttpResponseWrapper writeRecord(ORecord iRecord) throws IOException
      Writes a record as response. The record is serialized in JSON format.
      Parameters:
      iRecord - Record to serialize
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • writeRecord

      public OHttpResponseWrapper writeRecord(ORecord iRecord, String iFetchPlan) throws IOException
      Writes a record as response. The record is serialized in JSON format.
      Parameters:
      iRecord - Record to serialize
      iFetchPlan - Fetch plan to specify nested records
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • send

      public OHttpResponseWrapper send(int iCode, String iReason, String iContentType, Object iContent) throws IOException
      Sends the complete HTTP response in one call.
      Parameters:
      iCode - HTTP response's Code
      iReason - Response's reason
      iContentType - Response's content type
      iContent - Content to send. Content can be a string for plain text, binary data to return directly binary information, OIdentifiable for a single record and Collection for a collection of records
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • send

      public OHttpResponseWrapper send(int iCode, String iReason, String iContentType, Object iContent, String iHeaders) throws IOException
      Sends the complete HTTP response in one call specifying additional headers. Keep-alive is set.
      Parameters:
      iCode - HTTP response's Code
      iReason - Response's reason
      iContentType - Response's content type
      iContent - Content to send. Content can be a string for plain text, binary data to return directly binary information, OIdentifiable for a single record and Collection for a collection of records
      iHeaders - Response's additional headers
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • sendStream

      public OHttpResponseWrapper sendStream(int iCode, String iReason, String iContentType, InputStream iContent, long iSize) throws IOException
      Sends the complete HTTP response in one call specifying a stream as content.
      Parameters:
      iCode - HTTP response's Code
      iReason - Response's reason
      iContentType - Response's content type
      iContent - java.io.InputStream object
      iSize - Content size in bytes
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • sendStream

      public OHttpResponseWrapper sendStream(int iCode, String iReason, String iContentType, InputStream iContent, long iSize, String iFileName) throws IOException
      Sends the complete HTTP response in one call specifying a stream as content.
      Parameters:
      iCode - HTTP response's Code
      iReason - Response's reason
      iContentType - Response's content type
      iContent - java.io.InputStream object
      iSize - Content size in bytes
      iFileName - Optional file name
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • flush

      public OHttpResponseWrapper flush() throws IOException
      Flushes the content to the TCP/IP socket.
      Returns:
      The object itself for fluent chained calls
      Throws:
      IOException
    • getContentType

      public String getContentType()
    • setContentType

      public void setContentType(String contentType)
    • getContent

      public String getContent()
    • setContent

      public void setContent(String content)
    • getCode

      public int getCode()
    • setCode

      public void setCode(int code)