public abstract class JsonRestHandler extends RestHandler<com.google.gson.JsonElement>
This class can be used to define REST endpoints from RuntimePlatforms. The endpoint can be registered
using the following code:
XatkitServer xatkitServer = [...]
String restEndpointURI = "/myEndpoint";
xatkitServer.registerRestEndpoint(HttpMethod.GET, restEndpointURI, RestHandlerFactory.createJsonRestHandler(
(headers, params, content) -> {
// Handle the request
// return an Object that will be embedded in the HTTP response
}
XatkitServer| Modifier and Type | Class and Description |
|---|---|
static class |
JsonRestHandler.JsonHelper
A static class containing utility methods to manipulate Json contents.
|
| Constructor and Description |
|---|
JsonRestHandler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptContentType(String contentType)
Returns
true if the provided contentType represents a Json content, false otherwise. |
abstract com.google.gson.JsonElement |
handleParsedContent(List<org.apache.http.Header> headers,
List<org.apache.http.NameValuePair> params,
com.google.gson.JsonElement content)
Handles the received
headers, params, and JsonElement parsed from the request payload. |
protected com.google.gson.JsonElement |
parseContent(Object content)
Parses the provided raw HTTP request content into a
JsonElement. |
getAccessControlAllowHeaders, getHeaderValue, handleContentpublic final boolean acceptContentType(String contentType)
true if the provided contentType represents a Json content, false otherwise.acceptContentType in class RestHandler<com.google.gson.JsonElement>contentType - the content type to checktrue if the provided contentType represents a Json content, false otherwiseprotected final com.google.gson.JsonElement parseContent(Object content)
JsonElement.
This method is internally used to fill the handleParsedContent(List, List, JsonElement) parameter
with the JsonElement constructed from the raw request content.
parseContent in class RestHandler<com.google.gson.JsonElement>content - the raw HTTP request content to parseJsonElement representing the raw request contentXatkitException - if the provided content is cannot be parsed by the JsonParser.handleParsedContent(List, List, JsonElement)public abstract com.google.gson.JsonElement handleParsedContent(@Nonnull List<org.apache.http.Header> headers, @Nonnull List<org.apache.http.NameValuePair> params, @Nullable com.google.gson.JsonElement content) throws RestHandlerException
headers, params, and JsonElement parsed from the request payload.handleParsedContent in class RestHandler<com.google.gson.JsonElement>headers - the HTTP headers of the received requestparams - the request parameterscontent - the JsonElement representing the content of the HTTP requestJsonElement containing the endpoint response, or nullRestHandlerException - if an error occurred when handling the requestRestHandler.parseContent(Object),
HttpEntityHelper.createHttpEntity(Object)Copyright © 2020 SOM Research Lab. All rights reserved.