@Override public String getHttpMethod() { return resourceMethod.getHttpMethod(); }
@Override public String getHttpMethod() { return resourceMethod.getHttpMethod(); }
private boolean sameHttpMethod(ResourceMethod m1, ResourceMethod m2) { return m1.getHttpMethod().equals(m2.getHttpMethod()); } }
private boolean sameHttpMethod(ResourceMethod m1, ResourceMethod m2) { return m1.getHttpMethod().equals(m2.getHttpMethod()); } }
/** * 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; }
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); } } } } }
/** * 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; }
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 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()); } }
LOG.warn("REST endpoint not included in audit trail: {}", String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource))); LOG.debug("Missing @AuditEvent or @NoAuditEvent annotation: {}#{}", m.getDeclaringClass().getCanonicalName(), m.getName()); } else { String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource)), annotation.type()); LOG.debug("Make sure the audit event types are registered in a class that implements PluginAuditEventTypes: {}#{}", m.getDeclaringClass().getCanonicalName(), m.getName()); String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource)));
final String httpMethod = methodRouting.method.getHttpMethod(); httpMethods.add(httpMethod);
private static boolean isMethodOverridden(ResourceMethod resourceMethod, String httpMethod, MediaType consumes, MediaType produces) { if (!resourceMethod.getHttpMethod().equals(httpMethod)) { return false; } final boolean consumesMatch = overrides(resourceMethod.getConsumedTypes(), consumes); final boolean producesMatch = overrides(resourceMethod.getProducedTypes(), produces); return consumesMatch && producesMatch; }
private static boolean isMethodOverridden(ResourceMethod resourceMethod, String httpMethod, MediaType consumes, MediaType produces) { if (!resourceMethod.getHttpMethod().equals(httpMethod)) { return false; } final boolean consumesMatch = overrides(resourceMethod.getConsumedTypes(), consumes); final boolean producesMatch = overrides(resourceMethod.getProducedTypes(), produces); return consumesMatch && producesMatch; }
@Override public com.sun.research.ws.wadl.Method createMethod( org.glassfish.jersey.server.model.Resource r, final ResourceMethod m) { com.sun.research.ws.wadl.Method wadlMethod = new com.sun.research.ws.wadl.Method(); wadlMethod.setName(m.getHttpMethod()); wadlMethod.setId(m.getInvocable().getDefinitionMethod().getName()); if (m.isExtended()) { wadlMethod.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT); } return wadlMethod; }
@Override public com.sun.research.ws.wadl.Method createMethod( org.glassfish.jersey.server.model.Resource r, final ResourceMethod m) { com.sun.research.ws.wadl.Method wadlMethod = new com.sun.research.ws.wadl.Method(); wadlMethod.setName(m.getHttpMethod()); wadlMethod.setId(m.getInvocable().getDefinitionMethod().getName()); if (m.isExtended()) { wadlMethod.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT); } return wadlMethod; }
/** * Get the method unique string ID. The ID is constructed from method attributes separated * by pipe '|'. The attributes are used in the following order: * method-produces|method-consumes|http-method|method-path|method-java-name * <p> * If any of the attributes is not defined, "null" is used for such an attribute. * <p/> * * @param method Resource method. * @return String constructed from resource method parameters. */ public static String getMethodUniqueId(final ResourceMethod method) { final String path = method.getParent() != null ? createPath(method.getParent()) : "null"; return method.getProducedTypes().toString() + "|" + method.getConsumedTypes().toString() + "|" + method.getHttpMethod() + "|" + path + "|" + method.getInvocable().getHandlingMethod().getName(); }
/** * Get the method unique string ID. The ID is constructed from method attributes separated * by pipe '|'. The attributes are used in the following order: * method-produces|method-consumes|http-method|method-path|method-java-name * <p> * If any of the attributes is not defined, "null" is used for such an attribute. * <p/> * * @param method Resource method. * @return String constructed from resource method parameters. */ public static String getMethodUniqueId(final ResourceMethod method) { final String path = method.getParent() != null ? createPath(method.getParent()) : "null"; return method.getProducedTypes().toString() + "|" + method.getConsumedTypes().toString() + "|" + method.getHttpMethod() + "|" + path + "|" + method.getInvocable().getHandlingMethod().getName(); }
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; switch (method.getType()) { case RESOURCE_METHOD: methodLines.add(new EndpointLogLine(method.getHttpMethod(), path, handler)); break; case SUB_RESOURCE_LOCATOR: methodLines.add(new EndpointLogLine(method.getHttpMethod(), path, handler)); } else { methodLines.addAll(logResourceLines(res, path));
/** * 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); } }
/** * 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); } }