// getResourceAsInputStream also considers the content cache
Reader reader = encoding != null ? new InputStreamReader(getResourceAsInputStream(), encoding) : new InputStreamReader(getResourceAsInputStream());
StringWriter buffer = new StringWriter();
String logTag = getClass().getName();
Map variableMap = ExchangeHelper.createVariableMap(exchange);
Context velocityContext = new VelocityContext(variableMap);
// let velocity parse and generate the result in buffer
VelocityEngine engine = getVelocityEngine();
if (log.isDebugEnabled()) {
log.debug("Velocity is evaluating using velocity context: " + variableMap);
}
engine.evaluate(velocityContext, buffer, logTag, reader);
// now lets output the results to the exchange
Message out = exchange.getOut(true);
out.setBody(buffer.toString());
out.setHeader("org.apache.camel.velocity.resource", resource);
Map<String, Object> headers = (Map<String, Object>)velocityContext.get("headers");
for (String key : headers.keySet()) {
out.setHeader(key, headers.get(key));
}
}