private void removeRegistration(ResourceMethodRegistry rm, String path, Method method) { try { if (rm.isWiderMatching()) { RootNode rootNode = get(rm, "rootNode"); rootNode.removeBinding(path, method); } else { String methodpath = method.getAnnotation(Path.class).value(); String classExpression = path.replace(methodpath, ""); if (classExpression.endsWith("/")) { classExpression.substring(0, classExpression.length() - 1); } RootClassNode root = get(rm, "root"); root.removeBinding(classExpression, path, method); } } catch (Exception e) { LOGGER.error("Could not remove method registration from path {}, {}", e, path, method); } }
public Map<String, List<ResourceInvoker>> getBounded() { if (widerMatching) return rootNode.getBounded(); else return root.getBounded(); }
public void removeBinding(String classExpression, String path, Method method) { if (classExpression.startsWith("/")) classExpression = classExpression.substring(1); if (classExpression.endsWith("/")) classExpression = classExpression.substring(0, classExpression.length() - 1); String regex = new ClassExpression(classExpression).getRegex(); ClassExpression ce = bounded.get(regex); if (ce == null) return; ce.getRoot().removeBinding(path, method); if (ce.getRoot().getSize() == 0) { ce.getParent().targets.remove(ce); bounded.remove(regex); } }
public void addInvoker(String classExpression, String fullpath, ResourceInvoker invoker) { if (classExpression.startsWith("/")) classExpression = classExpression.substring(1); if (classExpression.endsWith("/")) classExpression = classExpression.substring(0, classExpression.length() - 1); ClassExpression newce = new ClassExpression(classExpression); String regex = newce.getRegex(); ClassExpression existing = bounded.get(regex); if (existing == null) { newce.getRoot().addInvoker(fullpath, invoker); addExpression(classExpression, newce); bounded.put(regex, newce); } else { existing.getRoot().addInvoker(fullpath, invoker); } } protected void addExpression(String path, ClassExpression ce)
rootNode.addInvoker(fullpath, invoker); } else { root.addInvoker(classExpression, fullpath, invoker); rootNode.addInvoker(fullpath, locator); } else { root.addInvoker(classExpression, fullpath, locator);
@Override public int compareTo(SortEntry o) { if (consumes.isWildcardType() && !o.consumes.isWildcardType()) return 1; if (!consumes.isWildcardType() && o.consumes.isWildcardType()) return -1; if (consumes.isWildcardSubtype() && !o.consumes.isWildcardSubtype()) return 1; if (!consumes.isWildcardSubtype() && o.consumes.isWildcardSubtype()) return -1; if (consumes.q > o.consumes.q) return -1; if (consumes.q < o.consumes.q) return 1; if (consumes.qs > o.consumes.qs) return -1; if (consumes.qs < o.consumes.qs) return 1; if (consumes.d < o.consumes.d) return -1; if (consumes.d > o.consumes.d) return 1; if (consumes.dm < o.consumes.dm) return -1; if (consumes.dm > o.consumes.dm) return 1; if (produces.isWildcardType() && !o.produces.isWildcardType()) return 1; if (!produces.isWildcardType() && o.produces.isWildcardType()) return -1; if (produces.isWildcardSubtype() && !o.produces.isWildcardSubtype()) return 1; if (!produces.isWildcardSubtype() && o.produces.isWildcardSubtype()) return -1; if (produces.q > o.produces.q) return -1; if (produces.q < o.produces.q) return 1; if (produces.qs > o.produces.qs) return -1; if (produces.qs < o.produces.qs) return 1; if (produces.d < o.produces.d) return -1; if (produces.d > o.produces.d) return 1; if (produces.dm < o.produces.dm) return -1; if (produces.dm > o.produces.dm) return 1; return match.expression.compareTo(o.match.expression); } }
public void potentials(String path, int start, List<MethodExpression> matches) { if (start == path.length()) // we've reached end of string { matches.addAll(targets); return; } if (start < path.length()) { String simpleSegment = null; int endOfSegmentIndex = path.indexOf('/', start); if (endOfSegmentIndex > -1) simpleSegment = path.substring(start, endOfSegmentIndex); else simpleSegment = path.substring(start); SegmentNode child = children.get(simpleSegment); if (child != null) { int next = start + simpleSegment.length(); if (endOfSegmentIndex > -1) next++; // go past '/' child.potentials(path, next, matches); } } for (MethodExpression exp : targets) { // skip any static matches as they will not match anyways if (exp.getNumGroups() > 0 || exp.getInvoker() instanceof ResourceLocatorInvoker) { matches.add(exp); } } }
public Map<String, List<ResourceInvoker>> getBounded() { MultivaluedMap<String, ResourceInvoker> invokers = new MultivaluedHashMap<String, ResourceInvoker>(); for (ClassExpression exp : bounded.values()) { MultivaluedMap<String, ResourceInvoker> expBounded = exp.getRoot().getBounded(); for (MultivaluedMap.Entry<String, List<ResourceInvoker>> entry : expBounded.entrySet()) { invokers.addAll(entry.getKey(), entry.getValue()); } } return invokers; }
/** * Find a resource to invoke on. * * @return resource invoker */ public ResourceInvoker getResourceInvoker(HttpRequest request) { RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request); final long timestamp = tracingLogger.timestamp("MATCH_SUMMARY"); try { if (widerMatching) { return rootNode.match(request, 0); } else { return root.match(request, 0); } } catch (RuntimeException e) { throw e; } finally { tracingLogger.logDuration("MATCH_SUMMARY", timestamp); } } }
public ResourceInvoker match(HttpRequest request, int start) { return root.match(request, start); }
public void addInvoker(String path, ResourceInvoker invoker) { MethodExpression expression = addExpression(path, invoker); size++; bounded.add(path, expression); } protected MethodExpression addExpression(String path, ResourceInvoker invoker)
public int compareTo(Expression expression) { int s = super.compareTo(expression); if (s != 0) return s; MethodExpression me = (MethodExpression)expression; if (invoker.getClass().equals(me.invoker.getClass())) return 0; if (invoker instanceof ResourceMethodInvoker) return -1; else return 1; }
public MultivaluedMap<String, ResourceInvoker> getBounded() { MultivaluedHashMap<String, ResourceInvoker> rtn = new MultivaluedHashMap<String, ResourceInvoker>(); for (Map.Entry<String, List<MethodExpression>> entry : bounded.entrySet()) { for (MethodExpression exp : entry.getValue()) { rtn.add(entry.getKey(), exp.getInvoker()); } } return rtn; }
public ResourceInvoker getResourceInvoker(HttpRequest request) { try { String currentUri = ((ResteasyUriInfo)request.getUri()).getEncodedMatchedPaths().get(0); int startAt = currentUri.length(); return root.match(request, startAt); } catch (RuntimeException e) { throw e; } } }
rootNode.addInvoker(fullpath, invoker); } else { root.addInvoker(classExpression, fullpath, invoker); rootNode.addInvoker(fullpath, locator); } else { root.addInvoker(classExpression, fullpath, locator);
@Override public void removeRegistrations(ResourceClass resourceClass) { for (ResourceMethod method : resourceClass.getResourceMethods()) { if (widerMatching) rootNode.removeBinding(method.getFullpath(), method.getMethod()); else root.removeBinding(resourceClass.getPath(), method.getFullpath(), method.getMethod()); } for (ResourceLocator method : resourceClass.getResourceLocators()) { if (widerMatching) rootNode.removeBinding(method.getFullpath(), method.getMethod()); else root.removeBinding(resourceClass.getPath(), method.getFullpath(), method.getMethod()); } }
private void removeRegistration(String base, Class<?> clazz) { for (Method method : clazz.getMethods()) { Path path = method.getAnnotation(Path.class); Set<String> httpMethods = IsHttpMethod.getHttpMethods(method); if (path == null && httpMethods == null) continue; ResteasyUriBuilder builder = new ResteasyUriBuilderImpl(); if (base != null) builder.path(base); if (clazz.isAnnotationPresent(Path.class)) builder.path(clazz); String classExpression = builder.getPath(); if (path != null) builder.path(method); String fullpath = builder.getPath(); if (fullpath == null) fullpath = ""; if (widerMatching) rootNode.removeBinding(fullpath, method); else root.removeBinding(classExpression, fullpath, method); } }