T - type of service contextV - type of service configurerpublic interface HttpServiceHandler<T extends HttpServiceContext,V extends HttpServiceConfigurer> extends ProgramLifecycle<T>
@Path annotation to specify the endpoint which that method handles. It can also use
the @GET, @POST, @PUT, @DELETE annotations to
specify the type of HTTP requests that it handles.
Example:
public class MyHttpHandler implements HttpServiceHandler {
@GET
@Path("/ping")
public void process(HttpServiceRequest request, HttpServiceResponder responder) {
responder.sendString("Hello World");
}
@Override
public void configure(HttpServiceConfigurer configurer) { }
@Override
public void initialize(HttpServiceContext context) throws Exception { }
@Override
public void destroy() { }
}
To handle HTTP request with large body, it is better to have the handler method to return a
HttpContentConsumer to avoid running out of memory. Similarly, to return a response with
a large body, it is preferable to return respond with HttpContentProducer.
By default, all handler methods are executed within an implicit transaction, that is, you can
access datasets and perform transactional data operations from the handler method. In some cases,
for example, if the handler does not need to perform data operations, or if the time it takes to
complete all operations may exceed the transaction timeout, it is better to annotate the method
with a different transaction policy, for example:
@GET @Path("/ping") @TransactionPolicy(TransactionControl.EXPLICIT) public void process(HttpServiceRequest request, HttpServiceResponder responder) { getContext().execute(60, new TxRunnable() { // perform data operations }); responder.sendString("Hello World"); }
HttpContentConsumer,
HttpContentProducer| Modifier and Type | Method and Description |
|---|---|
void |
configure(V configurer)
Configures this HttpServiceHandler with the given
HttpServiceConfigurer. |
void |
destroy()
Invoked whenever an instance of this HttpServiceHandler is destroyed.
|
void |
initialize(T context)
Invoked whenever a new instance of this HttpServiceHandler is created.
|
void configure(V configurer)
HttpServiceConfigurer. This method is
invoked at deployment time.configurer - the HttpServiceConfigurer which is used to configure this Handlervoid initialize(T context) throws Exception
initialize in interface ProgramLifecycle<T extends HttpServiceContext>context - An instance of RuntimeContextException - If there is any error during initialization.void destroy()
destroy in interface ProgramLifecycle<T extends HttpServiceContext>Copyright © 2024 Cask Data, Inc. Licensed under the Apache License, Version 2.0.