final Continuation continuation = ContinuationSupport.getContinuation(request, null);
if (continuation.isNew()) {
// Have the camel process the HTTP exchange.
final HttpExchange exchange = new HttpExchange(consumer.getEndpoint(), request, response);
boolean sync = consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
public void done(boolean sync) {
if (sync) {
return;
}
continuation.setObject(exchange);
continuation.resume();
}
});
if (!sync) {
// Wait for the exchange to get processed.
// This might block until it completes or it might return via an exception and
// then this method is re-invoked once the the exchange has finished processing
continuation.suspend(0);
}
// HC: The getBinding() is interesting because it illustrates the
// impedance miss-match between HTTP's stream oriented protocol, and
// Camels more message oriented protocol exchanges.
// set the header value from endpoint
if (exchange.getOut().getHeader(Exchange.HTTP_CHUNKED) == null) {
exchange.getOut().setHeader(Exchange.HTTP_CHUNKED, consumer.getEndpoint().isChunked());
}
// now lets output to the response
consumer.getBinding().writeResponse(exchange, response);
return;
}
if (continuation.isResumed()) {
HttpExchange exchange = (HttpExchange)continuation.getObject();
// now lets output to the response
consumer.getBinding().writeResponse(exchange, response);
return;
}