Package org.elasticsearch.rest
Class RestController
- java.lang.Object
-
- org.elasticsearch.rest.RestController
-
- All Implemented Interfaces:
HttpServerTransport.Dispatcher
public class RestController extends java.lang.Object implements HttpServerTransport.Dispatcher
-
-
Constructor Summary
Constructors Constructor Description RestController(java.util.Set<java.lang.String> headersToCopy, java.util.function.UnaryOperator<RestHandler> handlerWrapper, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService)
-
Method Summary
Modifier and Type Method Description boolean
canTripCircuitBreaker(java.util.Optional<RestHandler> handler)
void
dispatchBadRequest(RestRequest request, RestChannel channel, ThreadContext threadContext, java.lang.Throwable cause)
Dispatches a bad request.void
dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext)
Dispatches theRestRequest
to the relevant request handler or responds to the given rest channel directly if the request can't be handled by any request handler.void
registerAsDeprecatedHandler(RestRequest.Method method, java.lang.String path, RestHandler handler, java.lang.String deprecationMessage, DeprecationLogger logger)
Registers a REST handler to be executed when the providedmethod
andpath
match the request.void
registerHandler(RestRequest.Method method, java.lang.String path, RestHandler handler)
Registers a REST handler to be executed when one of the provided methods and path match the request.void
registerWithDeprecatedHandler(RestRequest.Method method, java.lang.String path, RestHandler handler, RestRequest.Method deprecatedMethod, java.lang.String deprecatedPath, DeprecationLogger logger)
Registers a REST handler to be executed when the providedmethod
andpath
match the request, or when provided withdeprecatedMethod
anddeprecatedPath
.
-
-
-
Constructor Detail
-
RestController
public RestController(java.util.Set<java.lang.String> headersToCopy, java.util.function.UnaryOperator<RestHandler> handlerWrapper, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService)
-
-
Method Detail
-
registerAsDeprecatedHandler
public void registerAsDeprecatedHandler(RestRequest.Method method, java.lang.String path, RestHandler handler, java.lang.String deprecationMessage, DeprecationLogger logger)
Registers a REST handler to be executed when the providedmethod
andpath
match the request.- Parameters:
method
- GET, POST, etc.path
- Path to handle (e.g., "/{index}/{type}/_bulk")handler
- The handler to actually executedeprecationMessage
- The message to log and send as a header in the responselogger
- The existing deprecation logger to use
-
registerWithDeprecatedHandler
public void registerWithDeprecatedHandler(RestRequest.Method method, java.lang.String path, RestHandler handler, RestRequest.Method deprecatedMethod, java.lang.String deprecatedPath, DeprecationLogger logger)
Registers a REST handler to be executed when the providedmethod
andpath
match the request, or when provided withdeprecatedMethod
anddeprecatedPath
. Expected usage:// remove deprecation in next major release controller.registerWithDeprecatedHandler(POST, "/_forcemerge", this, POST, "/_optimize", deprecationLogger); controller.registerWithDeprecatedHandler(POST, "/{index}/_forcemerge", this, POST, "/{index}/_optimize", deprecationLogger);
The registered REST handler (
method
withpath
) is a normal REST handler that is not deprecated and it is replacing the deprecated REST handler (deprecatedMethod
withdeprecatedPath
) that is using the samehandler
.Deprecated REST handlers without a direct replacement should be deprecated directly using
registerAsDeprecatedHandler(org.elasticsearch.rest.RestRequest.Method, java.lang.String, org.elasticsearch.rest.RestHandler, java.lang.String, org.elasticsearch.common.logging.DeprecationLogger)
and a specific message.- Parameters:
method
- GET, POST, etc.path
- Path to handle (e.g., "/_forcemerge")handler
- The handler to actually executedeprecatedMethod
- GET, POST, etc.deprecatedPath
- Deprecated path to handle (e.g., "/_optimize")logger
- The existing deprecation logger to use
-
registerHandler
public void registerHandler(RestRequest.Method method, java.lang.String path, RestHandler handler)
Registers a REST handler to be executed when one of the provided methods and path match the request.- Parameters:
path
- Path to handle (e.g., "/{index}/{type}/_bulk")handler
- The handler to actually executemethod
- GET, POST, etc.
-
canTripCircuitBreaker
public boolean canTripCircuitBreaker(java.util.Optional<RestHandler> handler)
- Returns:
- true iff the circuit breaker limit must be enforced for processing this request.
-
dispatchRequest
public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext)
Description copied from interface:HttpServerTransport.Dispatcher
Dispatches theRestRequest
to the relevant request handler or responds to the given rest channel directly if the request can't be handled by any request handler.- Specified by:
dispatchRequest
in interfaceHttpServerTransport.Dispatcher
- Parameters:
request
- the request to dispatchchannel
- the response channel of this requestthreadContext
- the thread context
-
dispatchBadRequest
public void dispatchBadRequest(RestRequest request, RestChannel channel, ThreadContext threadContext, java.lang.Throwable cause)
Description copied from interface:HttpServerTransport.Dispatcher
Dispatches a bad request. For example, if a request is malformed it will be dispatched via this method with the cause of the bad request.- Specified by:
dispatchBadRequest
in interfaceHttpServerTransport.Dispatcher
- Parameters:
request
- the request to dispatchchannel
- the response channel of this requestthreadContext
- the thread contextcause
- the cause of the bad request
-
-