private void logResources(List<Resource> resources) { final List<ResourceDescription> resourceDescriptions = new ArrayList<>(); for (Resource resource : resources) { for (ResourceMethod resourceMethod : resource.getAllMethods()) { final String path = RestTools.getPathFromResource(resource); resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses())); } } Collections.sort(resourceDescriptions); for (ResourceDescription resource : resourceDescriptions) { LOG.debug(resource.toString()); } }
private List<EndpointLogLine> logMethodLines(Resource resource, String contextPath) { final List<EndpointLogLine> methodLines = new ArrayList<>(); for (ResourceMethod method : resource.getAllMethods()) { if ("OPTIONS".equalsIgnoreCase(method.getHttpMethod())) { continue;
@Override public void onEvent(final ApplicationEvent event) { if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) { event.getResourceModel().getResources().parallelStream() .filter(Objects::nonNull) .forEach(resource -> { this.registerCircuitBreakerAnnotations(resource.getAllMethods()); resource.getChildResources().parallelStream() .filter(Objects::nonNull) .forEach(childResource -> { this.registerCircuitBreakerAnnotations( childResource.getAllMethods()); }); }); } }
private void logResources(List<Resource> resources) { final List<ResourceDescription> resourceDescriptions = new ArrayList<>(); for (Resource resource : resources) { for (ResourceMethod resourceMethod : resource.getAllMethods()) { final String path = RestTools.getPathFromResource(resource); resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses())); } } Collections.sort(resourceDescriptions); for (ResourceDescription resource : resourceDescriptions) { LOG.debug(resource.toString()); } }
/** * <p>getRoutes.</p> * * @return a {@link java.util.List} object. */ @GET public List<String> getRoutes() { List<Resource> resourceList = resourceContext.getResourceModel().getResources(); List<String> routeList = Lists.newArrayList(); for (Resource resource : resourceList) { String path = resource.getPath().startsWith("/") ? "" : "/" + resource.getPath(); if (resource.getAllMethods().size() > 0) { routeList.add(path); } routeList.addAll( resource.getChildResources() .stream() .map(res -> path + (res.getPath().startsWith("/") ? "" : "/") + res.getPath()) .collect(Collectors.toList()) ); } return routeList; }
public void onEvent(ApplicationEvent event) { if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) { for (Resource resource : event.getResourceModel().getResources()) { for (ResourceMethod method : resource.getAllMethods()) { registerAuditedMethodAnnotations(method); } for (Resource childResource : resource.getChildResources()) { for (ResourceMethod method : childResource.getAllMethods()) { registerAuditedMethodAnnotations(method); } } } } }
public void onEvent(ApplicationEvent event) { if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) { for (Resource resource : event.getResourceModel().getResources()) { for (ResourceMethod method : resource.getAllMethods()) { registerUnitOfWorkWithDetachAnnotations(method); } for (Resource childResource : resource.getChildResources()) { for (ResourceMethod method : childResource.getAllMethods()) { registerUnitOfWorkWithDetachAnnotations(method); } } } } }
private void logResources(List<Resource> resources) { final List<ResourceDescription> resourceDescriptions = new ArrayList<>(); for (Resource resource : resources) { for (ResourceMethod resourceMethod : resource.getAllMethods()) { String path = resource.getPath(); Resource parent = resource.getParent(); while (parent != null) { if (!path.startsWith("/")) { path = "/" + path; } path = parent.getPath() + path; parent = parent.getParent(); } resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses())); } } Collections.sort(resourceDescriptions); for (ResourceDescription resource : resourceDescriptions) { LOG.debug(resource.toString()); } }
private Resource createResource(F3ResourceHandler handler) { Resource template = Resource.from(handler.getInterface()); Resource.Builder resourceBuilder = Resource.builder(template.getPath()); for (ResourceMethod resourceMethod : template.getAllMethods()) { createMethod(resourceBuilder, resourceMethod, handler); } for (Resource childTemplate : template.getChildResources()) { Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath()); for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) { createMethod(childResourceBuilder, resourceMethod, handler); } resourceBuilder.addChildResource(childResourceBuilder.build()); } return resourceBuilder.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(); }
for (ResourceMethod method : childResource.getAllMethods()) { if (method.getType() == ResourceMethod.JaxrsType.RESOURCE_METHOD) { final String path = normalizePath(basePath, childResource.getPath());
private Resource createResource(F3ResourceHandler handler) { Class<?> interfaze = handler.getInterface(); Resource template = Resource.from(interfaze); if (template == null) { throw new Fabric3Exception("Interface is not a JAX-RS resource: " + interfaze.getName()); } // introspect consumes and produces annotations on the JAX-RS type as well as in meta-annotations Consumes consumes = AnnotationHelper.findAnnotation(Consumes.class, interfaze); String[] consumeTypes = consumes != null ? consumes.value() : EMPTY_ARRAY; Produces produces = AnnotationHelper.findAnnotation(Produces.class, interfaze); String[] produceTypes = produces != null ? produces.value() : EMPTY_ARRAY; Resource.Builder resourceBuilder = Resource.builder(template.getPath()); for (ResourceMethod resourceMethod : template.getAllMethods()) { createMethod(resourceBuilder, resourceMethod, handler, consumeTypes, produceTypes); } for (Resource childTemplate : template.getChildResources()) { Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath()); for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) { createMethod(childResourceBuilder, resourceMethod, handler, consumeTypes, produceTypes); } resourceBuilder.addChildResource(childResourceBuilder.build()); } return resourceBuilder.build(); }
private Resource createResource(F3ResourceHandler handler) { Class<?> interfaze = handler.getInterface(); Resource template = Resource.from(interfaze); if (template == null) { throw new Fabric3Exception("Interface is not a JAX-RS resource: " + interfaze.getName()); } // introspect consumes and produces annotations on the JAX-RS type as well as in meta-annotations Consumes consumes = AnnotationHelper.findAnnotation(Consumes.class, interfaze); String[] consumeTypes = consumes != null ? consumes.value() : EMPTY_ARRAY; Produces produces = AnnotationHelper.findAnnotation(Produces.class, interfaze); String[] produceTypes = produces != null ? produces.value() : EMPTY_ARRAY; Resource.Builder resourceBuilder = Resource.builder(template.getPath()); for (ResourceMethod resourceMethod : template.getAllMethods()) { createMethod(resourceBuilder, resourceMethod, handler, consumeTypes, produceTypes); } for (Resource childTemplate : template.getChildResources()) { Resource.Builder childResourceBuilder = Resource.builder(childTemplate.getPath()); for (ResourceMethod resourceMethod : childTemplate.getAllMethods()) { createMethod(childResourceBuilder, resourceMethod, handler, consumeTypes, produceTypes); } resourceBuilder.addChildResource(childResourceBuilder.build()); } return resourceBuilder.build(); }
private void registerMetricsForModel(ResourceModel resourceModel) { for (final Resource resource : resourceModel.getResources()) { final Timed classLevelTimed = getClassLevelAnnotation(resource, Timed.class); final Metered classLevelMetered = getClassLevelAnnotation(resource, Metered.class); final ExceptionMetered classLevelExceptionMetered = getClassLevelAnnotation(resource, ExceptionMetered.class); final ResponseMetered classLevelResponseMetered = getClassLevelAnnotation(resource, ResponseMetered.class); for (final ResourceMethod method : resource.getAllMethods()) { registerTimedAnnotations(method, classLevelTimed); registerMeteredAnnotations(method, classLevelMetered); registerExceptionMeteredAnnotations(method, classLevelExceptionMetered); registerResponseMeteredAnnotations(method, classLevelResponseMetered); } for (final Resource childResource : resource.getChildResources()) { final Timed classLevelTimedChild = getClassLevelAnnotation(childResource, Timed.class); final Metered classLevelMeteredChild = getClassLevelAnnotation(childResource, Metered.class); final ExceptionMetered classLevelExceptionMeteredChild = getClassLevelAnnotation(childResource, ExceptionMetered.class); final ResponseMetered classLevelResponseMeteredChild = getClassLevelAnnotation(childResource, ResponseMetered.class); for (final ResourceMethod method : childResource.getAllMethods()) { registerTimedAnnotations(method, classLevelTimedChild); registerMeteredAnnotations(method, classLevelMeteredChild); registerExceptionMeteredAnnotations(method, classLevelExceptionMeteredChild); registerResponseMeteredAnnotations(method, classLevelResponseMeteredChild); } } } }
private void populate(String basePath, Class<?> klass, boolean isLocator, Resource resource, Set<EndpointLogLine> endpointLogLines) { if (!isLocator) { basePath = normalizePath(basePath, resource.getPath()); } for (ResourceMethod method : resource.getResourceMethods()) { endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), basePath, klass)); } for (Resource childResource : resource.getChildResources()) { for (ResourceMethod method : childResource.getAllMethods()) { if (method.getType() == ResourceMethod.JaxrsType.RESOURCE_METHOD) { final String path = normalizePath(basePath, childResource.getPath()); endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), path, klass)); } else if (method.getType() == ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR) { final String path = normalizePath(basePath, childResource.getPath()); final ResolvedType responseType = TYPE_RESOLVER .resolve(method.getInvocable().getResponseType()); final Class<?> erasedType = !responseType.getTypeBindings().isEmpty() ? responseType.getTypeBindings().getBoundType(0).getErasedType() : responseType.getErasedType(); if (Resource.from(erasedType) == null) { endpointLogLines.add(new EndpointLogLine(method.getHttpMethod(), path, erasedType)); } else { populate(path, erasedType, true, endpointLogLines); } } } } }