Package io.streamthoughts.azkarra.http
Class ExchangeHelper
- java.lang.Object
-
- io.streamthoughts.azkarra.http.ExchangeHelper
-
public class ExchangeHelper extends Object
Simple class to wrapHttpServerExchange
instance.
-
-
Constructor Summary
Constructors Constructor Description ExchangeHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>
getOptionalQueryParam(io.undertow.server.HttpServerExchange exchange, String name)
Static helper that can be used to get an optional param from query for the specified name.static String
getQueryParam(io.undertow.server.HttpServerExchange exchange, String name)
Static helper that can be used to get an mandatory param from query for the specified name.static com.fasterxml.jackson.databind.JsonNode
readJsonRequest(io.undertow.server.HttpServerExchange exchange)
Static helper that can be used to read JSON object from HTTP-request payload.static <T> T
readJsonRequest(io.undertow.server.HttpServerExchange exchange, Class<T> type)
Static helper that can be used to read JSON object from HTTP-request payload.static void
sendJsonResponse(io.undertow.server.HttpServerExchange exchange, Object response)
Static helper that can be used to write a JSON object to HTTP-response withStatusCodes.OK
.static void
sendJsonResponseWithCode(io.undertow.server.HttpServerExchange exchange, Object response, int statusCode)
Static helper that can be used to write a JSON object to HTTP-response with the specified status code.
-
-
-
Method Detail
-
getOptionalQueryParam
public static Optional<String> getOptionalQueryParam(io.undertow.server.HttpServerExchange exchange, String name)
Static helper that can be used to get an optional param from query for the specified name.- Parameters:
exchange
- theHttpServerExchange
instance.name
- the query param name.- Returns:
- an
Optional
.
-
getQueryParam
public static String getQueryParam(io.undertow.server.HttpServerExchange exchange, String name)
Static helper that can be used to get an mandatory param from query for the specified name.- Parameters:
exchange
- theHttpServerExchange
instance.name
- the query param name.- Returns:
- a param as a string.
- Throws:
InvalidHttpQueryParamException
- if param is missing.
-
readJsonRequest
public static com.fasterxml.jackson.databind.JsonNode readJsonRequest(io.undertow.server.HttpServerExchange exchange) throws SerializationException
Static helper that can be used to read JSON object from HTTP-request payload.- Parameters:
exchange
- theHttpServerExchange
instance.- Returns:
- an
JsonNode
instance. - Throws:
SerializationException
- if an error happens while de-serializing.
-
readJsonRequest
public static <T> T readJsonRequest(io.undertow.server.HttpServerExchange exchange, Class<T> type) throws SerializationException
Static helper that can be used to read JSON object from HTTP-request payload.- Parameters:
exchange
- theHttpServerExchange
instance.type
- the type.- Returns:
- an
JsonNode
instance. - Throws:
SerializationException
- if an error happens while de-serializing.
-
sendJsonResponse
public static void sendJsonResponse(io.undertow.server.HttpServerExchange exchange, Object response)
Static helper that can be used to write a JSON object to HTTP-response withStatusCodes.OK
.- Parameters:
exchange
- theHttpServerExchange
instance.response
- theObject
to serialize.
-
sendJsonResponseWithCode
public static void sendJsonResponseWithCode(io.undertow.server.HttpServerExchange exchange, Object response, int statusCode)
Static helper that can be used to write a JSON object to HTTP-response with the specified status code.- Parameters:
exchange
- theHttpServerExchange
instance.response
- theObject
to serialize.statusCode
- the status code.
-
-