Source:
public Object toHttpResponse(HttpServerExchange httpExchange, Message message) throws IOException { boolean failed = message.getExchange().isFailed(); int defaultCode = failed ? 500 : 200; int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, defaultCode, int.class); httpExchange.setStatusCode(code); TypeConverter tc = message.getExchange().getContext().getTypeConverter(); for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); final Iterator<?> it = ObjectHelper.createIterator(value, null); while (it.hasNext()) { String headerValue = tc.convertTo(String.class, it.next()); if (headerValue != null && headerFilterStrategy != null && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, message.getExchange())) { LOG.trace("HTTP-Header: {}={}", key, headerValue); httpExchange.getResponseHeaders().add(new HttpString(key), headerValue); } } } Object body = message.getBody(); Exception exception = message.getExchange().getException(); if (exception != null) { if (!isMuteException()) { if (isTransferException()) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(exception); oos.flush(); IOHelper.close(oos, bos); body = ByteBuffer.wrap(bos.toByteArray()); message.setHeader(Exchange.CONTENT_TYPE, "application/x-java-serialized-object"); } else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); body = ByteBuffer.wrap(sw.toString().getBytes()); message.setHeader(Exchange.CONTENT_TYPE, "text/plain"); } } ExchangeHelper.setFailureHandled(message.getExchange()); } String contentType = MessageHelper.getContentType(message); if (contentType != null) { httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, contentType); LOG.trace("Content-Type: {}", contentType); } return body; }

Target:
public Object toHttpResponse(HttpServerExchange httpExchange, Message message) throws IOException { boolean failed = message.getExchange().isFailed(); int defaultCode = failed ? 500 : 200; int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, defaultCode, int.class); httpExchange.setStatusCode(code); TypeConverter tc = message.getExchange().getContext().getTypeConverter(); for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); final Iterator<?> it = ObjectHelper.createIterator(value, null); while (it.hasNext()) { String headerValue = tc.convertTo(String.class, it.next()); if (headerValue != null && headerFilterStrategy != null && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, message.getExchange())) { LOG.trace("HTTP-Header: {}={}", key, headerValue); httpExchange.getResponseHeaders().add(new HttpString(key), headerValue); } } } Object body = message.getBody(); Exception exception = message.getExchange().getException(); if (exception != null && !isMuteException()) { if (isTransferException()) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(exception); oos.flush(); IOHelper.close(oos, bos); body = ByteBuffer.wrap(bos.toByteArray()); message.setHeader(Exchange.CONTENT_TYPE, "application/x-java-serialized-object"); } else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); body = ByteBuffer.wrap(sw.toString().getBytes()); message.setHeader(Exchange.CONTENT_TYPE, "text/plain"); } ExchangeHelper.setFailureHandled(message.getExchange()); } else if (exception != null && isMuteException()) { ExchangeHelper.setFailureHandled(message.getExchange()); } String contentType = MessageHelper.getContentType(message); if (contentType != null) { httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, contentType); LOG.trace("Content-Type: {}", contentType); } return body; }