Java Code Examples for org.apache.cxf.jaxrs.model.ClassResourceInfo#getResourceProvider()

The following examples show how to use org.apache.cxf.jaxrs.model.ClassResourceInfo#getResourceProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComparableResourceComparator.java    From aries-jax-rs-whiteboard with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(
    ClassResourceInfo cri1, ClassResourceInfo cri2, Message message) {

    ResourceProvider rp1 = cri1.getResourceProvider();
    ResourceProvider rp2 = cri2.getResourceProvider();

    if (rp1 instanceof ServiceReferenceResourceProvider &&
        rp2 instanceof ServiceReferenceResourceProvider) {

        return comparator.compare(
            (ServiceReferenceResourceProvider)rp2,
            (ServiceReferenceResourceProvider)rp1);
    }

    if (rp1 instanceof ServiceReferenceResourceProvider) {
        return -1;
    }

    if (rp2 instanceof ServiceReferenceResourceProvider) {
        return 1;
    }

    return 0;
}
 
Example 2
Source File: ClassResourceInfoProxyHelper.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
public static void reloadClassResourceInfo(ClassResourceInfo classResourceInfoProxy) {
    try {
        DISABLE_PROXY_GENERATION.set(true);
        CriProxyMethodHandler criMethodHandler = (CriProxyMethodHandler) ((ProxyObject)classResourceInfoProxy).getHandler();
        ClassResourceInfo newClassResourceInfo = (ClassResourceInfo) ReflectionHelper.invoke(null, ResourceUtils.class, "createClassResourceInfo",
                criMethodHandler.generatorTypes, criMethodHandler.generatorParams);
        ClassResourceInfo oldClassResourceInfo = criMethodHandler.delegate;
        ResourceProvider resourceProvider = oldClassResourceInfo.getResourceProvider();
        updateResourceProvider(resourceProvider);
        newClassResourceInfo.setResourceProvider(resourceProvider);
        criMethodHandler.delegate = newClassResourceInfo;
    } catch (Exception e) {
        LOGGER.error("reloadClassResourceInfo() exception {}", e.getMessage());
    } finally {
        DISABLE_PROXY_GENERATION.remove();
    }
}
 
Example 3
Source File: CxfJaxrsServiceRegistrator.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
public Iterable<Class<?>> getStaticResourceClasses() {
    if (_jaxRsServerFactoryBean == null) {
        return Collections.emptyList();
    }

    JAXRSServiceFactoryBean serviceFactory =
        _jaxRsServerFactoryBean.getServiceFactory();

    List<ClassResourceInfo> classResourceInfo =
        serviceFactory.getClassResourceInfo();

    ArrayList<Class<?>> classes = new ArrayList<>();

    for (ClassResourceInfo resourceInfo : classResourceInfo) {
        if (resourceInfo == null) {
            continue;
        }

        ResourceProvider resourceProvider =
            resourceInfo.getResourceProvider();

        if (resourceProvider == null ||
            !ServiceReferenceResourceProvider.class.isAssignableFrom(
                resourceProvider.getClass())) {

            classes.add(resourceInfo.getResourceClass());
        }
    }

    return classes;
}
 
Example 4
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 5
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 6
Source File: ValidationInInterceptor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {

        final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
        if (operationResource == null) {
            log.info("OperationResourceInfo is not available, skipping validation");
            return;
        }

        final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
        if (classResource == null) {
            log.info("ClassResourceInfo is not available, skipping validation");
            return;
        }

        final ResourceProvider resourceProvider = classResource.getResourceProvider();
        if (resourceProvider == null) {
            log.info("ResourceProvider is not available, skipping validation");
            return;
        }

        final List<Object> arguments = MessageContentsList.getContentsList(message);
        final Method method = operationResource.getAnnotatedMethod();
        final Object instance = resourceProvider.getInstance(message);
        if (method != null && arguments != null) {
            //validate the parameters(arguments) over the invoked method
            validate(method, arguments.toArray(), instance);

            //validate the fields of each argument
            for (Object arg : arguments) {
                if (arg != null)
                    validate(arg);
            }
        }
    }
 
Example 7
Source File: JAXRSInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setExchangeProperties(Message message,
                                   Exchange exchange,
                                   OperationResourceInfo ori,
                                   MultivaluedMap<String, String> values,
                                   int numberOfResources) {
    final ClassResourceInfo cri = ori.getClassResourceInfo();
    exchange.put(OperationResourceInfo.class, ori);
    exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
    message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
    message.put(URITemplate.TEMPLATE_PARAMETERS, values);

    String plainOperationName = ori.getMethodToInvoke().getName();
    if (numberOfResources > 1) {
        plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
    }
    exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);

    if (ori.isOneway()
        || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) {
        exchange.setOneWay(true);
    }
    ResourceProvider rp = cri.getResourceProvider();
    if (rp instanceof SingletonResourceProvider) {
        //cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton
        exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
    }
}
 
Example 8
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
private ResourceProvider getResourceProvider(Exchange exchange) {
    Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
    if (provider == null) {
        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
        ClassResourceInfo cri = ori.getClassResourceInfo();
        return cri.getResourceProvider();
    }
    return (ResourceProvider)provider;
}
 
Example 9
Source File: JAXRSServerFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void updateClassResourceProviders(Endpoint ep) {
    for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
        if (cri.getResourceProvider() == null) {
            ResourceProvider rp = resourceProviders.get(cri.getResourceClass());
            if (rp != null) {
                cri.setResourceProvider(rp);
            } else {
                setDefaultResourceProvider(cri);
            }
        }
        if (cri.getResourceProvider() instanceof SingletonResourceProvider) {
            ((SingletonResourceProvider)cri.getResourceProvider()).init(ep);
        }
    }
}