Class OHttpResponseWrapper
java.lang.Object
com.orientechnologies.orient.server.network.protocol.http.OHttpResponseWrapper
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionflush()Flushes the content to the TCP/IP socket.String[]Returns the response's character set used.intgetCode()Returns the response's additional headers.Sends the complete HTTP response in one call.Sends the complete HTTP response in one call specifying additional headers.sendStream(int iCode, String iReason, String iContentType, InputStream iContent, long iSize) Sends the complete HTTP response in one call specifying a stream as content.sendStream(int iCode, String iReason, String iContentType, InputStream iContent, long iSize, String iFileName) Sends the complete HTTP response in one call specifying a stream as content.setCharacterSet(String iCharacterSet) Sets the response's character set.voidsetCode(int code) voidsetContent(String content) voidsetContentType(String contentType) Sets the response's additional headers to send back.writeContent(String iContent) Writes content directly to the response.writeHeaders(String iContentType) Sets the response's headers using the keep-alive.writeHeaders(String iContentType, boolean iKeepAlive) Sets the response's headers specifying when using the keep-alive or not.Writes a line in the response.writeRecord(ORecord iRecord) Writes a record as response.writeRecord(ORecord iRecord, String iFetchPlan) Writes a record as response.writeRecords(Object iRecords, String iFetchPlan) Writes records as response specifying a fetch-plan to serialize nested records.writeRecords(List<OIdentifiable> iRecords) Writes records as response.writeStatus(int iHttpCode, String iReason) Sets the response's status as HTTP code and reason.
-
Constructor Details
-
OHttpResponseWrapper
- Parameters:
iResponse-
-
-
Method Details
-
getResponse
-
getHeader
Returns the response's additional headers.- Returns:
- The additional headers in form of String
-
setHeader
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
Returns the response's character set used.- Returns:
- The character set in form of String
-
setCharacterSet
Sets the response's character set.- Parameters:
iCharacterSet- String containing the charset to use- Returns:
- The object itself for fluent chained calls
-
getHttpVersion
-
getAdditionalResponseHeaders
-
getOutputStream
-
writeStatus
Sets the response's status as HTTP code and reason.- Parameters:
iHttpCode- Response's HTTP codeiReason- Response's reason- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
writeHeaders
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 typeiKeepAlive- Use the keep-alive of the connection- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
writeLine
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
Writes content directly to the response.- Parameters:
iContent- Content to send as string- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
writeRecords
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
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 serializeiFetchPlan- Fetch plan to specify nested records- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
writeRecord
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
Writes a record as response. The record is serialized in JSON format.- Parameters:
iRecord- Record to serializeiFetchPlan- 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 CodeiReason- Response's reasoniContentType- Response's content typeiContent- Content to send. Content can be a string for plain text, binary data to return directly binary information, OIdentifiable for a single record and Collectionfor 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 CodeiReason- Response's reasoniContentType- Response's content typeiContent- Content to send. Content can be a string for plain text, binary data to return directly binary information, OIdentifiable for a single record and Collectionfor 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 CodeiReason- Response's reasoniContentType- Response's content typeiContent- java.io.InputStream objectiSize- 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 CodeiReason- Response's reasoniContentType- Response's content typeiContent- java.io.InputStream objectiSize- Content size in bytesiFileName- Optional file name- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
flush
Flushes the content to the TCP/IP socket.- Returns:
- The object itself for fluent chained calls
- Throws:
IOException
-
getContentType
-
setContentType
-
getContent
-
setContent
-
getCode
public int getCode() -
setCode
public void setCode(int code)
-