use of java.lang.reflect.Method in project camel by apache.
the class CxfRsProducer method invokeAsyncProxyClient.
protected void invokeAsyncProxyClient(Exchange exchange, final AsyncCallback callback) 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;
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));
CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
final CxfProxyInvocationCallback invocationCallback = new CxfProxyInvocationCallback(target, exchange, cxfRsEndpoint, callback);
WebClient.getConfig(target).getRequestContext().put(InvocationCallback.class.getName(), invocationCallback);
// handle cookies
CookieHandler cookieHandler = ((CxfRsEndpoint) getEndpoint()).getCookieHandler();
loadCookies(exchange, target, cookieHandler);
method.invoke(target, parameters);
}
use of java.lang.reflect.Method in project camel by apache.
the class MapperWithTwoMethods method selectMapperMultipleMethods.
@Test
public void selectMapperMultipleMethods() throws Exception {
Method selectedMethod = customMapper.selectMethod(MapperWithTwoMethods.class, B.class);
Assert.assertNotNull(selectedMethod);
Assert.assertEquals(MapperWithTwoMethods.class.getMethod("convertToA", B.class), selectedMethod);
}
use of java.lang.reflect.Method in project camel by apache.
the class FacebookMethodsTypeTest method areAllMethodsMapped.
@Test
public void areAllMethodsMapped() throws Exception {
final Class<?>[] interfaces = Facebook.class.getInterfaces();
for (Class<?> clazz : interfaces) {
if (clazz.getName().endsWith("Methods")) {
// check all methods of this *Methods interface
for (Method method : clazz.getDeclaredMethods()) {
final FacebookMethodsType methodsType = FacebookMethodsType.findMethod(method.getName(), method.getParameterTypes());
assertNotNull("Expected method mapping not found:" + method.getName(), methodsType);
assertEquals("Methods are not equal", method, methodsType.getMethod());
}
}
}
}
use of java.lang.reflect.Method in project camel by apache.
the class GenericFileEndpoint method createGenericFileStrategy.
/**
* A strategy method to lazily create the file strategy
*/
@SuppressWarnings("unchecked")
protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
Class<?> factory = null;
try {
FactoryFinder finder = getCamelContext().getFactoryFinder("META-INF/services/org/apache/camel/component/");
log.trace("Using FactoryFinder: {}", finder);
factory = finder.findClass(getScheme(), "strategy.factory.", CamelContext.class);
} catch (ClassNotFoundException e) {
log.trace("'strategy.factory.class' not found", e);
} catch (IOException e) {
log.trace("No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
}
if (factory == null) {
// use default
try {
log.trace("Using ClassResolver to resolve class: {}", DEFAULT_STRATEGYFACTORY_CLASS);
factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
} catch (Exception e) {
log.trace("Cannot load class: {}", DEFAULT_STRATEGYFACTORY_CLASS, e);
}
// fallback and us this class loader
try {
if (log.isTraceEnabled()) {
log.trace("Using classloader: {} to resolve class: {}", this.getClass().getClassLoader(), DEFAULT_STRATEGYFACTORY_CLASS);
}
factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS, this.getClass().getClassLoader());
} catch (Exception e) {
if (log.isTraceEnabled()) {
log.trace("Cannot load class: {} using classloader: " + this.getClass().getClassLoader(), DEFAULT_STRATEGYFACTORY_CLASS, e);
}
}
if (factory == null) {
throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
}
}
try {
Method factoryMethod = factory.getMethod("createGenericFileProcessStrategy", CamelContext.class, Map.class);
Map<String, Object> params = getParamsAsMap();
log.debug("Parameters for Generic file process strategy {}", params);
return (GenericFileProcessStrategy<T>) ObjectHelper.invokeMethod(factoryMethod, null, getCamelContext(), params);
} catch (NoSuchMethodException e) {
throw new TypeNotPresentException(factory.getSimpleName() + ".createGenericFileProcessStrategy method not found", e);
}
}
use of java.lang.reflect.Method in project camel by apache.
the class HeaderSelectorProducer method doStart.
@Override
protected void doStart() throws Exception {
for (final Method method : target.getClass().getDeclaredMethods()) {
InvokeOnHeaders annotation = method.getAnnotation(InvokeOnHeaders.class);
if (annotation != null) {
for (InvokeOnHeader processor : annotation.value()) {
bind(processor, method);
}
} else {
bind(method.getAnnotation(InvokeOnHeader.class), method);
}
}
handlers = Collections.unmodifiableMap(handlers);
super.doStart();
}
Aggregations