use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class ServiceMethodsRegistry method getMethods.
public List<Method> getMethods() {
List<Method> results = new LinkedList<>();
for (Map.Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
List<ResourceInvoker> invokers = entry.getValue();
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker resourceMethod = (ResourceMethodInvoker) invoker;
Method method = resourceMethod.getMethod();
results.add(method);
} else {
// TODO: fix this?
}
}
}
return results;
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class ServiceRegistry method scanRegistry.
private void scanRegistry() throws Exception {
methods = new ArrayList<MethodMetaData>();
locators = new ArrayList<ServiceRegistry>();
for (Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
List<ResourceInvoker> invokers = entry.getValue();
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
methods.add(new MethodMetaData(this, (ResourceMethodInvoker) invoker));
} else if (invoker instanceof ResourceLocatorInvoker) {
ResourceLocatorInvoker locator = (ResourceLocatorInvoker) invoker;
Method method = locator.getMethod();
Class<?> locatorType = method.getReturnType();
Class<?>[] locatorResourceTypes = GetRestful.getSubResourceClasses(locatorType);
for (Class<?> locatorResourceType : locatorResourceTypes) {
if (locatorResourceType == null) {
// just logging this
if (LogMessages.LOGGER.isEnabled(Level.WARN))
LogMessages.LOGGER.warn(Messages.MESSAGES.impossibleToGenerateJsapi(method.getDeclaringClass().getName(), method.getName()));
// skip this
continue;
}
ResourceMethodRegistry locatorRegistry = new ResourceMethodRegistry(providerFactory);
locatorRegistry.addResourceFactory(null, null, locatorResourceType);
locators.add(new ServiceRegistry(this, locatorRegistry, providerFactory, locator));
}
}
}
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SegmentTest method testDefaultOptions.
/**
* @tpTestDetails Check default option for segment
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testDefaultOptions() throws URISyntaxException {
ResourceMethodRegistry registry = new ResourceMethodRegistry(ResteasyProviderFactory.getInstance());
registry.addPerRequestResource(SegmentResource.class);
try {
ResourceInvoker invoker = registry.getResourceInvoker(MockHttpRequest.options("/resource/sub"));
} catch (DefaultOptionsMethodException e) {
}
try {
ResourceInvoker invoker = registry.getResourceInvoker(MockHttpRequest.put("/resource/sub"));
} catch (NotAllowedException e) {
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class ResteasyWadlServiceRegistry method scanRegistry.
private void scanRegistry() {
resources = new HashMap<>();
locators = new ArrayList<>();
for (Map.Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
List<ResourceInvoker> invokers = entry.getValue();
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
ResteasyWadlMethodMetaData methodMetaData = new ResteasyWadlMethodMetaData(this, (ResourceMethodInvoker) invoker);
ResteasyWadlResourceMetaData resourceMetaData = resources.get(methodMetaData.getKlassUri());
if (resourceMetaData == null) {
resourceMetaData = new ResteasyWadlResourceMetaData(methodMetaData.getKlassUri());
resources.put(methodMetaData.getKlassUri(), resourceMetaData);
}
resourceMetaData.addMethodMetaData(methodMetaData);
} else if (invoker instanceof ResourceLocator) {
ResourceLocator locator = (ResourceLocator) invoker;
Method method = locator.getMethod();
Class<?> locatorType = method.getReturnType();
Class<?>[] locatorResourceTypes = GetRestful.getSubResourceClasses(locatorType);
for (Class<?> locatorResourceType : locatorResourceTypes) {
if (locatorResourceType == null) {
// FIXME: we could generate an error for the client, which would be more informative than
// just logging this
// skip this
LogMessages.LOGGER.warn(Messages.MESSAGES.impossibleToGenerateWADL(method.getDeclaringClass().getName(), method.getName()));
continue;
}
ResourceMethodRegistry locatorRegistry = new ResourceMethodRegistry(providerFactory);
locatorRegistry.addResourceFactory(null, null, locatorResourceType);
locators.add(new ResteasyWadlServiceRegistry(this, locatorRegistry, providerFactory, locator));
}
}
}
}
}
use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.
the class SynchronousDispatcher method invoke.
/**
* Invoke and write response.
*
* @param request http request
* @param response http response
* @param invoker resource invoker
*/
public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) {
RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
Response jaxrsResponse = null;
try {
request.getAsyncContext().initialRequestStarted();
jaxrsResponse = invoker.invoke(request, response);
request.getAsyncContext().initialRequestEnded();
tracingLogger.log("DISPATCH_RESPONSE", jaxrsResponse);
if (request.getAsyncContext().isSuspended()) {
/**
* Callback by the initial calling thread. This callback will probably do nothing in an asynchronous environment
* but will be used to simulate AsynchronousResponse in vanilla Servlet containers that do not support
* asychronous HTTP.
*/
request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
// we're handing response asynchronously
jaxrsResponse = null;
}
} catch (CompletionException e) {
// logger.error("invoke() failed mapping exception", e);
writeException(request, response, e.getCause(), t -> {
});
return;
} catch (Exception e) {
// logger.error("invoke() failed mapping exception", e);
invoker.getMethodStatisticsLogger().incFailureCnt();
writeException(request, response, e, t -> {
});
return;
}
if (jaxrsResponse != null) {
writeResponse(request, response, jaxrsResponse);
}
}
Aggregations