@Test public void create_invalidResourceBody() { when(context.getBodyAsJson()).thenReturn(new JsonObject(Json.encode(new Resource().setId(RESOURCE_ID)))); endpoint.create(context); verify(context).fail(errCaptor.capture()); Assert.assertTrue(errCaptor.getValue() instanceof InvalidRequestException); }
public void create(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); String basePath = UriBuilderRequest.resolveProxyRequest(context); this.extractRequest(context) .flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())) .subscribe( resource -> { final String resourceLocation = resourceLocation(basePath, resource); context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .putHeader(HttpHeaders.LOCATION, resourceLocation) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation))); } , error -> context.fail(error) ); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { public void create(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); String basePath = UriBuilderRequest.resolveProxyRequest(context); this.extractRequest(context) .flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())) .subscribe( resource -> { final String resourceLocation = resourceLocation(basePath, resource); context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .putHeader(HttpHeaders.LOCATION, resourceLocation) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation))); } , error -> context.fail(error) ); } }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { public void create(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); String basePath = UriBuilderRequest.resolveProxyRequest(context); this.extractRequest(context) .flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())) .subscribe( resource -> { final String resourceLocation = resourceLocation(basePath, resource); context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .putHeader(HttpHeaders.LOCATION, resourceLocation) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation))); } , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { public void create(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); String basePath = UriBuilderRequest.resolveProxyRequest(context); this.extractRequest(context) .flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())) .subscribe( resource -> { final String resourceLocation = resourceLocation(basePath, resource); context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .putHeader(HttpHeaders.LOCATION, resourceLocation) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation))); } , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); @Override void handle(RoutingContext context); void create(RoutingContext context); void get(RoutingContext context); void update(RoutingContext context); void delete(RoutingContext context); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { public void create(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); String basePath = UriBuilderRequest.resolveProxyRequest(context); this.extractRequest(context) .flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())) .subscribe( resource -> { final String resourceLocation = resourceLocation(basePath, resource); context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .putHeader(HttpHeaders.LOCATION, resourceLocation) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation))); } , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); @Override void handle(RoutingContext context); void create(RoutingContext context); void get(RoutingContext context); void update(RoutingContext context); void delete(RoutingContext context);  }