package br.com.caelum.camel;
import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext;
public class RotaMovimentacoes {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() { //cuidado, não é RoutesBuilder
@Override
public void configure() throws Exception {
from("direct:entrada").
to("xslt:movimentacoes-para-html.xslt").
//to("xslt:pedido-para-soap.xslt").
setHeader(Exchange.FILE_NAME, constant("movimentacoes.html")).
log("${body}").
to("file:saida");
}
});
context.start();
ProducerTemplate producer = context.createProducerTemplate();
producer.sendBody("direct:entrada",
"<movimentacoes>" +
"<movimentacao><valor>2314.4</valor><data>11/12/2015</data><tipo>ENTRADA</tipo></movimentacao>" +
"<movimentacao><valor>546.98</valor><data>11/12/2015</data><tipo>SAIDA</tipo></movimentacao>" +
"<movimentacao><valor>314.1</valor><data>12/12/2015</data><tipo>SAIDA</tipo></movimentacao>" +
"<movimentacao><valor>56.99</valor><data>13/12/2015</data><tipo>SAIDA</tipo></movimentacao>" +
"</movimentacoes>");
context.stop();
}
}
Aqui segue o conteúdo de movimentacoes-para-html.xslt: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/movimentacoes">
<html xmlns:alura="http://alura.com.br">
<body>
<table>
<tr>
<th>Valor</th>
<th>Data</th>
<th>Tipo</th>
</tr>
<xsl:for-each select="movimentacao">
<tr>
<th><xsl:value-of select="valor"/></th>
<th><xsl:value-of select="data"/></th>
<th><xsl:value-of select="tipo"/></th>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>