@Override public List<? extends ResourceModelComponent> getComponents() { return getChildRuntimeResources(); } }
@Override public int compare(RuntimeResource o1, RuntimeResource o2) { return PathPattern.COMPARATOR.compare(o1.getPathPattern(), o2.getPathPattern()); } };
private void checkMethods(RuntimeResource resource) { final List<ResourceMethod> resourceMethods = new ArrayList<>(resource.getResourceMethods()); resourceMethods.addAll(resource.getResourceLocators()); if (resourceMethods.size() >= 2) { for (ResourceMethod m1 : resourceMethods.subList(0, resourceMethods.size() - 1)) { for (ResourceMethod m2 : resourceMethods.subList(resourceMethods.indexOf(m1) + 1, resourceMethods.size())) { if (m1.getHttpMethod() == null && m2.getHttpMethod() == null) { Errors.error(this, LocalizationMessages.AMBIGUOUS_SRLS_PATH_PATTERN(resource.getFullPathRegex()), Severity.FATAL); } else if (m1.getHttpMethod() != null && m2.getHttpMethod() != null && sameHttpMethod(m1, m2)) { checkIntersectingMediaTypes(resource, m1.getHttpMethod(), m1, m2); } } } } }
private PushMatchedTemplateRouter getTemplateRouterForChildLocator(final boolean subResourceMode, final RuntimeResource child) { int i = 0; for (final Resource res : child.getResources()) { if (res.getResourceLocator() != null) { return getTemplateRouter(subResourceMode, child.getParentResources().get(i).getPathPattern().getTemplate(), res.getPathPattern().getTemplate()); } i++; } return null; }
private List<MethodRouting> createResourceMethodRouters( final RuntimeResource runtimeResource, final boolean subResourceMode) { final List<MethodRouting> methodRoutings = new ArrayList<>(); int i = 0; for (final Resource resource : runtimeResource.getResources()) { final Resource parentResource = runtimeResource.getParent() == null ? null : runtimeResource.getParentResources().get(i++); final UriTemplate template = resource.getPathPattern().getTemplate(); final PushMatchedTemplateRouter templateRouter = parentResource == null ? getTemplateRouter(subResourceMode, template, null) : getTemplateRouter(subResourceMode, parentResource.getPathPattern().getTemplate(), template); for (final ResourceMethod resourceMethod : resource.getResourceMethods()) { methodRoutings.add(new MethodRouting(resourceMethod, templateRouter, new PushMatchedMethodRouter(resourceMethod), createMethodRouter(resourceMethod))); } } return methodRoutings.isEmpty() ? Collections.emptyList() : methodRoutings; }
final Resource firstResource = resource.getResources().get(0); final Set<MediaType> produces = new HashSet<>(method.produces); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { for (final MediaType produce : method.produces) { if (ModelProcessorUtil.isMethodOverridden( final Resource parentResource = resource.getParentResources().get(0); if (parentResource != null && method.path != null) { continue; for (RuntimeResource child : resource.getChildRuntimeResources()) { enhanceResource(child, enhancedModelBuilder, methods, extended);
if (!resource.getResourceMethods().isEmpty()) { final List<MethodRouting> methodRoutings = createResourceMethodRouters(resource, subResourceMode); final Router methodSelectingRouter = new MethodSelectingRouter(messageBodyWorkers, methodRoutings); .to(methodSelectingRouter); } else { currentRouterBuilder = startNextRoute(currentRouterBuilder, PathPattern.asClosed(resource.getPathPattern())) .to(uriPushingRouter) .to(resourcePushingRouter) if (!resource.getChildRuntimeResources().isEmpty()) { for (final RuntimeResource childResource : resource.getChildRuntimeResources()) { final PathPattern childOpenPattern = childResource.getPathPattern(); final PathPattern childClosedPattern = PathPattern.asClosed(childOpenPattern); final PushMatchedRuntimeResourceRouter childResourcePushingRouter = if (!childResource.getResourceMethods().isEmpty()) { final List<MethodRouting> childMethodRoutings = createResourceMethodRouters(childResource, subResourceMode); if (childResource.getResourceLocator() != null) { final PushMatchedTemplateRouter locTemplateRouter = getTemplateRouterForChildLocator(subResourceMode, childResource); .to(locTemplateRouter) .to(childResourcePushingRouter) .to(new PushMatchedMethodRouter(childResource.getResourceLocator())) .to(createMethodRouter(childResource.getResourceLocator()));
private Resource getLocatorResource(final RuntimeResource resource) { for (final Resource res : resource.getResources()) { if (res.getResourceLocator() != null) { return res; } } return null; }
/** * Return allowed methods for the given {@code resource}. OPTIONS and HEAD are always returned in the result. * * @param resource Resource for which resource methods should be found. * @return Set of resource methods that can be invoked on the given resource. */ public static Set<String> getAllowedMethods(RuntimeResource resource) { boolean getFound = false; Set<String> allowedMethods = new HashSet<>(); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { final String httpMethod = resourceMethod.getHttpMethod(); allowedMethods.add(httpMethod); if (!getFound && httpMethod.equals(HttpMethod.GET)) { getFound = true; } } allowedMethods.add(HttpMethod.OPTIONS); if (getFound) { allowedMethods.add(HttpMethod.HEAD); } return allowedMethods; }
/** * Get full regular expression of this runtime resource prefixed by regular expression of parent if present. * * @return Full resource regular expression. */ public String getFullPathRegex() { if (parent == null) { return regex; } else { return parent.getRegex() + regex; } }
/** * Build new RuntimeResource from this builder. * * @param parent Parent runtime resource. * @return New RuntimeResource instance. */ public RuntimeResource build(RuntimeResource parent) { return new RuntimeResource(resources, childRuntimeResourceBuilders, parent, regex); } }
final Resource firstResource = resource.getResources().get(0); final Set<MediaType> produces = new HashSet<>(method.produces); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { for (final MediaType produce : method.produces) { if (ModelProcessorUtil.isMethodOverridden( final Resource parentResource = resource.getParentResources().get(0); if (parentResource != null && method.path != null) { continue; for (RuntimeResource child : resource.getChildRuntimeResources()) { enhanceResource(child, enhancedModelBuilder, methods, extended);
if (!resource.getResourceMethods().isEmpty()) { final List<MethodRouting> methodRoutings = createResourceMethodRouters(resource, subResourceMode); final Router methodSelectingRouter = new MethodSelectingRouter(messageBodyWorkers, methodRoutings); .to(methodSelectingRouter); } else { currentRouterBuilder = startNextRoute(currentRouterBuilder, PathPattern.asClosed(resource.getPathPattern())) .to(uriPushingRouter) .to(resourcePushingRouter) if (!resource.getChildRuntimeResources().isEmpty()) { for (final RuntimeResource childResource : resource.getChildRuntimeResources()) { final PathPattern childOpenPattern = childResource.getPathPattern(); final PathPattern childClosedPattern = PathPattern.asClosed(childOpenPattern); final PushMatchedRuntimeResourceRouter childResourcePushingRouter = if (!childResource.getResourceMethods().isEmpty()) { final List<MethodRouting> childMethodRoutings = createResourceMethodRouters(childResource, subResourceMode); if (childResource.getResourceLocator() != null) { final PushMatchedTemplateRouter locTemplateRouter = getTemplateRouterForChildLocator(subResourceMode, childResource); .to(locTemplateRouter) .to(childResourcePushingRouter) .to(new PushMatchedMethodRouter(childResource.getResourceLocator())) .to(createMethodRouter(childResource.getResourceLocator()));
private List<MethodRouting> createResourceMethodRouters( final RuntimeResource runtimeResource, final boolean subResourceMode) { final List<MethodRouting> methodRoutings = new ArrayList<>(); int i = 0; for (final Resource resource : runtimeResource.getResources()) { final Resource parentResource = runtimeResource.getParent() == null ? null : runtimeResource.getParentResources().get(i++); final UriTemplate template = resource.getPathPattern().getTemplate(); final PushMatchedTemplateRouter templateRouter = parentResource == null ? getTemplateRouter(subResourceMode, template, null) : getTemplateRouter(subResourceMode, parentResource.getPathPattern().getTemplate(), template); for (final ResourceMethod resourceMethod : resource.getResourceMethods()) { methodRoutings.add(new MethodRouting(resourceMethod, templateRouter, new PushMatchedMethodRouter(resourceMethod), createMethodRouter(resourceMethod))); } } return methodRoutings.isEmpty() ? Collections.emptyList() : methodRoutings; }
private PushMatchedTemplateRouter getTemplateRouterForChildLocator(final boolean subResourceMode, final RuntimeResource child) { int i = 0; for (final Resource res : child.getResources()) { if (res.getResourceLocator() != null) { return getTemplateRouter(subResourceMode, child.getParentResources().get(i).getPathPattern().getTemplate(), res.getPathPattern().getTemplate()); } i++; } return null; }
private Resource getLocatorResource(final RuntimeResource resource) { for (final Resource res : resource.getResources()) { if (res.getResourceLocator() != null) { return res; } } return null; }
/** * Return allowed methods for the given {@code resource}. OPTIONS and HEAD are always returned in the result. * * @param resource Resource for which resource methods should be found. * @return Set of resource methods that can be invoked on the given resource. */ public static Set<String> getAllowedMethods(RuntimeResource resource) { boolean getFound = false; Set<String> allowedMethods = new HashSet<>(); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { final String httpMethod = resourceMethod.getHttpMethod(); allowedMethods.add(httpMethod); if (!getFound && httpMethod.equals(HttpMethod.GET)) { getFound = true; } } allowedMethods.add(HttpMethod.OPTIONS); if (getFound) { allowedMethods.add(HttpMethod.HEAD); } return allowedMethods; }
/** * Get full regular expression of this runtime resource prefixed by regular expression of parent if present. * * @return Full resource regular expression. */ public String getFullPathRegex() { if (parent == null) { return regex; } else { return parent.getRegex() + regex; } }
/** * Build new RuntimeResource from this builder. * * @param parent Parent runtime resource. * @return New RuntimeResource instance. */ public RuntimeResource build(RuntimeResource parent) { return new RuntimeResource(resources, childRuntimeResourceBuilders, parent, regex); } }
final Resource firstResource = resource.getResources().get(0); final Set<MediaType> produces = new HashSet<>(method.produces); for (ResourceMethod resourceMethod : resource.getResourceMethods()) { for (final MediaType produce : method.produces) { if (ModelProcessorUtil.isMethodOverridden( final Resource parentResource = resource.getParentResources().get(0); if (parentResource != null && method.path != null) { continue; for (RuntimeResource child : resource.getChildRuntimeResources()) { enhanceResource(child, enhancedModelBuilder, methods, extended);