Class AbstractHandler<T>
- java.lang.Object
-
- org.apache.calcite.avatica.remote.AbstractHandler<T>
-
- Type Parameters:
T- The format Requests/Responses are serialized as.
- All Implemented Interfaces:
Handler<T>
- Direct Known Subclasses:
JsonHandler,ProtobufHandler
public abstract class AbstractHandler<T> extends java.lang.Object implements Handler<T>
Abstract base class forHandlers to extend to inherit functionality common across serialization strategies.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.calcite.avatica.remote.Handler
Handler.HandlerResponse<T>
-
-
Field Summary
Fields Modifier and Type Field Description private Service.RpcMetadataResponsemetadataprivate static java.lang.StringNULL_EXCEPTION_MESSAGEprotected Serviceservice-
Fields inherited from interface org.apache.calcite.avatica.remote.Handler
HANDLER_SERIALIZATION_METRICS_NAME, HTTP_INTERNAL_SERVER_ERROR, HTTP_OK, HTTP_UNAUTHENTICATED, HTTP_UNAUTHORIZED
-
-
Constructor Summary
Constructors Constructor Description AbstractHandler(Service service)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Handler.HandlerResponse<T>apply(T serializedRequest)Compute a response for the given request, handling errors generated by that computation.Handler.HandlerResponse<T>convertToErrorResponse(java.lang.Exception e)Attempts to convert an Exception to an ErrorResponse.private Handler.HandlerResponse<T>createErrorResponse(java.lang.Exception e, int statusCode)(package private) abstract Service.Requestdecode(T serializedRequest)(package private) abstract Tencode(Service.Response response)Serialize the givenService.Responseper the concreteHandlerimplementation.private java.lang.StringgetCausalChain(java.lang.Throwable e)Constructs a message for the summary of an Exception.voidsetRpcMetadata(Service.RpcMetadataResponse metadata)Sets some general server information to return to the client in all responses.Handler.HandlerResponse<T>unauthenticatedErrorResponse(java.lang.Exception e)Attempts to convert an Exception to an ErrorResponse with an HTTP status code of401.Handler.HandlerResponse<T>unauthorizedErrorResponse(java.lang.Exception e)Attempts to convert an Exception to an ErrorResponse with an HTTP stauts code of403.(package private) Service.ErrorResponseunwrapException(java.lang.Exception e)Unwrap Avatica-specific context about a given exception.
-
-
-
Field Detail
-
NULL_EXCEPTION_MESSAGE
private static final java.lang.String NULL_EXCEPTION_MESSAGE
- See Also:
- Constant Field Values
-
service
protected final Service service
-
metadata
private Service.RpcMetadataResponse metadata
-
-
Constructor Detail
-
AbstractHandler
public AbstractHandler(Service service)
-
-
Method Detail
-
decode
abstract Service.Request decode(T serializedRequest) throws java.io.IOException
- Throws:
java.io.IOException
-
encode
abstract T encode(Service.Response response) throws java.io.IOException
Serialize the givenService.Responseper the concreteHandlerimplementation.- Parameters:
response- TheService.Responseto serialize.- Returns:
- A serialized representation of the
Service.Response. - Throws:
java.io.IOException
-
unwrapException
Service.ErrorResponse unwrapException(java.lang.Exception e)
Unwrap Avatica-specific context about a given exception.- Parameters:
e- A caught exception throw by Avatica implementation.- Returns:
- An
Service.ErrorResponse.
-
apply
public Handler.HandlerResponse<T> apply(T serializedRequest)
Compute a response for the given request, handling errors generated by that computation.- Specified by:
applyin interfaceHandler<T>- Parameters:
serializedRequest- The caller's request.- Returns:
- A
Service.Responsewith additional context about that response.
-
convertToErrorResponse
public Handler.HandlerResponse<T> convertToErrorResponse(java.lang.Exception e)
Attempts to convert an Exception to an ErrorResponse. If there is an issue in serialization, a RuntimeException is thrown instead (wrapping the original exception if necessary).- Parameters:
e- The exception to convert.- Returns:
- A HandlerResponse instance.
-
unauthenticatedErrorResponse
public Handler.HandlerResponse<T> unauthenticatedErrorResponse(java.lang.Exception e)
Attempts to convert an Exception to an ErrorResponse with an HTTP status code of401.
-
unauthorizedErrorResponse
public Handler.HandlerResponse<T> unauthorizedErrorResponse(java.lang.Exception e)
Attempts to convert an Exception to an ErrorResponse with an HTTP stauts code of403.
-
createErrorResponse
private Handler.HandlerResponse<T> createErrorResponse(java.lang.Exception e, int statusCode)
-
getCausalChain
private java.lang.String getCausalChain(java.lang.Throwable e)
Constructs a message for the summary of an Exception.- Parameters:
e- The Exception to summarize.- Returns:
- A summary message for the Exception.
-
setRpcMetadata
public void setRpcMetadata(Service.RpcMetadataResponse metadata)
Description copied from interface:HandlerSets some general server information to return to the client in all responses.- Specified by:
setRpcMetadatain interfaceHandler<T>- Parameters:
metadata- Server-wide information
-
-