this.methodInfoCache = methodInfoCache;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
BeanInvocation invocation = new BeanInvocation(method, args);
ExchangePattern pattern = ExchangePattern.InOut;
MethodInfo methodInfo = methodInfoCache.getMethodInfo(method);
if (methodInfo != null) {
pattern = methodInfo.getPattern();
}
Exchange exchange = new DefaultExchange(endpoint, pattern);
exchange.getIn().setBody(invocation);
producer.process(exchange);
Throwable fault = exchange.getException();
if (fault != null) {
if (fault instanceof RuntimeCamelException) {
// if the inner cause is a runtime exception we can throw it directly
if (((RuntimeCamelException) fault).getCause() instanceof RuntimeException) {
throw (RuntimeException) ((RuntimeCamelException) fault).getCause();
}
throw (RuntimeCamelException) fault;
}
throw new InvocationTargetException(fault);
}
if (pattern.isOutCapable()) {
return exchange.getOut().getBody();
} else {
return null;
}
}