}
}
protected void onProviderExchange(MessageExchange exchange) throws Exception {
Object corId = getCorrelation(exchange);
Request req = requests.get(corId);
if (req == null) {
Object pojo = getBean();
if (pojo == null) {
pojo = createBean();
injectBean(pojo);
ReflectionUtils.callLifecycleMethod(pojo, PostConstruct.class);
}
req = new Request(pojo, exchange);
requests.put(corId, req);
}
currentRequest.set(req);
synchronized (req) {
// If the bean implements MessageExchangeListener,
// just call the method
if (req.getBean() instanceof MessageExchangeListener) {
((MessageExchangeListener) req.getBean()).onMessageExchange(exchange);
} else {
// Exchange is finished
if (exchange.getStatus() == ExchangeStatus.DONE) {
return;
// Exchange has been aborted with an exception
} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
return;
// Fault message
} else if (exchange.getFault() != null) {
// TODO: find a way to send it back to the bean before setting the DONE status
done(exchange);
} else {
MethodInvocation invocation = getMethodInvocationStrategy().createInvocation(
req.getBean(), getBeanInfo(), exchange, this);
if (invocation == null) {
throw new UnknownMessageExchangeTypeException(exchange, this);
}
try {
invocation.proceed();
} catch (Exception e) {
throw e;
} catch (Throwable throwable) {
throw new MethodInvocationFailedException(req.getBean(), invocation, exchange, this, throwable);
}
if (exchange.getStatus() == ExchangeStatus.ERROR) {
send(exchange);
}
if (exchange.getFault() == null && exchange.getMessage("out") == null) {