Java Code Examples for org.glassfish.jersey.server.model.Resource#builder()
The following examples show how to use
org.glassfish.jersey.server.model.Resource#builder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KrazoModelProcessor.java From krazo with Apache License 2.0 | 6 votes |
/** * Updates the default {@code @Produces} list of every controller method whose list is empty. * The new list contains a single media type: "text/html". * * @param r resource to process. * @return newly updated resource. */ private static Resource processResource(Resource r) { final boolean isControllerClass = isController(r); Resource.Builder rb = Resource.builder(r); r.getAllMethods().forEach( (ResourceMethod m) -> { if ((isController(m) || isControllerClass) && m.getProducedTypes().isEmpty()) { final ResourceMethod.Builder rmb = rb.updateMethod(m); rmb.produces(MediaType.TEXT_HTML_TYPE); rmb.build(); } } ); r.getChildResources().forEach(cr -> { rb.replaceChildResource(cr, processResource(cr)); }); return rb.build(); }
Example 2
Source File: OzarkModelProcessor.java From ozark with Apache License 2.0 | 6 votes |
/** * Updates the default {@code @Produces} list of every controller method whose list is empty. * The new list contains a single media type: "text/html". * * @param r resource to process. * @return newly updated resource. */ private static Resource processResource(Resource r) { final boolean isControllerClass = isController(r); Resource.Builder rb = Resource.builder(r); r.getAllMethods().forEach( (ResourceMethod m) -> { if ((isController(m) || isControllerClass) && m.getProducedTypes().isEmpty()) { final ResourceMethod.Builder rmb = rb.updateMethod(m); rmb.produces(MediaType.TEXT_HTML_TYPE); rmb.build(); } } ); r.getChildResources().forEach(cr -> { rb.replaceChildResource(cr, processResource(cr)); }); return rb.build(); }
Example 3
Source File: OpenAPIInflector.java From swagger-inflector with Apache License 2.0 | 5 votes |
private void enableSwaggerJSON(OpenAPI openAPI, List<String> swaggerProcessors) { final Resource.Builder builder = Resource.builder(); builder.path(basePath(originalBasePath, StringUtils.appendIfMissing(config.getSwaggerBase(), "/") + "openapi.json")) .addMethod(HttpMethod.GET) .produces(MediaType.APPLICATION_JSON) .handledBy(new OpenAPIResourceController(openAPI, swaggerProcessors)) .build(); registerResources(builder.build()); }
Example 4
Source File: OpenAPIInflector.java From swagger-inflector with Apache License 2.0 | 5 votes |
private void enableSwaggerYAML(OpenAPI openAPI, List<String> swaggerProcessors) { final Resource.Builder builder = Resource.builder(); builder.path(basePath(originalBasePath, StringUtils.appendIfMissing(config.getSwaggerBase(), "/") + "openapi.yaml")) .addMethod(HttpMethod.GET) .produces("application/yaml") .handledBy(new OpenAPIResourceController(openAPI, swaggerProcessors)) .build(); registerResources(builder.build()); }
Example 5
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private void registerCrudApi(String path, Inflector<ContainerRequestContext, Response> handler, Inflector<ContainerRequestContext, Response> linksHandler) { Resource.Builder core = Resource.builder(path); // list endpoints (both do the same thing) core.addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("search/{querytype}").addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("search").addMethod(GET).produces(JSON).handledBy(handler); // CRUD endpoints (non-batch) core.addMethod(POST).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(PUT).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(PATCH).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(DELETE).produces(JSON).handledBy(handler); // links CRUD endpoints core.addChildResource("{id}/links/{type2}/{id2}").addMethod(GET).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{type2}").addMethod(GET).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{id2}").addMethod(POST).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{id2}").addMethod(PUT).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{type2}/{id2}").addMethod(DELETE).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links").addMethod(DELETE).produces(JSON).handledBy(linksHandler); // CRUD endpoints (batch) Resource.Builder batch = Resource.builder("_batch"); batch.addMethod(POST).produces(JSON).consumes(JSON).handledBy(batchCreateHandler(null)); batch.addMethod(GET).produces(JSON).handledBy(batchReadHandler(null)); batch.addMethod(PUT).produces(JSON).consumes(JSON).handledBy(batchCreateHandler(null)); batch.addMethod(PATCH).produces(JSON).consumes(JSON).handledBy(batchUpdateHandler(null)); batch.addMethod(DELETE).produces(JSON).handledBy(batchDeleteHandler(null)); registerResources(core.build()); registerResources(batch.build()); }