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 RedirectHandler<T>
RequestBody
s and ResponseBody
s.
Subclasses must be thread-safe.
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
log |
leaderRetriever, localAddressFuture, logger, timeout
Modifier | Constructor and Description |
---|---|
protected |
AbstractRestHandler(CompletableFuture<String> localRestAddress,
GatewayRetriever<? extends T> leaderRetriever,
Time timeout,
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 void |
respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Routed routed,
T gateway) |
channelRead0
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
handlerAdded, handlerRemoved, isSharable
protected AbstractRestHandler(CompletableFuture<String> localRestAddress, GatewayRetriever<? extends T> leaderRetriever, Time timeout, MessageHeaders<R,P,M> messageHeaders)
public MessageHeaders<R,P,M> getMessageHeaders()
protected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Routed routed, T gateway) throws Exception
respondAsLeader
in class RedirectHandler<T extends RestfulGateway>
Exception
protected 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 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–2018 The Apache Software Foundation. All rights reserved.