Package org.elasticsearch.rest
Class RestController
java.lang.Object
org.elasticsearch.rest.RestController
- All Implemented Interfaces:
HttpServerTransport.Dispatcher
-
Constructor Summary
ConstructorDescriptionRestController(Set<RestHeaderDefinition> headersToCopy, UnaryOperator<RestHandler> handlerWrapper, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dispatchBadRequest(RestChannel channel, ThreadContext threadContext, 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.protected void
registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, String deprecationMessage)
Registers a REST handler to be executed when the providedmethod
andpath
match the request.protected void
registerAsReplacedHandler(RestRequest.Method method, String path, RestHandler handler, RestRequest.Method replacedMethod, String replacedPath)
Registers a REST handler to be executed when the providedmethod
andpath
match the request, or when provided withreplacedMethod
andreplacedPath
.void
registerHandler(RestHandler handler)
Registers a REST handler with the controller.void
registerHandler(RestHandler.Route route, RestHandler handler)
protected void
registerHandler(RestRequest.Method method, String path, RestHandler handler)
Registers a REST handler to be executed when one of the provided methods and path match the request.
-
Constructor Details
-
RestController
public RestController(Set<RestHeaderDefinition> headersToCopy, UnaryOperator<RestHandler> handlerWrapper, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService)
-
-
Method Details
-
registerAsDeprecatedHandler
protected void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, String deprecationMessage)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 response
-
registerAsReplacedHandler
protected void registerAsReplacedHandler(RestRequest.Method method, String path, RestHandler handler, RestRequest.Method replacedMethod, String replacedPath)Registers a REST handler to be executed when the providedmethod
andpath
match the request, or when provided withreplacedMethod
andreplacedPath
. Expected usage:// remove deprecation in next major release controller.registerAsDeprecatedHandler(POST, "/_forcemerge", RestApiVersion.V_8, someHandler, POST, "/_optimize", RestApiVersion.V_7); controller.registerAsDeprecatedHandler(POST, "/{index}/_forcemerge", RestApiVersion.V_8, someHandler, POST, "/{index}/_optimize", RestApiVersion.V_7);
The registered REST handler (
method
withpath
) is a normal REST handler that is not deprecated and it is replacing the deprecated REST handler (replacedMethod
withreplacedPath
) 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)
and a specific message.- Parameters:
method
- GET, POST, etc.path
- Path to handle (e.g. "/_forcemerge")handler
- The handler to actually executereplacedMethod
- GET, POST, etc.replacedPath
- Replaced path to handle (e.g. "/_optimize")
-
registerHandler
Registers a REST handler to be executed when one of the provided methods and path match the request.- Parameters:
method
- GET, POST, etc.path
- Path to handle (e.g. "/{index}/{type}/_bulk")handler
- The handler to actually execute
-
registerHandler
-
registerHandler
Registers a REST handler with the controller. The REST handler declares themethod
andpath
combinations. -
dispatchRequest
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
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:
channel
- the response channel of this requestthreadContext
- the thread contextcause
- the cause of the bad request
-