use of org.apache.camel.Message in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndSpecialCharacters.
@Test
@Ignore("Fails on CI servers and some platforms - maybe due locale or something")
public void roundtripWithTextAttachmentsAndSpecialCharacters() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text with special characters: ©";
String attFileName = "Attachment File Name with special characters: ©";
in.setBody("Body text with special characters: ©");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain");
in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtrip", exchange);
Message out = result.getOut();
assertEquals("Body text with special characters: ©", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
use of org.apache.camel.Message in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndBinaryContent.
@Test
public void roundtripWithTextAttachmentsAndBinaryContent() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text";
String attFileName = "Attachment File Name";
in.setBody("Body text");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtripbinarycontent", exchange);
Message out = result.getOut();
assertEquals("Body text", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("iso8859-1", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
use of org.apache.camel.Message in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsHeadersInline.
@Test
public void roundtripWithTextAttachmentsHeadersInline() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text";
String attFileName = "Attachment File Name";
in.setBody("Body text");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtripinlineheaders", exchange);
Message out = result.getOut();
assertEquals("Body text", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
use of org.apache.camel.Message in project camel by apache.
the class AbstractMetricsProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String defaultMetricsName = getEndpoint().getMetricsName();
String finalMetricsName = getMetricsName(in, defaultMetricsName);
MetricRegistry registry = getEndpoint().getRegistry();
try {
doProcess(exchange, getEndpoint(), registry, finalMetricsName);
} catch (Exception e) {
exchange.setException(e);
} finally {
clearMetricsHeaders(in);
}
}
use of org.apache.camel.Message in project camel by apache.
the class HistogramProducer method doProcess.
@Override
protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
Message in = exchange.getIn();
Histogram histogram = registry.histogram(metricsName);
Long value = endpoint.getValue();
Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
if (finalValue != null) {
histogram.update(finalValue);
} else {
LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
}
}
Aggregations