@Test public void shouldReturnBadRequestWhenRequestBodyIsInvalid() throws Exception { when(context.body()).thenReturn("{\"foo\": \"bar\"}"); handler.handle(context); verify(context).status(SC_BAD_REQUEST); }
@OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override public void handle(Context ctx) throws Exception { try { final List<SubnetSubscription> request = jsonProvider.getObjectMapper().readValue(ctx.body(), new TypeReference<>() {}); provider.subscribeToPersistentSubnets(request); ctx.status(SC_OK); } catch (final JsonMappingException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } catch (Exception e) { ctx.status(SC_INTERNAL_SERVER_ERROR); } }
PostSubscribeToPersistentSubnets implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override public void handle(Context ctx) throws Exception { try { final List<SubnetSubscription> request = jsonProvider.getObjectMapper().readValue(ctx.body(), new TypeReference<>() {}); provider.subscribeToPersistentSubnets(request); ctx.status(SC_OK); } catch (final JsonMappingException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } catch (Exception e) { ctx.status(SC_INTERNAL_SERVER_ERROR); } } }
PostSubscribeToPersistentSubnets implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override public void handle(Context ctx) throws Exception { try { final List<SubnetSubscription> request = jsonProvider.getObjectMapper().readValue(ctx.body(), new TypeReference<>() {}); provider.subscribeToPersistentSubnets(request); ctx.status(SC_OK); } catch (final JsonMappingException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } catch (Exception e) { ctx.status(SC_INTERNAL_SERVER_ERROR); } } PostSubscribeToPersistentSubnets(
      final ValidatorDataProvider provider, final JsonProvider jsonProvider); }
PostSubscribeToPersistentSubnets implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override public void handle(Context ctx) throws Exception { try { final List<SubnetSubscription> request = jsonProvider.getObjectMapper().readValue(ctx.body(), new TypeReference<>() {}); provider.subscribeToPersistentSubnets(request); ctx.status(SC_OK); } catch (final JsonMappingException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } catch (Exception e) { ctx.status(SC_INTERNAL_SERVER_ERROR); } } PostSubscribeToPersistentSubnets(
      final ValidatorDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override void handle(Context ctx); }
PostSubscribeToPersistentSubnets implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override public void handle(Context ctx) throws Exception { try { final List<SubnetSubscription> request = jsonProvider.getObjectMapper().readValue(ctx.body(), new TypeReference<>() {}); provider.subscribeToPersistentSubnets(request); ctx.status(SC_OK); } catch (final JsonMappingException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } catch (Exception e) { ctx.status(SC_INTERNAL_SERVER_ERROR); } } PostSubscribeToPersistentSubnets(
      final ValidatorDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.POST, summary = "Subscribe beacon node persistently to a list of subnets.", tags = {TAG_VALIDATOR}, requestBody = @OpenApiRequestBody( content = {@OpenApiContent(from = SubnetSubscription.class, isArray = true)}), responses = { @OpenApiResponse(status = RES_OK, description = "Subscribed to subnets."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid request syntax."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") }) @Override void handle(Context ctx); static final String ROUTE; }