Finds the right handler for an HTTP query (either built-in or user plugin) and executes it. Also handles simple and pre-flight CORS requests if configured, rejecting requests that do not match a domain in the list. @param chan The channel on which the query was received. @param req The parsed HTTP r
(final TSDB tsdb, final Channel chan, final HttpRequest req)
| 247 | * @param req The parsed HTTP request. |
| 248 | */ |
| 249 | private void handleHttpQuery(final TSDB tsdb, final Channel chan, final HttpRequest req) { |
| 250 | AbstractHttpQuery abstractQuery = null; |
| 251 | try { |
| 252 | abstractQuery = createQueryInstance(tsdb, req, chan); |
| 253 | if (!tsdb.getConfig().enable_chunked_requests() && req.isChunked()) { |
| 254 | logError(abstractQuery, "Received an unsupported chunked request: " |
| 255 | + abstractQuery.request()); |
| 256 | abstractQuery.badRequest(new BadRequestException("Chunked request not supported.")); |
| 257 | return; |
| 258 | } |
| 259 | // NOTE: Some methods in HttpQuery have side-effects (getQueryBaseRoute and |
| 260 | // setSerializer for instance) so invocation order is important here. |
| 261 | final String route = abstractQuery.getQueryBaseRoute(); |
| 262 | if (abstractQuery.getClass().isAssignableFrom(HttpRpcPluginQuery.class)) { |
| 263 | if (applyCorsConfig(req, abstractQuery)) { |
| 264 | return; |
| 265 | } |
| 266 | final HttpRpcPluginQuery pluginQuery = (HttpRpcPluginQuery) abstractQuery; |
| 267 | final HttpRpcPlugin rpc = rpc_manager.lookupHttpRpcPlugin(route); |
| 268 | if (rpc != null) { |
| 269 | rpc.execute(tsdb, pluginQuery); |
| 270 | } else { |
| 271 | pluginQuery.notFound(); |
| 272 | } |
| 273 | } else if (abstractQuery.getClass().isAssignableFrom(HttpQuery.class)) { |
| 274 | final HttpQuery builtinQuery = (HttpQuery) abstractQuery; |
| 275 | builtinQuery.setSerializer(); |
| 276 | if (applyCorsConfig(req, abstractQuery)) { |
| 277 | return; |
| 278 | } |
| 279 | final HttpRpc rpc = rpc_manager.lookupHttpRpc(route); |
| 280 | if (rpc != null) { |
| 281 | rpc.execute(tsdb, builtinQuery); |
| 282 | } else { |
| 283 | builtinQuery.notFound(); |
| 284 | } |
| 285 | } else { |
| 286 | throw new IllegalStateException("Unknown instance of AbstractHttpQuery: " |
| 287 | + abstractQuery.getClass().getName()); |
| 288 | } |
| 289 | } catch (BadRequestException ex) { |
| 290 | if (abstractQuery == null) { |
| 291 | LOG.warn("{} Unable to create query for {}. Reason: {}", chan, req, ex); |
| 292 | sendStatusAndClose(chan, HttpResponseStatus.BAD_REQUEST); |
| 293 | } else { |
| 294 | abstractQuery.badRequest(ex); |
| 295 | } |
| 296 | } catch (Exception ex) { |
| 297 | exceptions_caught.incrementAndGet(); |
| 298 | if (abstractQuery == null) { |
| 299 | LOG.warn("{} Unexpected error handling HTTP request {}. Reason: {} ", chan, req, ex); |
| 300 | sendStatusAndClose(chan, HttpResponseStatus.INTERNAL_SERVER_ERROR); |
| 301 | } else { |
| 302 | abstractQuery.internalError(ex); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 |
no test coverage detected