Search in sources :

Example 1 with BeanParamInfo

use of org.apache.cxf.jaxrs.model.BeanParamInfo in project cxf by apache.

the class ServerProviderFactory method addBeanParamInfo.

public void addBeanParamInfo(BeanParamInfo bpi) {
    beanParams.put(bpi.getResourceClass(), bpi);
    for (Method m : bpi.getResourceClass().getMethods()) {
        if (m.getAnnotation(BeanParam.class) != null) {
            BeanParamInfo methodBpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
            addBeanParamInfo(methodBpi);
        }
    }
    for (Field f : bpi.getResourceClass().getDeclaredFields()) {
        if (f.getAnnotation(BeanParam.class) != null) {
            BeanParamInfo fieldBpi = new BeanParamInfo(f.getType(), getBus());
            addBeanParamInfo(fieldBpi);
        }
    }
}
Also used : Field(java.lang.reflect.Field) BeanParamInfo(org.apache.cxf.jaxrs.model.BeanParamInfo) Method(java.lang.reflect.Method) BeanParam(javax.ws.rs.BeanParam)

Example 2 with BeanParamInfo

use of org.apache.cxf.jaxrs.model.BeanParamInfo in project cxf by apache.

the class JAXRSUtils method createBeanParamValue.

public static Object createBeanParamValue(Message m, Class<?> clazz, OperationResourceInfo ori) {
    BeanParamInfo bmi = ServerProviderFactory.getInstance(m).getBeanParamInfo(clazz);
    if (bmi == null) {
        // we could've started introspecting now but the fact no bean info
        // is available indicates that the one created at start up has been
        // lost and hence it is 500
        LOG.warning("Bean parameter info is not available");
        throw ExceptionUtils.toInternalServerErrorException(null, null);
    }
    Object instance;
    try {
        instance = clazz.newInstance();
    } catch (Throwable t) {
        throw ExceptionUtils.toInternalServerErrorException(t, null);
    }
    JAXRSUtils.injectParameters(ori, bmi, instance, m);
    InjectionUtils.injectContexts(instance, bmi, m);
    return instance;
}
Also used : BeanParamInfo(org.apache.cxf.jaxrs.model.BeanParamInfo)

Aggregations

BeanParamInfo (org.apache.cxf.jaxrs.model.BeanParamInfo)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 BeanParam (javax.ws.rs.BeanParam)1