Search in sources :

Example 1 with Method

use of java.lang.reflect.Method in project camel by apache.

the class SessionFactoryLocator method loadSessionFactoryFromClassPath.

private static SessionFactory loadSessionFactoryFromClassPath() {
    try {
        Class<?> factoryClass = null;
        factoryClass = Class.forName("org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl");
        if (factoryClass != null) {
            Method method = factoryClass.getMethod("newInstance", new Class<?>[0]);
            return (SessionFactory) method.invoke(null, new Object[0]);
        }
    } catch (Exception ex) {
        LOG.error("Cannot create the SessionFactoryImpl due to: {0}", ex);
        throw new RuntimeCamelException(ex);
    }
    return null;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Method(java.lang.reflect.Method) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 2 with Method

use of java.lang.reflect.Method in project camel by apache.

the class BundleContextUtils method getBundleContext.

/**
     * Retrieve the BundleContext that the given class has been loaded from.
     *
     * @param clazz the class to find the bundle context from
     * @return the bundle context or <code>null</code> if it can't be found
     */
public static BundleContext getBundleContext(Class<?> clazz) {
    try {
        ClassLoader cl = clazz.getClassLoader();
        Class<?> clClazz = cl.getClass();
        Method mth = null;
        while (clClazz != null) {
            try {
                mth = clClazz.getDeclaredMethod("getBundle");
                break;
            } catch (NoSuchMethodException e) {
            // Ignore
            }
            clClazz = clClazz.getSuperclass();
        }
        if (mth != null) {
            mth.setAccessible(true);
            return ((Bundle) mth.invoke(cl)).getBundleContext();
        }
    } catch (Throwable t) {
    // Ignore
    }
    return null;
}
Also used : Bundle(org.osgi.framework.Bundle) Method(java.lang.reflect.Method)

Example 3 with Method

use of java.lang.reflect.Method in project camel by apache.

the class CxfEndpoint method setupHandlers.

protected void setupHandlers(ClientFactoryBean factoryBean, Client client) throws Exception {
    if (factoryBean instanceof JaxWsClientFactoryBean && handlers != null) {
        AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
        Method m = factoryBean.getClass().getMethod("getServiceFactory");
        JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean) m.invoke(factoryBean);
        @SuppressWarnings("rawtypes") List<Handler> chain = new ArrayList<Handler>(handlers);
        chain.addAll(builder.buildHandlerChainFromClass(sf.getServiceClass(), sf.getEndpointInfo().getName(), sf.getServiceQName(), factoryBean.getBindingId()));
        if (!chain.isEmpty()) {
            ResourceManager resourceManager = getBus().getExtension(ResourceManager.class);
            List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
            resourceManager = new DefaultResourceManager(resolvers);
            resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
            ResourceInjector injector = new ResourceInjector(resourceManager);
            for (Handler<?> h : chain) {
                if (Proxy.isProxyClass(h.getClass()) && getServiceClass() != null) {
                    injector.inject(h, getServiceClass());
                    injector.construct(h, getServiceClass());
                } else {
                    injector.inject(h);
                    injector.construct(h);
                }
            }
        }
        ((JaxWsEndpointImpl) client.getEndpoint()).getJaxwsBinding().setHandlerChain(chain);
    }
}
Also used : JaxWsClientFactoryBean(org.apache.cxf.jaxws.JaxWsClientFactoryBean) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) AnnotationHandlerChainBuilder(org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) ArrayList(java.util.ArrayList) CookieHandler(org.apache.camel.http.common.cookie.CookieHandler) Handler(javax.xml.ws.handler.Handler) Method(java.lang.reflect.Method) ResourceManager(org.apache.cxf.resource.ResourceManager) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceResolver(org.apache.cxf.resource.ResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver)

Example 4 with Method

use of java.lang.reflect.Method in project camel by apache.

the class DefaultCxfBinding method changeToOneway.

//TODO replace this method with the cxf util's method when it becomes available
private static void changeToOneway(org.apache.cxf.message.Exchange cxfExchange) {
    cxfExchange.setOneWay(true);
    Object httpresp = cxfExchange.getInMessage().get("HTTP.RESPONSE");
    if (httpresp != null) {
        try {
            Method m = findMethod(httpresp.getClass(), "setStatus", int.class);
            if (m != null) {
                m.invoke(httpresp, 202);
            }
        } catch (Exception e) {
            LOG.warn("Unable to set the http ", e);
        }
    }
}
Also used : Method(java.lang.reflect.Method)

Example 5 with Method

use of java.lang.reflect.Method in project camel by apache.

the class CxfRsProducer method invokeProxyClient.

protected void invokeProxyClient(Exchange exchange) throws Exception {
    Message inMessage = exchange.getIn();
    Object[] varValues = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
    String methodName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
    Client target = null;
    JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils.getEffectiveAddress(exchange, ((CxfRsEndpoint) getEndpoint()).getAddress()));
    Bus bus = ((CxfRsEndpoint) getEndpoint()).getBus();
    // We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
    if (bus != null) {
        cfb.setBus(bus);
    }
    if (varValues == null) {
        target = cfb.create();
    } else {
        target = cfb.createWithValues(varValues);
    }
    setupClientHeaders(target, exchange);
    // find out the method which we want to invoke
    JAXRSServiceFactoryBean sfb = cfb.getServiceFactory();
    sfb.getResourceClasses();
    // check the null body first
    Object[] parameters = null;
    if (inMessage.getBody() != null) {
        parameters = inMessage.getBody(Object[].class);
    }
    // get the method
    Method method = findRightMethod(sfb.getResourceClasses(), methodName, getParameterTypes(parameters));
    // handle cookies
    CookieHandler cookieHandler = ((CxfRsEndpoint) getEndpoint()).getCookieHandler();
    loadCookies(exchange, target, cookieHandler);
    // Will send out the message to
    // Need to deal with the sub resource class
    Object response = method.invoke(target, parameters);
    int statesCode = target.getResponse().getStatus();
    // handle cookies
    saveCookies(exchange, target, cookieHandler);
    if (throwException) {
        if (response instanceof Response) {
            Integer respCode = ((Response) response).getStatus();
            if (respCode > 207) {
                throw populateCxfRsProducerException(exchange, (Response) response, respCode);
            }
        }
    }
    CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
    CxfRsBinding binding = cxfRsEndpoint.getBinding();
    if (exchange.getPattern().isOutCapable()) {
        LOG.trace("Response body = {}", response);
        exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
        exchange.getOut().setBody(binding.bindResponseToCamelBody(response, exchange));
        exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response, exchange));
        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, statesCode);
    } else {
        // just close the input stream of the response object
        if (response instanceof Response) {
            ((Response) response).close();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.camel.Message) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) Method(java.lang.reflect.Method) Response(javax.ws.rs.core.Response) JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(org.apache.cxf.jaxrs.client.Client) CookieHandler(org.apache.camel.http.common.cookie.CookieHandler)

Aggregations

Method (java.lang.reflect.Method)7234 Test (org.junit.Test)1402 InvocationTargetException (java.lang.reflect.InvocationTargetException)935 ArrayList (java.util.ArrayList)557 Field (java.lang.reflect.Field)498 IOException (java.io.IOException)463 HashMap (java.util.HashMap)279 Map (java.util.Map)232 PropertyDescriptor (java.beans.PropertyDescriptor)230 List (java.util.List)221 Annotation (java.lang.annotation.Annotation)174 Type (java.lang.reflect.Type)174 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)168 BeanInfo (java.beans.BeanInfo)155 HashSet (java.util.HashSet)147 File (java.io.File)138 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128 URL (java.net.URL)114 ParameterizedType (java.lang.reflect.ParameterizedType)113