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>
RequestBody
s and ResponseBody
s.
Subclasses must be thread-safe.
log, MAPPER
leaderRetriever, logger, responseHeaders, timeout
Modifier | Constructor and Description |
---|---|
protected |
AbstractRestHandler(GatewayRetriever<? extends T> leaderRetriever,
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> 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> handlerRequest,
T gateway)
Respond to the given
HandlerRequest . |
closeAsync, closeHandlerAsync, respondAsLeader
channelRead0
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
protected AbstractRestHandler(GatewayRetriever<? extends T> leaderRetriever, 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> handlerRequest, T gateway)
AbstractHandler
HandlerRequest
.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> request, @Nonnull T gateway) throws RestHandlerException
CompletableFuture
containing a the response.
Implementations may decide whether to throw RestHandlerException
s 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–2024 The Apache Software Foundation. All rights reserved.