我有一个路由定义文件,内容如下:
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<setHeader headerName="from">
<constant>user@mailserver.com</constant>
</setHeader>
<setHeader headerName="to">
<constant>john.smith@acme.com</constant>
</setHeader>
<setHeader headerName="subject">
<constant>Hello</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<setBody>
<constant>Test</constant>
</setBody>
<!-- <attachment id="attachment.zip" uri="resource:file:test.zip"/> -->
<to uri="smtp://user@mailserver.com?password=secret"/>
</route>
</routes>
使用Java DSL可以发送带有附件的电子邮件:
Endpoint endpoint = camelContext.getEndpoint(
"smtp://user@mailserver.com?password=secret");
Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
Map<String, Object> headers = new HashMap<>();
headers.put("from", "user@mailserver.com");
headers.put("to", "john.smith@acme.com");
headers.put("subject", "Hello");
headers.put("contentType", "text/plain;charset=UTF-8");
in.setHeaders(headers);
in.setBody("Test");
in.addAttachment("attachment.zip", new DataHandler(
applicationContext.getResource("file:test.zip").getURL()));
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
但我需要仅使用XML DSL执行它。
是否有一种在Camel中实现的方式?