java.lang.Object
org.elasticsearch.rest.RestController
- All Implemented Interfaces:
HttpServerTransport.Dispatcher
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRestController(RestInterceptor restInterceptor, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService, TelemetryProvider telemetryProvider) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckSupported(RestRequest.Method method, String path, Set<String> parameters, Set<String> capabilities, RestApiVersion restApiVersion) voiddispatchBadRequest(RestChannel channel, ThreadContext threadContext, Throwable cause) Dispatches a bad request.voiddispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) Dispatches theRestRequestto the relevant request handler or responds to the given rest channel directly if the request can't be handled by any request handler.Returns the holder for search usage statistics, to be used to track search usage when parsing incoming search requests from the relevant REST endpoints.getStats()protected voidregisterAsDeprecatedHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler, String deprecationMessage, org.apache.logging.log4j.Level deprecationLevel) Registers a REST handler to be executed when the providedmethodandpathmatch the request.protected voidregisterAsReplacedHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler, RestRequest.Method replacedMethod, String replacedPath, RestApiVersion replacedVersion, String replacedMessage, org.apache.logging.log4j.Level deprecationLevel) Registers a REST handler to be executed when the providedmethodandpathmatch the request, or when provided withreplacedMethodandreplacedPath.voidregisterHandler(RestHandler handler) Registers a REST handler with the controller.voidregisterHandler(RestHandler.Route route, RestHandler handler) protected voidregisterHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler) Registers a REST handler to be executed when one of the provided methods and path match the request.protected voidvalidateRequest(RestRequest request, RestHandler handler, NodeClient client) Validates that the request should be allowed.
-
Field Details
-
STATUS_CODE_KEY
- See Also:
-
HANDLER_NAME_KEY
- See Also:
-
REQUEST_METHOD_KEY
- See Also:
-
ERROR_TRACE_DEFAULT
public static final boolean ERROR_TRACE_DEFAULT- See Also:
-
METRIC_REQUESTS_TOTAL
- See Also:
-
-
Constructor Details
-
RestController
public RestController(RestInterceptor restInterceptor, NodeClient client, CircuitBreakerService circuitBreakerService, UsageService usageService, TelemetryProvider telemetryProvider)
-
-
Method Details
-
getApiProtections
-
registerAsDeprecatedHandler
protected void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler, String deprecationMessage, org.apache.logging.log4j.Level deprecationLevel) Registers a REST handler to be executed when the providedmethodandpathmatch the request.- Parameters:
method- GET, POST, etc.path- Path to handle (e.g. "/{index}/{type}/_bulk")version- API version to handle (e.g. RestApiVersion.V_8)handler- The handler to actually executedeprecationMessage- The message to log and send as a header in the responsedeprecationLevel- The deprecation log level to use for the deprecation warning, either WARN or CRITICAL
-
registerAsReplacedHandler
protected void registerAsReplacedHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler, RestRequest.Method replacedMethod, String replacedPath, RestApiVersion replacedVersion, String replacedMessage, org.apache.logging.log4j.Level deprecationLevel) Registers a REST handler to be executed when the providedmethodandpathmatch the request, or when provided withreplacedMethodandreplacedPath. 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 (
methodwithpath) is a normal REST handler that is not deprecated and it is replacing the deprecated REST handler (replacedMethodwithreplacedPath) 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.core.RestApiVersion, org.elasticsearch.rest.RestHandler, java.lang.String, org.apache.logging.log4j.Level)and a specific message.- Parameters:
method- GET, POST, etc.path- Path to handle (e.g. "/_forcemerge")version- API version to handle (e.g. RestApiVersion.V_8)handler- The handler to actually executereplacedMethod- GET, POST, etc.replacedPath- Replaced path to handle (e.g. "/_optimize")replacedVersion- Replaced API version to handle (e.g. RestApiVersion.V_7)
-
registerHandler
protected void registerHandler(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler) 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")version- API version to handle (e.g. RestApiVersion.V_8)handler- The handler to actually execute
-
registerHandler
-
registerHandler
Registers a REST handler with the controller. The REST handler declares themethodandpathcombinations. -
dispatchRequest
Description copied from interface:HttpServerTransport.DispatcherDispatches theRestRequestto 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:
dispatchRequestin interfaceHttpServerTransport.Dispatcher- Parameters:
request- the request to dispatchchannel- the response channel of this requestthreadContext- the thread context
-
dispatchBadRequest
Description copied from interface:HttpServerTransport.DispatcherDispatches 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:
dispatchBadRequestin interfaceHttpServerTransport.Dispatcher- Parameters:
channel- the response channel of this requestthreadContext- the thread contextcause- the cause of the bad request
-
checkSupported
public boolean checkSupported(RestRequest.Method method, String path, Set<String> parameters, Set<String> capabilities, RestApiVersion restApiVersion) -
getStats
- Specified by:
getStatsin interfaceHttpServerTransport.Dispatcher
-
validateRequest
protected void validateRequest(RestRequest request, RestHandler handler, NodeClient client) throws ElasticsearchStatusException Validates that the request should be allowed. Throws an exception if the request should be rejected.- Throws:
ElasticsearchStatusException
-
getSearchUsageHolder
Returns the holder for search usage statistics, to be used to track search usage when parsing incoming search requests from the relevant REST endpoints. This is exposed for plugins that expose search functionalities which need to contribute to the search usage statistics.
-