public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Receiving HTTP request: " + request);
}
MessageExchange exchange = null;
try {
// Handle WSDLs, XSDs
if (handleStaticResource(request, response)) {
return;
}
// Not giving a specific mutex will synchronize on the continuation itself
Continuation cont = ContinuationSupport.getContinuation(request, null);
// If the continuation is not a retry
if (!cont.isPending()) {
exchange = createExchange(request);
locks.put(exchange.getExchangeId(), cont);
request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
synchronized (cont) {
send(exchange);
if (logger.isDebugEnabled()) {
logger.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
}
long to = this.timeout;
if (to == 0) {
to = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration()
.getConsumerProcessorSuspendTime();
}
boolean result = cont.suspend(to);
exchanges.remove(exchange.getExchangeId());
if (!result) {
locks.remove(exchange.getExchangeId());
throw new Exception("Exchange timed out");
}
request.removeAttribute(MessageExchange.class.getName());
}
return;
} else {
String id = (String) request.getAttribute(MessageExchange.class.getName());
locks.remove(id);
exchange = exchanges.remove(id);
request.removeAttribute(MessageExchange.class.getName());
boolean result = cont.suspend(0);
// Check if this is a timeout
if (exchange == null) {
throw new IllegalStateException("Exchange not found");
}
if (!result) {
throw new Exception("Timeout");
}
}
if (exchange.getStatus() == ExchangeStatus.ERROR) {
Exception e = exchange.getError();
if (e == null) {
e = new Exception("Unkown error (exchange aborted ?)");
}
throw e;
} else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
try {
Fault fault = exchange.getFault();
if (fault != null) {
sendFault(exchange, fault, request, response);
} else {
NormalizedMessage outMsg = exchange.getMessage("out");
if (outMsg != null) {
sendOut(exchange, outMsg, request, response);
}
}
exchange.setStatus(ExchangeStatus.DONE);
send(exchange);
} catch (Exception e) {
exchange.setError(e);
send(exchange);
throw e;
}
} else if (exchange.getStatus() == ExchangeStatus.DONE) {
// This happens when there is no response to send back
sendAccepted(exchange, request, response);
}
} catch (RetryRequest e) {
throw e;