Search in sources :

Example 1 with ResourceLocator

use of org.jboss.resteasy.spi.metadata.ResourceLocator in project openremote by openremote.

the class MethodMetaData method getResourceLocator.

public static ResourceLocator getResourceLocator(ResourceInvoker invoker) throws Exception {
    Field resourceMethodField = null;
    resourceMethodField = invoker.getClass().getDeclaredField("method");
    resourceMethodField.setAccessible(true);
    return (ResourceLocator) resourceMethodField.get(invoker);
}
Also used : Field(java.lang.reflect.Field) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Example 2 with ResourceLocator

use of org.jboss.resteasy.spi.metadata.ResourceLocator in project candlepin by candlepin.

the class VerifyAuthorizationFilter method getArguments.

protected Map<Verify, Object> getArguments(HttpRequest request, Method method) {
    ResteasyProviderFactory resourceFactory = ResteasyProviderFactory.getInstance();
    InjectorFactory injectorFactory = resourceFactory.getInjectorFactory();
    ResourceLocator locator = locatorMap.get(method);
    if (null == locator) {
        throw new IseException("Method " + method.getName() + " not registered as RESTful.");
    }
    MethodInjector methodInjector = injectorFactory.createMethodInjector(locator, resourceFactory);
    HttpResponse response = ResteasyProviderFactory.popContextData(HttpResponse.class);
    Object[] args = methodInjector.injectArguments(request, response);
    // LinkedHashMap preserves insertion order
    Map<Verify, Object> argMap = new LinkedHashMap<>();
    Annotation[][] allAnnotations = method.getParameterAnnotations();
    // Any occurrence of the Verify annotation means the method is not superadmin exclusive.
    for (int i = 0; i < allAnnotations.length; i++) {
        for (Annotation a : allAnnotations[i]) {
            if (a instanceof Verify) {
                Verify v = (Verify) a;
                if (!v.nullable() && args[i] == null) {
                    throw new IllegalStateException("Null passed to a non-nullable Verify annotation.");
                } else {
                    argMap.put(v, args[i]);
                }
            }
        }
    }
    return argMap;
}
Also used : HttpResponse(org.jboss.resteasy.spi.HttpResponse) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap) MethodInjector(org.jboss.resteasy.spi.MethodInjector) IseException(org.candlepin.common.exceptions.IseException) InjectorFactory(org.jboss.resteasy.spi.InjectorFactory) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Verify(org.candlepin.auth.Verify) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Example 3 with ResourceLocator

use of org.jboss.resteasy.spi.metadata.ResourceLocator in project wildfly by wildfly.

the class DeploymentRestResourcesDefintion method resLocatorDescription.

private JaxrsResourceLocatorDescription resLocatorDescription(ResourceClass resClass, String contextPath, String mapping, Collection<String> servletMappings, List<Class<?>> resolvedCls) {
    JaxrsResourceLocatorDescription locatorRes = new JaxrsResourceLocatorDescription();
    locatorRes.resourceClass = resClass.getClazz();
    resolvedCls.add(resClass.getClazz());
    for (ResourceMethod resMethod : resClass.getResourceMethods()) {
        JaxrsResourceMethodDescription jaxrsRes = new JaxrsResourceMethodDescription();
        jaxrsRes.consumeTypes = resMethod.getConsumes();
        jaxrsRes.contextPath = contextPath;
        jaxrsRes.httpMethods = resMethod.getHttpMethods();
        jaxrsRes.method = resMethod.getMethod();
        jaxrsRes.produceTypes = resMethod.getProduces();
        jaxrsRes.resourceClass = resClass.getClazz();
        String resPath = new StringBuilder(mapping).append("/").append(resMethod.getFullpath()).toString().replace("//", "/");
        jaxrsRes.resourcePath = resPath;
        jaxrsRes.servletMappings = servletMappings;
        addMethodParameters(jaxrsRes, resMethod.getMethod());
        locatorRes.methodsDescriptions.add(jaxrsRes);
    }
    for (ResourceLocator resLocator : resClass.getResourceLocators()) {
        Class<?> clz = resLocator.getReturnType();
        if (clz.equals(resClass.getClazz())) {
            break;
        }
        if (resolvedCls.contains(clz)) {
            break;
        } else {
            resolvedCls.add(clz);
        }
        ResourceClass subResClass = ResourceBuilder.locatorFromAnnotations(clz);
        String subMapping = new StringBuilder(mapping).append("/").append(resLocator.getFullpath()).toString().replace("//", "/");
        JaxrsResourceLocatorDescription inner = resLocatorDescription(subResClass, contextPath, subMapping, servletMappings, resolvedCls);
        if (inner.containsMethodResources()) {
            locatorRes.subLocatorDescriptions.add(inner);
        }
    }
    return locatorRes;
}
Also used : ResourceMethod(org.jboss.resteasy.spi.metadata.ResourceMethod) ResourceClass(org.jboss.resteasy.spi.metadata.ResourceClass) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Aggregations

ResourceLocator (org.jboss.resteasy.spi.metadata.ResourceLocator)3 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 LinkedHashMap (java.util.LinkedHashMap)1 Verify (org.candlepin.auth.Verify)1 IseException (org.candlepin.common.exceptions.IseException)1 HttpResponse (org.jboss.resteasy.spi.HttpResponse)1 InjectorFactory (org.jboss.resteasy.spi.InjectorFactory)1 MethodInjector (org.jboss.resteasy.spi.MethodInjector)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 ResourceClass (org.jboss.resteasy.spi.metadata.ResourceClass)1 ResourceMethod (org.jboss.resteasy.spi.metadata.ResourceMethod)1