Refine search
/** * Create a builder from an existing resource method model. * * @param parent parent resource model builder. * @param originalMethod existing resource method model to create the builder from. */ /* package */ Builder(final Resource.Builder parent, ResourceMethod originalMethod) { this.parent = parent; this.consumedTypes = new LinkedHashSet<>(originalMethod.getConsumedTypes()); this.producedTypes = new LinkedHashSet<>(originalMethod.getProducedTypes()); this.suspended = originalMethod.isSuspendDeclared(); this.suspendTimeout = originalMethod.getSuspendTimeout(); this.suspendTimeoutUnit = originalMethod.getSuspendTimeoutUnit(); this.handlerParameters = new LinkedHashSet<>(originalMethod.getInvocable().getHandler().getParameters()); this.nameBindings = originalMethod.getNameBindings(); this.httpMethod = originalMethod.getHttpMethod(); this.managedAsync = originalMethod.isManagedAsyncDeclared(); Invocable invocable = originalMethod.getInvocable(); this.handlingMethod = invocable.getHandlingMethod(); this.encodedParams = false; this.routingResponseType = invocable.getRoutingResponseType(); this.extended = originalMethod.isExtended(); Method handlerMethod = invocable.getDefinitionMethod(); MethodHandler handler = invocable.getHandler(); if (handler.isClassBased()) { handledBy(handler.getHandlerClass(), handlerMethod); } else { handledBy(handler.getHandlerInstance(), handlerMethod); } }
ClipboardDataProvider.TextPlain.class); final Resource.Builder resourceBuilder = Resource.builder("echo"); ResourceMethod.Builder rmBuilder = resourceBuilder.addMethod("POST"); rmBuilder.consumes(jsonAndTextTypes).produces(jsonAndTextTypes) .handledBy(new Inflector<ContainerRequestContext, Response>() { resourceConfig.registerResources(resourceBuilder.build()); return resourceConfig;
private void processMethodBuilders() { // We have to iterate the set this way to prevent ConcurrentModificationExceptions // caused by the nested invocation of Set.remove(...) in Resource.Builder.onBuildMethod(...). while (!methodBuilders.isEmpty()) { methodBuilders.iterator().next().build(); } }
final Resource.Builder resourceBuilder = Resource.builder(path); builder.addResource(Resource.from(endpointDefinition.getImplementationClass())); final ResourceModel resourceModel = builder.build(); if (CollectionUtils.isNotEmpty(c.getResourceMethods())) { for (ResourceMethod m : c.getResourceMethods()) { final Method handlingMethod = m.getInvocable().getHandlingMethod(); log.debug("Add path {}", c.getPath()); resourceBuilder.addChildResource(c.getPath()) .addMethod(m) .handledBy(endpoint, handlingMethod); for (Resource cr : c.getChildResources()) { for (ResourceMethod m : cr.getResourceMethods()) { final Method handlingMethod = m.getInvocable().getHandlingMethod(); final Path annotation = handlingMethod.getAnnotation(Path.class); final String relativePath = new String(c.getPath() + annotation.value()).replaceAll("//", "/"); log.debug("Add child path {}", relativePath); resourceBuilder.addChildResource(relativePath) .addMethod(m) .handledBy(endpoint, handlingMethod);
final Resource.Builder resourceBuilder = Resource.builder(firstResource.getPath()); final Resource.Builder builder = method.path != null ? resourceBuilder.addChildResource(method.path) : resourceBuilder; final ResourceMethod.Builder methodBuilder = builder .addMethod(method.httpMethod) .consumes(method.consumes) .produces(produces); methodBuilder.handledBy(method.inflector); } else { methodBuilder.handledBy(method.inflectorClass); methodBuilder.extended(extended); final Resource newResource = resourceBuilder.build(); if (parentResource != null) { final Resource.Builder parentBuilder = Resource.builder(parentResource.getPath()); parentBuilder.addChildResource(newResource); enhancedModelBuilder.addResource(parentBuilder.build());
/** * 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(); }
private void createMethod(Resource.Builder resourceBuilder, ResourceMethod template, F3ResourceHandler handler) { ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(template.getHttpMethod()); methodBuilder.consumes(template.getConsumedTypes()); methodBuilder.produces(template.getProducedTypes()); methodBuilder.handledBy(handler, template.getInvocable().getHandlingMethod()); }
@Override public ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration) { ResourceModel.Builder builder = new ResourceModel.Builder(resourceModel.getRootResources(), false); final Resource singletonResource = Resource.from(SingletonResource.class); builder.addResource(singletonResource); final Resource requestScopeResource = Resource.from(RequestScopeResource.class); builder.addResource(requestScopeResource); final Resource.Builder resourceBuilder = Resource.builder("instance"); resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() { private int counter = 0; @Override public String apply(ContainerRequestContext containerRequestContext) { return String.valueOf("Inflector:" + counter++); } }); final Resource instanceResource = resourceBuilder.build(); builder.addResource(instanceResource); return builder.build(); }
/** * Add consumed media types supported by the component. * * @param types consumed media types. * @return updated builder object. */ public Builder consumes(MediaType... types) { return consumes(Arrays.asList(types)); }
/** * Define an inflector-based resource method handler binding. * * @param inflectorClass class of the inflector handling the resource method. * @return updated builder object. */ public Builder handledBy(Class<? extends Inflector> inflectorClass) { return handledBy(inflectorClass, Invocable.APPLY_INFLECTOR_METHOD); }
/** * Add produced media types supported by the component. * * @param types produced media types. * @return updated builder object. */ public Builder produces(MediaType... types) { return produces(Arrays.asList(types)); }
/** * Add produced media types supported by the component. * * @param types produced media types. * @return updated builder object. */ public Builder produces(MediaType... types) { return produces(Arrays.asList(types)); }
/** * Define an inflector-based resource method handler binding. * * @param inflectorClass class of the inflector handling the resource method. * @return updated builder object. */ public Builder handledBy(Class<? extends Inflector> inflectorClass) { return handledBy(inflectorClass, Invocable.APPLY_INFLECTOR_METHOD); }
/** * Add consumed media types supported by the component. * * @param types consumed media types. * @return updated builder object. */ public Builder consumes(String... types) { return consumes(MediaTypes.createFrom(types)); }
/** * Add produced media types supported by the component. * * @param types produced media types. * @return updated builder object. */ public Builder produces(String... types) { return produces(MediaTypes.createFrom(types)); }
/** * Define an inflector-based resource method handler binding. * * @param inflector inflector handling the resource method. * @return updated builder object. */ public Builder handledBy(Inflector<ContainerRequestContext, ?> inflector) { return handledBy(inflector, Invocable.APPLY_INFLECTOR_METHOD); }
/** * Define an inflector-based resource method handler binding. * * @param inflector inflector handling the resource method. * @return updated builder object. */ public Builder handledBy(Inflector<ContainerRequestContext, ?> inflector) { return handledBy(inflector, Invocable.APPLY_INFLECTOR_METHOD); }
private void processMethodBuilders() { // We have to iterate the set this way to prevent ConcurrentModificationExceptions // caused by the nested invocation of Set.remove(...) in Resource.Builder.onBuildMethod(...). while (!methodBuilders.isEmpty()) { methodBuilders.iterator().next().build(); } }
/** * Add consumed media types supported by the component. * * @param types consumed media types. * @return updated builder object. */ public Builder consumes(String... types) { return consumes(MediaTypes.createFrom(types)); }
/** * Add consumed media types supported by the component. * * @param types consumed media types. * @return updated builder object. */ public Builder consumes(MediaType... types) { return consumes(Arrays.asList(types)); }