@Test public void failedProcessIndexRequest() { when(RequestIdentifier.isConfigRequest(esRequest)).thenReturn(false); when(RequestIdentifier.isMutationRequest(esRequest)).thenReturn(true); when(RequestIdentifier.isIndexRequest(esRequest)).thenReturn(true); when(mockIndexProcessor.processRequest(esRequest, mockLogger)).thenThrow(InternalErrorException.class); APIGatewayProxyResponseEvent result = test.handleRequest(mockRequestEvent, mockContext); verifyZeroInteractions(mockConfigProcessor); verifyZeroInteractions(mockBulkProcessor); verifyZeroInteractions(mockDefaultProcessor); assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, result.getStatusCode().intValue()); }
@Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context) { LambdaLogger logger = context.getLogger(); logger.log("Received API Gateway request event"); try { Request esRequest = HTTPTransformer.apiGatewayRequestToESRequest(requestEvent); ElasticsearchProcessor elasticsearchProcessor = getProcessor(esRequest); Response esConfigResponse = elasticsearchProcessor.processRequest(esRequest, logger); return HTTPTransformer.esResponseToAPIGatewayResponse(esConfigResponse); } catch (InvalidRequestException e) { logger.log("Received InvalidRequestException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (Exception e) { logger.log("Received InternalErrorException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
ElasticsearchProxyRequestHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context) { LambdaLogger logger = context.getLogger(); logger.log("Received API Gateway request event"); try { Request esRequest = HTTPTransformer.apiGatewayRequestToESRequest(requestEvent); ElasticsearchProcessor elasticsearchProcessor = getProcessor(esRequest); Response esConfigResponse = elasticsearchProcessor.processRequest(esRequest, logger); return HTTPTransformer.esResponseToAPIGatewayResponse(esConfigResponse); } catch (InvalidRequestException e) { logger.log("Received InvalidRequestException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (Exception e) { logger.log("Received InternalErrorException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } }
ElasticsearchProxyRequestHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context) { LambdaLogger logger = context.getLogger(); logger.log("Received API Gateway request event"); try { Request esRequest = HTTPTransformer.apiGatewayRequestToESRequest(requestEvent); ElasticsearchProcessor elasticsearchProcessor = getProcessor(esRequest); Response esConfigResponse = elasticsearchProcessor.processRequest(esRequest, logger); return HTTPTransformer.esResponseToAPIGatewayResponse(esConfigResponse); } catch (InvalidRequestException e) { logger.log("Received InvalidRequestException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (Exception e) { logger.log("Received InternalErrorException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } ElasticsearchProxyRequestHandler(); @VisibleForTesting  ElasticsearchProxyRequestHandler(Injector testInjector); }
ElasticsearchProxyRequestHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context) { LambdaLogger logger = context.getLogger(); logger.log("Received API Gateway request event"); try { Request esRequest = HTTPTransformer.apiGatewayRequestToESRequest(requestEvent); ElasticsearchProcessor elasticsearchProcessor = getProcessor(esRequest); Response esConfigResponse = elasticsearchProcessor.processRequest(esRequest, logger); return HTTPTransformer.esResponseToAPIGatewayResponse(esConfigResponse); } catch (InvalidRequestException e) { logger.log("Received InvalidRequestException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (Exception e) { logger.log("Received InternalErrorException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } ElasticsearchProxyRequestHandler(); @VisibleForTesting  ElasticsearchProxyRequestHandler(Injector testInjector); @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context); }
ElasticsearchProxyRequestHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context) { LambdaLogger logger = context.getLogger(); logger.log("Received API Gateway request event"); try { Request esRequest = HTTPTransformer.apiGatewayRequestToESRequest(requestEvent); ElasticsearchProcessor elasticsearchProcessor = getProcessor(esRequest); Response esConfigResponse = elasticsearchProcessor.processRequest(esRequest, logger); return HTTPTransformer.esResponseToAPIGatewayResponse(esConfigResponse); } catch (InvalidRequestException e) { logger.log("Received InvalidRequestException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (Exception e) { logger.log("Received InternalErrorException when processing request"); logger.log(Arrays.toString(e.getStackTrace())); return new APIGatewayProxyResponseEvent() .withBody(e.getMessage()) .withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } ElasticsearchProxyRequestHandler(); @VisibleForTesting  ElasticsearchProxyRequestHandler(Injector testInjector); @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent requestEvent, Context context);  }