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);
// process the exchange
if (LOG.isTraceEnabled()) {
LOG.trace("Proxied method call " + method.getName() + " invoking producer: " + producer);
}
producer.process(exchange);
// check if we had an exception
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 (fault.getCause() instanceof RuntimeException) {
throw (RuntimeException) ((RuntimeCamelException) fault).getCause();
}
throw (RuntimeCamelException) fault;
}
throw fault;
}
// do not return a reply if the method is VOID or the MEP is not OUT capable
Class<?> to = method.getReturnType();
if (to == Void.TYPE || !pattern.isOutCapable()) {
return null;
}
// only convert if there is a body
if (!exchange.hasOut() || exchange.getOut().getBody() == null) {