private void processChildResourceBuilders() { // We have to iterate the set this way to prevent ConcurrentModificationExceptions // caused by the nested invocation of Set.remove(...) in Resource.Builder.onBuildChildResource(...). while (!childResourceBuilders.isEmpty()) { childResourceBuilders.iterator().next().build(); } }
private void processChildResourceBuilders() { // We have to iterate the set this way to prevent ConcurrentModificationExceptions // caused by the nested invocation of Set.remove(...) in Resource.Builder.onBuildChildResource(...). while (!childResourceBuilders.isEmpty()) { childResourceBuilders.iterator().next().build(); } }
private <T> Set<Resource> prefixResources(String prefix, Set<Class<? extends T>> resources) { final String pathPrefix = prefix.endsWith("/") ? prefix.substring(0, prefix.length() - 1) : prefix; return resources .stream() .map(resource -> { final javax.ws.rs.Path pathAnnotation = Resource.getPath(resource); final String resourcePathSuffix = Strings.nullToEmpty(pathAnnotation.value()); final String resourcePath = resourcePathSuffix.startsWith("/") ? pathPrefix + resourcePathSuffix : pathPrefix + "/" + resourcePathSuffix; return Resource .builder(resource) .path(resourcePath) .build(); }) .collect(Collectors.toSet()); }
resourceConfig.registerResources(resourceBuilder.build()); return resourceConfig;
resourceBuilder.addMethod("OPTIONS").handledBy(noContentResponder); return new ResourceConfig().registerResources(resourceBuilder.build());
@Override public void visitResourceMethod(final ResourceMethod resourceMethod) { if (resourceMethod.isExtended()) { return; } if (ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR.equals(resourceMethod.getType())) { if (resourceMethod.getInvocable() != null) { final Invocable i = resourceMethod.getInvocable(); final Type type = i.getResponseType(); final StringBuilder template = getTemplate(); mappings.put((Class) type, getMapping(template)); // Process sub resources ? Resource.Builder builder = Resource .builder(i.getRawResponseType()); if (builder == null) { // for example in the case the return type of the sub resource locator is Object builder = Resource.builder().path(resourceMethod.getParent().getPath()); } final Resource subResource = builder.build(); visitChildResource(subResource); } } processComponents(resourceMethod); }
/** * Create example application resource configuration. * * @return initialized resource configuration of the example application. */ public static ResourceConfig create() { final ResourceConfig resourceConfig = new ResourceConfig(TracingResource.class); final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH_PROGRAMMATIC); resourceBuilder.addMethod(TRACE.NAME).handledBy(new Inflector<ContainerRequestContext, Response>() { @Override public Response apply(ContainerRequestContext request) { if (request == null) { return Response.noContent().build(); } else { return Response.ok(Stringifier.stringify((ContainerRequest) request), MediaType.TEXT_PLAIN).build(); } } }); return resourceConfig.registerResources(resourceBuilder.build()); } }
@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(); }
@Override public ResourceModel processResourceModel(ResourceModel model, Configuration config) { // Create new resource model. final ResourceModel.Builder resourceModelBuilder = new ResourceModel.Builder(false); for (final Resource resource : model.getResources()) { for (Class handlerClass : resource.getHandlerClasses()) { final String packageName = handlerClass.getPackage().getName(); final Optional<String> packagePrefix = packagePrefixes.entrySet().stream() .filter(entry -> packageName.startsWith(entry.getKey())) .sorted((o1, o2) -> -o1.getKey().compareTo(o2.getKey())) .map(Map.Entry::getValue) .findFirst(); if (packagePrefix.isPresent()) { final String prefixedPath = prefixPath(packagePrefix.get(), resource.getPath()); final Resource newResource = Resource.builder(resource) .path(prefixedPath) .build(); resourceModelBuilder.addResource(newResource); } else { resourceModelBuilder.addResource(resource); } } } return resourceModelBuilder.build(); }
private Resource processResource(Resource resource) { Resource.Builder resourceBuilder = Resource.builder(resource.getPath()); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { ResourceMethod.Builder builder = resourceBuilder.addMethod(resourceMethod); if (resourceMethod.getInvocable().getHandlingMethod().isAnnotationPresent(Template.class)) { builder.routingResponseType(Viewable.class); } } if (resource.getResourceLocator() != null) { resourceBuilder.addMethod(resource.getResourceLocator()); } for (Resource child : resource.getChildResources()) { resourceBuilder.addChildResource(processResource(child)); } return resourceBuilder.build(); }
private void registerModel(Resource resourceModel) { final String path = resourceModel.getPath(); if (path != null) { Resource existing = rootResourceMap.get(path); if (existing != null) { // merge resources existing = Resource.builder(existing).mergeWith(resourceModel).build(); rootResourceMap.put(path, existing); } else { rootResourceMap.put(path, resourceModel); } } else { models.add(resourceModel); } }
private void registerModel(Resource resourceModel) { final String path = resourceModel.getPath(); if (path != null) { Resource existing = rootResourceMap.get(path); if (existing != null) { // merge resources existing = Resource.builder(existing).mergeWith(resourceModel).build(); rootResourceMap.put(path, existing); } else { rootResourceMap.put(path, resourceModel); } } else { models.add(resourceModel); } }
@Override public ResourceModel processResourceModel(final ResourceModel resourceModel, final Configuration configuration) { final boolean disabled = PropertiesHelper.isProperty(configuration.getProperty(ServerProperties.WADL_FEATURE_DISABLE)); if (disabled) { return resourceModel; } final ResourceModel.Builder builder = ModelProcessorUtil.enhanceResourceModel(resourceModel, false, methodList, true); // Do not add WadlResource if already present in the classes (i.e. added during scanning). if (!configuration.getClasses().contains(WadlResource.class)) { final Resource wadlResource = Resource.builder(WadlResource.class).build(); builder.addResource(wadlResource); } return builder.build(); }
@Override public ResourceModel processResourceModel(final ResourceModel resourceModel, final Configuration configuration) { final boolean disabled = PropertiesHelper.isProperty(configuration.getProperty(ServerProperties.WADL_FEATURE_DISABLE)); if (disabled) { return resourceModel; } final ResourceModel.Builder builder = ModelProcessorUtil.enhanceResourceModel(resourceModel, false, methodList, true); // Do not add WadlResource if already present in the classes (i.e. added during scanning). if (!configuration.getClasses().contains(WadlResource.class)) { final Resource wadlResource = Resource.builder(WadlResource.class).build(); builder.addResource(wadlResource); } return builder.build(); }
/** * Create a resource model initialized by introspecting an annotated * JAX-RS resource class. * * @param resourceClass resource class to be modelled. * @param disableValidation if set to {@code true}, then any model validation checks will be disabled. * @return resource model initialized by the class or {@code null} if the * class does not represent a resource. */ public static Resource from(Class<?> resourceClass, boolean disableValidation) { final Builder builder = new IntrospectionModeller(resourceClass, disableValidation).createResourceBuilder(); return builder.isEmpty() ? null : builder.build(); }
/** * Create a resource model initialized by introspecting an annotated * JAX-RS resource class. * * @param resourceClass resource class to be modelled. * @param disableValidation if set to {@code true}, then any model validation checks will be disabled. * @return resource model initialized by the class or {@code null} if the * class does not represent a resource. */ public static Resource from(Class<?> resourceClass, boolean disableValidation) { final Builder builder = new IntrospectionModeller(resourceClass, disableValidation).createResourceBuilder(); return builder.isEmpty() ? null : builder.build(); }
/** * Create example application resource configuration. * * @return initialized resource configuration of the example application. */ public static ResourceConfig create() { final ResourceConfig resourceConfig = new ResourceConfig(JaxrsInjectionReportingResource.class); final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH_PROGRAMMATIC); resourceBuilder.addMethod("GET").handledBy(JaxrsInjectionReportingInflector.class); return resourceConfig.registerResources(resourceBuilder.build()); } }
private LocatorRouting createRouting(final Class<?> locatorClass) { Resource.Builder builder = Resource.builder(locatorClass, disableValidation); if (builder == null) { // resource is empty - do not throw 404, wait if ModelProcessors add any method builder = Resource.builder().name(locatorClass.getName()); } return buildRouting(builder.build()); }
private LocatorRouting createRouting(final Class<?> locatorClass) { Resource.Builder builder = Resource.builder(locatorClass, disableValidation); if (builder == null) { // resource is empty - do not throw 404, wait if ModelProcessors add any method builder = Resource.builder().name(locatorClass.getName()); } return buildRouting(builder.build()); }
@Override public ResourceModel processSubResource(ResourceModel subResource, Configuration configuration) { final Resource resource = Resource.builder() .mergeWith(Resource.from(EnhancedSubResourceSingleton.class)) .mergeWith(Resource.from(EnhancedSubResource.class)) .mergeWith(subResource.getResources().get(0)).build(); return new ResourceModel.Builder(true).addResource(resource).build(); } }