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;
}
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;
}
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);
}
}
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);
}
}
}
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();
}
}
}
Aggregations