Search in sources :

Example 1 with ResourceMethodRegistry

use of org.jboss.resteasy.core.ResourceMethodRegistry in project openremote by openremote.

the class JSAPIServlet method scanResources.

@SuppressWarnings("unchecked")
public void scanResources() throws Exception {
    ServletConfig config = getServletConfig();
    ServletContext servletContext = config.getServletContext();
    Map<String, ResteasyDeployment> deployments = (Map<String, ResteasyDeployment>) servletContext.getAttribute(ResteasyContextParameters.RESTEASY_DEPLOYMENTS);
    if (deployments == null)
        return;
    synchronized (this) {
        services = new HashMap<String, ServiceRegistry>();
        for (Map.Entry<String, ResteasyDeployment> entry : deployments.entrySet()) {
            ResourceMethodRegistry registry = (ResourceMethodRegistry) entry.getValue().getRegistry();
            ResteasyProviderFactory providerFactory = entry.getValue().getProviderFactory();
            ServiceRegistry service = new ServiceRegistry(null, registry, providerFactory, null);
            services.put(entry.getKey(), service);
        }
    }
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ResourceMethodRegistry

use of org.jboss.resteasy.core.ResourceMethodRegistry in project openremote by openremote.

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) {
                        // FIXME: we could generate an error for the client, which would be more informative than
                        // just logging this
                        LOG.warning("Error generating JS API: " + 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));
                }
            }
        }
    }
}
Also used : ResourceLocatorInvoker(org.jboss.resteasy.core.ResourceLocatorInvoker) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) Method(java.lang.reflect.Method) ResourceInvoker(org.jboss.resteasy.core.ResourceInvoker) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ResourceMethodRegistry (org.jboss.resteasy.core.ResourceMethodRegistry)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ServletConfig (javax.servlet.ServletConfig)1 ServletContext (javax.servlet.ServletContext)1 ResourceInvoker (org.jboss.resteasy.core.ResourceInvoker)1 ResourceLocatorInvoker (org.jboss.resteasy.core.ResourceLocatorInvoker)1 ResourceMethodInvoker (org.jboss.resteasy.core.ResourceMethodInvoker)1 ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1