/** * Returns list of root resources. * * @return list of root resources. */ List<Resource> getRootResources() { List<Resource> rootResources = new ArrayList<Resource>(); for (Resource resource : models) { if (resource.getPath() != null) { rootResources.add(resource); } } return rootResources; } }
@Override public void pushMatchedRuntimeResource(final RuntimeResource runtimeResource) { if (tracingLogger.isLogEnabled(ServerTraceEvent.MATCH_RUNTIME_RESOURCE)) { tracingLogger.log(ServerTraceEvent.MATCH_RUNTIME_RESOURCE, runtimeResource.getResources().get(0).getPath(), runtimeResource.getResources().get(0).getPathPattern().getRegex(), matchResults.peek().group() .substring(0, matchResults.peek().group().length() - getFinalMatchingGroup().length()), matchResults.peek().group()); } this.matchedRuntimeResources.push(runtimeResource); }
/** * Returns list of root resources. * * @return list of root resources. */ List<Resource> getRootResources() { List<Resource> rootResources = new ArrayList<Resource>(); for (Resource resource : models) { if (resource.getPath() != null) { rootResources.add(resource); } } return rootResources; } }
@Override public void pushMatchedRuntimeResource(final RuntimeResource runtimeResource) { if (tracingLogger.isLogEnabled(ServerTraceEvent.MATCH_RUNTIME_RESOURCE)) { tracingLogger.log(ServerTraceEvent.MATCH_RUNTIME_RESOURCE, runtimeResource.getResources().get(0).getPath(), runtimeResource.getResources().get(0).getPathPattern().getRegex(), matchResults.peek().group() .substring(0, matchResults.peek().group().length() - getFinalMatchingGroup().length()), matchResults.peek().group()); } this.matchedRuntimeResources.push(runtimeResource); }
private void processResource(final Resource resource, final String pathPrefix) { final StringBuilder pathSB = new StringBuilder(pathPrefix); if (!pathPrefix.endsWith("/") && !resource.getPath().startsWith("/")) { pathSB.append("/"); } pathSB.append(resource.getPath()); uriStatistics.put(pathSB.toString(), new ResourceStatisticsImpl.Builder(resource, methodFactory)); for (final ResourceMethod resourceMethod : resource.getResourceMethods()) { getOrCreateResourceBuilder(resourceMethod).addMethod(resourceMethod); } }
private void processResource(final Resource resource, final String pathPrefix) { final StringBuilder pathSB = new StringBuilder(pathPrefix); if (!pathPrefix.endsWith("/") && !resource.getPath().startsWith("/")) { pathSB.append("/"); } pathSB.append(resource.getPath()); uriStatistics.put(pathSB.toString(), new ResourceStatisticsImpl.Builder(resource, methodFactory)); for (final ResourceMethod resourceMethod : resource.getResourceMethods()) { getOrCreateResourceBuilder(resourceMethod).addMethod(resourceMethod); } }
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()); }
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 List<EndpointLogLine> logResourceLines(Resource resource, String contextPath) { final List<EndpointLogLine> resourceLines = new ArrayList<>(); for (Resource child : resource.getChildResources()) { resourceLines.addAll(logResourceLines(child, cleanUpPath(contextPath + Strings.nullToEmpty(resource.getPath())))); } resourceLines.addAll(logMethodLines(resource, contextPath)); return resourceLines; }
@Override public Resource createResource(org.glassfish.jersey.server.model.Resource resource, String path) { Resource wadlResource = new Resource(); if (path != null) { wadlResource.setPath(path); } else if (resource.getPath() != null) { wadlResource.setPath(resource.getPath()); } if (resource.isExtended()) { wadlResource.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT); } return wadlResource; }
private void checkResource(final Resource resource) { if (!resource.getResourceMethods().isEmpty() && resource.getResourceLocator() != null) { Errors.warning(resource, LocalizationMessages.RESOURCE_CONTAINS_RES_METHODS_AND_LOCATOR(resource, resource.getPath())); } if (resource.getPath() != null && resource.getResourceMethods().isEmpty() && resource.getChildResources().isEmpty() && resource.getResourceLocator() == null) { Errors.warning(resource, LocalizationMessages.RESOURCE_EMPTY(resource, resource.getPath())); } }
private void checkResource(final Resource resource) { if (!resource.getResourceMethods().isEmpty() && resource.getResourceLocator() != null) { Errors.warning(resource, LocalizationMessages.RESOURCE_CONTAINS_RES_METHODS_AND_LOCATOR(resource, resource.getPath())); } if (resource.getPath() != null && resource.getResourceMethods().isEmpty() && resource.getChildResources().isEmpty() && resource.getResourceLocator() == null) { Errors.warning(resource, LocalizationMessages.RESOURCE_EMPTY(resource, resource.getPath())); } }
@Override public Resource createResource(org.glassfish.jersey.server.model.Resource resource, String path) { Resource wadlResource = new Resource(); if (path != null) { wadlResource.setPath(path); } else if (resource.getPath() != null) { wadlResource.setPath(resource.getPath()); } if (resource.isExtended()) { wadlResource.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT); } return wadlResource; }
@Override protected Inflector<ContractProvider.Builder, ContractProvider> getModelEnhancer(final Class<?> componentClass) { return builder -> { if (builder.getScope() == null && builder.getContracts().isEmpty() && Resource.getPath(componentClass) != null) { builder.scope(RequestScoped.class); } return builder.build(); }; }
@Override protected Inflector<ContractProvider.Builder, ContractProvider> getModelEnhancer(final Class<?> componentClass) { return builder -> { if (builder.getScope() == null && builder.getContracts().isEmpty() && Resource.getPath(componentClass) != null) { builder.scope(RequestScoped.class); } return builder.build(); }; }
/** * Create a new builder and initialize it from resource model. * * @param resourceModel resource model. */ Builder(final ResourceModel resourceModel) { this(); for (final Resource resource : resourceModel.getRootResources()) { processResource(resource, ""); for (final Resource child : resource.getChildResources()) { final String path = resource.getPath(); processResource(child, path.startsWith("/") ? path : "/" + path); } } }
/** * Create a new builder and initialize it from resource model. * * @param resourceModel resource model. */ Builder(final ResourceModel resourceModel) { this(); for (final Resource resource : resourceModel.getRootResources()) { processResource(resource, ""); for (final Resource child : resource.getChildResources()) { final String path = resource.getPath(); processResource(child, path.startsWith("/") ? path : "/" + path); } } }