R - type of incoming requestsP - type of outgoing responses@ChannelHandler.Sharable public abstract class AbstractRestHandler<T extends RestfulGateway,R extends RequestBody,P extends ResponseBody,M extends MessageParameters> extends AbstractHandler<T,R,M>
RequestBodys and ResponseBodys.
Subclasses must be thread-safe.
log, MAPPERleaderRetriever, logger, responseHeaders, timeout| Modifier | Constructor and Description |
|---|---|
protected |
AbstractRestHandler(GatewayRetriever<? extends T> leaderRetriever,
org.apache.flink.api.common.time.Time timeout,
Map<String,String> responseHeaders,
MessageHeaders<R,P,M> messageHeaders) |
| Modifier and Type | Method and Description |
|---|---|
MessageHeaders<R,P,M> |
getMessageHeaders() |
protected abstract CompletableFuture<P> |
handleRequest(HandlerRequest<R,M> request,
T gateway)
This method is called for every incoming request and returns a
CompletableFuture
containing a the response. |
protected CompletableFuture<Void> |
respondToRequest(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest httpRequest,
HandlerRequest<R,M> handlerRequest,
T gateway)
Respond to the given
HandlerRequest. |
closeAsync, closeHandlerAsync, respondAsLeaderchannelRead0acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharableprotected AbstractRestHandler(GatewayRetriever<? extends T> leaderRetriever, org.apache.flink.api.common.time.Time timeout, Map<String,String> responseHeaders, MessageHeaders<R,P,M> messageHeaders)
public MessageHeaders<R,P,M> getMessageHeaders()
protected CompletableFuture<Void> respondToRequest(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest httpRequest, HandlerRequest<R,M> handlerRequest, T gateway)
AbstractHandlerHandlerRequest.respondToRequest in class AbstractHandler<T extends RestfulGateway,R extends RequestBody,M extends MessageParameters>ctx - channel handler context to write the responsehttpRequest - original http requesthandlerRequest - typed handler requestgateway - leader gatewayprotected abstract CompletableFuture<P> handleRequest(@Nonnull HandlerRequest<R,M> request, @Nonnull T gateway) throws RestHandlerException
CompletableFuture
containing a the response.
Implementations may decide whether to throw RestHandlerExceptions or fail the
returned CompletableFuture with a RestHandlerException.
Failing the future with another exception type or throwing unchecked exceptions is
regarded as an implementation error as it does not allow us to provide a meaningful HTTP
status code. In this case a HttpResponseStatus.INTERNAL_SERVER_ERROR will be
returned.
request - request that should be handledgateway - leader gatewayRestHandlerException - if the handling failedCopyright © 2014–2021 The Apache Software Foundation. All rights reserved.