use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SynchronousDispatcher method getInvoker.
public ResourceInvoker getInvoker(HttpRequest request) throws Failure {
LogMessages.LOGGER.pathInfo(request.getUri().getPath());
if (!request.isInitial()) {
throw new InternalServerErrorException(Messages.MESSAGES.isNotInitialRequest(request.getUri().getPath()));
}
ResourceInvoker invoker = registry.getResourceInvoker(request);
if (invoker == null) {
throw new NotFoundException(Messages.MESSAGES.unableToFindJaxRsResource(request.getUri().getPath()));
}
RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
logger.log("MATCH_RESOURCE", invoker);
logger.log("MATCH_RESOURCE_METHOD", invoker.getMethod());
return invoker;
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class AbstractPatchMethodFilter method getMethodInvoker.
protected ResourceMethodInvoker getMethodInvoker(ContainerRequestContext requestContext) {
HttpRequest request = ResteasyContext.getContextData(HttpRequest.class);
Registry methodRegistry = ResteasyContext.getContextData(Registry.class);
ResourceInvoker resourceInovker = null;
try {
resourceInovker = methodRegistry.getResourceInvoker(request);
} catch (Exception e) {
LogMessages.LOGGER.patchTargetMethodNotFound(requestContext.getUriInfo().getRequestUri().toString());
throw new ProcessingException("GET method returns the patch/merge json object target not found");
}
return (ResourceMethodInvoker) resourceInovker;
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class RootNode method removeBinding.
public void removeBinding(String path, Method method) {
List<MethodExpression> expressions = bounded.get(path);
if (expressions == null)
return;
for (MethodExpression expression : expressions) {
ResourceInvoker invoker = expression.getInvoker();
if (invoker.getMethod().equals(method)) {
expression.parent.targets.remove(expression);
expressions.remove(expression);
if (expressions.size() == 0)
bounded.remove(path);
size--;
if (invoker instanceof ResourceMethodInvoker) {
((ResourceMethodInvoker) invoker).cleanup();
}
return;
}
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SegmentNode method match.
public MatchCache match(HttpRequest request, int start) {
String path = ((ResteasyUriInfo) request.getUri()).getMatchingPath();
RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
logger.log("MATCH_PATH_FIND", ((ResteasyUriInfo) request.getUri()).getMatchingPath());
if (start < path.length() && path.charAt(start) == '/')
start++;
List<MethodExpression> potentials = new ArrayList<MethodExpression>();
potentials(path, start, potentials);
Collections.sort(potentials);
boolean expressionMatched = false;
List<Match> matches = new ArrayList<Match>();
for (MethodExpression expression : potentials) {
// We ignore locators if the first match was a resource method as per the spec Section 3, Step 2(h)
if (expressionMatched && expression.isLocator()) {
logger.log("MATCH_PATH_SKIPPED", expression.getRegex());
continue;
}
Pattern pattern = expression.getPattern();
Matcher matcher = pattern.matcher(path);
matcher.region(start, path.length());
if (matcher.matches()) {
expressionMatched = true;
ResourceInvoker invoker = expression.getInvoker();
if (invoker instanceof ResourceLocatorInvoker) {
MatchCache ctx = new MatchCache();
ctx.invoker = invoker;
ResteasyUriInfo uriInfo = (ResteasyUriInfo) request.getUri();
int length = matcher.start(expression.getNumGroups() + 1);
if (length == -1) {
uriInfo.pushMatchedPath(path);
uriInfo.pushMatchedURI(path);
} else {
// must find the end of the matched pattern
// and get the substring from 1st char thru end
// of matched chars
Pattern p = expression.getPattern();
Matcher m = p.matcher(path);
m.region(start, path.length());
String substring = path;
while (m.find()) {
String endText = m.group(m.groupCount());
if (endText != null && !endText.isEmpty()) {
int indx = path.indexOf(endText, length);
if (indx > -1) {
substring = path.substring(0, indx);
}
}
}
uriInfo.pushMatchedPath(substring);
uriInfo.pushMatchedURI(substring);
}
expression.populatePathParams(request, matcher, path);
logger.log("MATCH_LOCATOR", invoker.getMethod());
return ctx;
} else {
matches.add(new Match(expression, matcher));
}
} else {
logger.log("MATCH_PATH_NOT_MATCHED", expression.getRegex());
}
}
if (matches.size() == 0) {
throw new NotFoundException(Messages.MESSAGES.couldNotFindResourceForFullPath(request.getUri().getRequestUri()));
}
MatchCache match = match(matches, request.getHttpMethod(), request);
match.match.expression.populatePathParams(request, match.match.matcher, path);
logger.log("MATCH_PATH_SELECTED", match.match.expression.getRegex());
return match;
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class ResourceMethodRegistry method checkAmbiguousUri.
/**
* Resteasy 2.x does not properly handle sub-resource and sub-resource locator
* endpoints with the same uri. Resteasy 3.x does handle this properly. In
* assisting customers identify this issue during an upgrade from Resteasy 2 to 3
* provides a waring when the situation is found.
*/
public void checkAmbiguousUri() {
for (Map.Entry<String, List<ResourceInvoker>> entry : this.root.getBounded().entrySet()) {
List<ResourceInvoker> values = entry.getValue();
if (values.size() > 1) {
int locatorCnt = 0;
int methodCnt = 0;
for (ResourceInvoker rInvoker : values) {
if (rInvoker instanceof ResourceLocatorInvoker) {
locatorCnt++;
} else if (rInvoker instanceof ResourceMethodInvoker) {
methodCnt++;
}
}
if (methodCnt > 0 && locatorCnt > 0) {
StringBuilder sb = new StringBuilder();
int cnt = values.size();
for (int i = 0; i < cnt; i++) {
ResourceInvoker exp = values.get(i);
sb.append(exp.getMethod().getDeclaringClass().getName()).append(".").append(exp.getMethod().getName());
if (i < cnt - 1) {
sb.append(", ");
}
}
LogMessages.LOGGER.uriAmbiguity(entry.getKey(), sb.toString());
}
}
}
}
Aggregations