Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class Principal {
  2. public static void main(String[] args) throws Exception {
  3. DefaultCamelContext context = new DefaultCamelContext();
  4.  
  5. context.addRoutes(new RouteBuilder() {
  6.  
  7. AggregationStrategy ag = new MyAggragate();
  8.  
  9. @Override
  10. public void configure() throws Exception {
  11. from("file:entrada?delay=1s&noop=true")
  12. .split()
  13. .xpath("/pedido/itens/item/formato[text()='EBOOK']/..")
  14. .to("direct:aggregate-item");
  15.  
  16. from("direct:aggregate-item")
  17. .aggregate(constant(true), ag)
  18. .completionSize(header("CamelSplitSize"))
  19. .transform(simple("<itens>\n${body}\n</itens>"))
  20. .log("${body}")
  21. .log("${headers.CamelFileAbsolutePath}")
  22. .setBody(simple("insert into Livros values('${headers.CamelFileAbsolutePath}')"))
  23. .log("${body}")
  24. .to("mock:jms/FILA.GERADOR");
  25.  
  26. }
  27. });
  28.  
  29. context.start();
  30. Thread.sleep(2000);
  31. context.stop();
  32. }
  33. private static class MyAggragate implements AggregationStrategy{
  34.  
  35. @Override
  36. public Exchange aggregate(Exchange a, Exchange b) {
  37.  
  38. if (a == null) return b;
  39.  
  40. String aBody = a.getIn().getBody(String.class);
  41. String bBody = b.getIn().getBody(String.class);
  42.  
  43. a.getIn().setBody(aBody + "\n" + bBody);
  44.  
  45. return a;
  46. }
  47.  
  48. }
  49. }
Add Comment
Please, Sign In to add comment