public abstract class EmptyContentRestHandler extends RestHandler<Object>
This class can be used to define REST endpoints from RuntimePlatform
s. The
endpoint can be registered using the following code:
XatkitServer xatkitServer = [...]
String restEndpointURI = "/myEndpoint";
xatkitServer.registerRestEndpoint(HttpMethod.GET, restEndpointURI, RestHandlerFactory.createEmptyContentRestHandler(
(headers, params, content) -> {
// Handle the request
// return an Object that will be embedded in the HTTP response
}
Constructor and Description |
---|
EmptyContentRestHandler() |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptContentType(String contentType)
Returns
true . |
protected abstract Object |
handleParsedContent(List<org.apache.http.Header> headers,
List<org.apache.http.NameValuePair> params,
Object content)
Handles the request.
|
protected Object |
parseContent(Object content)
Checks that the provided
content object is null and returns it. |
getAccessControlAllowHeaders, getHeaderValue, handleContent
public boolean acceptContentType(String contentType)
true
.
This handler accepts any content type, but will throw an exception if the request's content is not empty.
acceptContentType
in class RestHandler<Object>
contentType
- the content type to checktrue
@Nullable protected Object parseContent(@Nullable Object content)
content
object is null
and returns it.
This method throws an exception if the provided content
object is not null
. The handler does
not support request's content, see other handlers to deal with specific content type (e.g.
JsonRestHandler
).
parseContent
in class RestHandler<Object>
content
- the raw HTTP request content to parsenull
IllegalArgumentException
- if the provided content
is not nullRestHandler.handleParsedContent(List, List, Object)
@Nullable protected abstract Object handleParsedContent(@Nonnull List<org.apache.http.Header> headers, @Nonnull List<org.apache.http.NameValuePair> params, @Nullable Object content) throws RestHandlerException
Note: the content
object is always null
(this handler does not support request's content).
handleParsedContent
in class RestHandler<Object>
headers
- the HTTP headers of the received requestparams
- the request parameterscontent
- the parsed request payload to handleRestHandlerException
- if an error occurred when handling the requestRestHandler.parseContent(Object)
,
HttpEntityHelper.createHttpEntity(Object)
Copyright © 2020 SOM Research Lab. All rights reserved.