public class JsonHttpUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static IpcAnyWriter |
IPC_ANY_WRITER
for Any -> BON/JSON serialization.
|
static IpcRecordReader |
IPC_RECORD_READER
for BON/JSON -> record parsing.
|
static IpcRecordWriter |
IPC_RECORD_WRITER
for record -> BON/JSON serialization.
|
Constructor and Description |
---|
JsonHttpUtils() |
Modifier and Type | Method and Description |
---|---|
Record |
convertGetRequest(HttpExchange he)
Converts a HTTP GET request into a query record by setting all parameters as attributes and literal values.
|
Record |
convertPostRequest(HttpExchange he)
Converts a HTTP POST request into a query record by converting the posted JSON stream into a record.
|
Record |
convertRequest(HttpExchange exchange)
Create an input record from a request by either parse JSON from the request body, or by converting URI parameters.
|
int |
getErrorStatus(java.lang.Throwable ex)
Return a status code for an exception.
|
ObjectMapper |
getObjectMapper()
Creates an
ObjectMapper instance with disabled JsonGenerator.Feature#AUTO_CLOSE_TARGET and default
SMILA date/time format. |
boolean |
hasRequestContent(HttpExchange exchange)
check if the request contains content in the body.
|
boolean |
prepareResponseHeader(HttpExchange exchange,
int statusCode,
boolean hasResponseBody)
set basic HTTP response headers.
|
void |
writeErrorDetails(HttpExchange exchange,
java.lang.Throwable error)
write exception in JSON format to response stream.
|
void |
writeResultObject(java.io.OutputStream responseStream,
java.lang.Object resultObject)
write result object.
|
public static final IpcRecordWriter IPC_RECORD_WRITER
public static final IpcRecordReader IPC_RECORD_READER
public static final IpcAnyWriter IPC_ANY_WRITER
public Record convertRequest(HttpExchange exchange) throws IpcException
exchange
- the HttpExchange objectIpcException
- if any error occurs during conversionpublic Record convertGetRequest(HttpExchange he) throws IpcException
he
- the HttpExchange objectIpcException
- if any error occurs during conversionpublic Record convertPostRequest(HttpExchange he) throws IpcException
he
- the HttpExchange objectIpcException
- if any error occurs during conversion from JSON to Recordpublic boolean hasRequestContent(HttpExchange exchange)
exchange
- HTTP exchangepublic boolean prepareResponseHeader(HttpExchange exchange, int statusCode, boolean hasResponseBody)
exchange
- HTTP exchangestatusCode
- HTTP response status code.hasResponseBody
- true if the response will have data in body, else false.public void writeResultObject(java.io.OutputStream responseStream, java.lang.Object resultObject) throws java.io.IOException
Record
results. Subclasses that produce
different result types must override this method.responseStream
- response streamresultObject
- result object.java.io.IOException
- error writing resultpublic int getErrorStatus(java.lang.Throwable ex)
ex
- an exceptionpublic void writeErrorDetails(HttpExchange exchange, java.lang.Throwable error) throws java.io.IOException
java.io.IOException
public ObjectMapper getObjectMapper()
ObjectMapper
instance with disabled JsonGenerator.Feature#AUTO_CLOSE_TARGET
and default
SMILA date/time format.ObjectMapper