use of javax.activation.DataHandler in project camel by apache.
the class MessageWithAttachmentRedeliveryIssueTest method testMessageWithAttachmentRedeliveryIssue.
public void testMessageWithAttachmentRedeliveryIssue() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.send("direct:start", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
exchange.getIn().addAttachment("message1.xml", new DataHandler(new FileDataSource(new File("src/test/data/message1.xml"))));
exchange.getIn().addAttachmentObject("message2.xml", new DefaultAttachment(new FileDataSource(new File("src/test/data/message2.xml"))));
}
});
assertMockEndpointsSatisfied();
Message msg = getMockEndpoint("mock:result").getReceivedExchanges().get(0).getIn();
assertNotNull(msg);
assertEquals("Hello World", msg.getBody());
assertTrue(msg.hasAttachments());
}
use of javax.activation.DataHandler in project camel by apache.
the class ExpressionClauseTest method testAttachments.
public void testAttachments() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
mock.expectedBodiesReceivedInAnyOrder("log4j2.properties", "jndi-example.properties");
template.send("direct:begin", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message m = exchange.getIn();
m.setBody("Hello World");
m.addAttachmentObject("log4j", new DefaultAttachment(new FileDataSource("src/test/resources/log4j2.properties")));
m.addAttachment("jndi-example", new DataHandler(new FileDataSource("src/test/resources/jndi-example.properties")));
}
});
assertMockEndpointsSatisfied();
Map<String, Attachment> attachments = mock.getExchanges().get(0).getIn().getAttachmentObjects();
assertTrue(attachments == null || attachments.size() == 0);
}
use of javax.activation.DataHandler in project camel by apache.
the class DefaultHttpBinding method populateAttachments.
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
// check if there is multipart files, if so will put it into DataHandler
Enumeration<?> names = request.getAttributeNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
Object object = request.getAttribute(name);
LOG.trace("HTTP attachment {} = {}", name, object);
if (object instanceof File) {
String fileName = request.getParameter(name);
message.addAttachment(fileName, new DataHandler(new CamelFileDataSource((File) object, fileName)));
}
}
}
use of javax.activation.DataHandler in project camel by apache.
the class AttachmentHttpBinding method populateRequestParameters.
protected void populateRequestParameters(HttpServletRequest request, HttpMessage message) throws Exception {
//we populate the http request parameters without checking the request method
Map<String, Object> headers = message.getHeaders();
Enumeration<?> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (message.getAttachment(name) != null) {
DataHandler dh = message.getAttachment(name);
Object value = dh;
if (dh.getContentType() == null || dh.getContentType().startsWith("text/plain")) {
value = request.getParameter(name);
}
if (getHeaderFilterStrategy() != null && !getHeaderFilterStrategy().applyFilterToExternalHeaders(name, value, message.getExchange())) {
HttpHelper.appendHeader(headers, name, value);
}
continue;
}
// there may be multiple values for the same name
String[] values = request.getParameterValues(name);
LOG.trace("HTTP parameter {} = {}", name, values);
if (values != null) {
for (String value : values) {
if (getHeaderFilterStrategy() != null && !getHeaderFilterStrategy().applyFilterToExternalHeaders(name, value, message.getExchange())) {
HttpHelper.appendHeader(headers, name, value);
}
}
}
}
}
use of javax.activation.DataHandler in project camel by apache.
the class LdapRouteTest method testLdapRoutePreserveHeaderAndAttachments.
@Test
public void testLdapRoutePreserveHeaderAndAttachments() throws Exception {
camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system"));
camel.start();
final DataHandler dataHandler = new DataHandler("test", "text");
Exchange out = template.request("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("(!(ou=test1))");
exchange.getIn().setHeader("ldapTest", "Camel");
exchange.getIn().addAttachment("ldapAttachment", dataHandler);
}
});
Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
assertFalse(contains("uid=test1,ou=test,ou=system", searchResults));
assertTrue(contains("uid=test2,ou=test,ou=system", searchResults));
assertTrue(contains("uid=testNoOU,ou=test,ou=system", searchResults));
assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
assertEquals("Camel", out.getOut().getHeader("ldapTest"));
assertSame(dataHandler, out.getOut().getAttachment("ldapAttachment"));
}
Aggregations