use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SynchronousDispatcher method invoke.
public void invoke(HttpRequest request, HttpResponse response) {
RESTEasyTracingLogger.initTracingSupport(providerFactory, request);
RESTEasyTracingLogger.logStart(request);
try {
pushContextObjects(request, response);
preprocess(request, response, () -> {
ResourceInvoker invoker = null;
try {
try {
invoker = getInvoker(request);
} catch (Exception exception) {
// logger.error("getInvoker() failed mapping exception", exception);
writeException(request, response, exception, t -> {
});
return;
}
invoke(request, response, invoker);
} finally {
// we're probably clearing it twice but still required
clearContextData();
}
});
} finally {
clearContextData();
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SynchronousDispatcher method internalInvocation.
public Response internalInvocation(HttpRequest request, HttpResponse response, Object entity) {
// be extra careful in the clean up process. Only pop if there was an
// equivalent push.
ResteasyContext.addContextDataLevel();
boolean pushedBody = false;
try {
MessageBodyParameterInjector.pushBody(entity);
pushedBody = true;
ResourceInvoker invoker = getInvoker(request);
if (invoker != null) {
pushContextObjects(request, response);
return execute(request, response, invoker);
}
// if invoker is null
return null;
} finally {
ResteasyContext.removeContextDataLevel();
if (pushedBody) {
MessageBodyParameterInjector.popBody();
}
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SynchronousDispatcher method invokePropagateNotFound.
/**
* Propagate NotFoundException. This is used for Filters.
*
* @param request http request
* @param response http response
*/
public void invokePropagateNotFound(HttpRequest request, HttpResponse response) throws NotFoundException {
try {
pushContextObjects(request, response);
preprocess(request, response, () -> {
ResourceInvoker invoker = null;
try {
try {
invoker = getInvoker(request);
} catch (Exception failure) {
if (failure instanceof NotFoundException) {
throw ((NotFoundException) failure);
} else {
// logger.error("getInvoker() failed mapping exception", failure);
writeException(request, response, failure, t -> {
});
return;
}
}
invoke(request, response, invoker);
} finally {
// we're probably clearing it twice but still required
clearContextData();
}
});
} finally {
clearContextData();
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class ResourceLocatorInvoker method invokeOnTargetObject.
protected BuiltResponse invokeOnTargetObject(HttpRequest request, HttpResponse response, Object target) {
if (target == null) {
NotFoundException notFound = new NotFoundException(Messages.MESSAGES.nullSubresource(request.getUri().getAbsolutePath()));
throw notFound;
}
Class<? extends Object> clazz = target.getClass();
LocatorRegistry registry = cachedSubresources.get(clazz);
if (registry == null) {
if (!GetRestful.isSubResourceClass(clazz)) {
String msg = Messages.MESSAGES.subresourceHasNoJaxRsAnnotations(clazz.getName());
throw new InternalServerErrorException(msg);
}
registry = new LocatorRegistry(clazz, providerFactory);
cachedSubresources.putIfAbsent(clazz, registry);
}
ResourceInvoker invoker = registry.getResourceInvoker(request);
if (invoker instanceof ResourceLocatorInvoker) {
ResourceLocatorInvoker locator = (ResourceLocatorInvoker) invoker;
final long timeStamp = methodStatisticsLogger.timestamp();
try {
return locator.invoke(request, response, target);
} finally {
methodStatisticsLogger.duration(timeStamp);
}
} else {
ResourceMethodInvoker method = (ResourceMethodInvoker) invoker;
return method.invoke(request, response, target);
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class RegistryStatsResource method get.
@GET
@Produces({ "application/xml", "application/json" })
public RegistryData get() throws JAXBException {
ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyContext.getContextData(Registry.class);
RegistryData data = new RegistryData();
for (String key : registry.getBounded().keySet()) {
List<ResourceInvoker> invokers = registry.getBounded().get(key);
RegistryEntry entry = new RegistryEntry();
data.getEntries().add(entry);
entry.setUriTemplate(key);
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker rm = (ResourceMethodInvoker) invoker;
for (String httpMethod : rm.getHttpMethods()) {
ResourceMethodEntry method = null;
if (httpMethod.equals("GET"))
method = new GetResourceMethod();
else if (httpMethod.equals("PUT"))
method = new PutResourceMethod();
else if (httpMethod.equals("DELETE"))
method = new DeleteResourceMethod();
else if (httpMethod.equals("POST"))
method = new PostResourceMethod();
else if (httpMethod.equals("OPTIONS"))
method = new OptionsResourceMethod();
else if (httpMethod.equals("TRACE"))
method = new TraceResourceMethod();
else if (httpMethod.equals("HEAD"))
method = new HeadResourceMethod();
method.setClazz(rm.getResourceClass().getName());
method.setMethod(rm.getMethod().getName());
AtomicLong stat = rm.getStats().get(httpMethod);
if (stat != null)
method.setInvocations(stat.longValue());
else
method.setInvocations(0);
if (rm.getProduces() != null) {
for (MediaType mediaType : rm.getProduces()) {
method.getProduces().add(mediaType.toString());
}
}
if (rm.getConsumes() != null) {
for (MediaType mediaType : rm.getConsumes()) {
method.getConsumes().add(mediaType.toString());
}
}
entry.getMethods().add(method);
}
} else {
ResourceLocatorInvoker rl = (ResourceLocatorInvoker) invoker;
SubresourceLocator locator = new SubresourceLocator();
locator.setClazz(rl.getMethod().getDeclaringClass().getName());
locator.setMethod(rl.getMethod().getName());
entry.setLocator(locator);
}
}
}
return data;
}
Aggregations