use of org.apache.camel.Exchange in project camel by apache.
the class MailMessageTest method testMailMessageHandlesSingleHeader.
@Test
public void testMailMessageHandlesSingleHeader() throws Exception {
mimeMessage.setRecipients(Message.RecipientType.TO, new Address[] { new InternetAddress("frank@localhost") });
Exchange exchange = endpoint.createExchange(mimeMessage);
MailMessage in = (MailMessage) exchange.getIn();
assertNotNull(in);
Object header = in.getHeader("TO");
String value = assertIsInstanceOf(String.class, header);
assertEquals("value", "frank@localhost", value);
assertEquals("body", body, in.getBody());
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaEndpoint method createExchange.
public Exchange createExchange(IoSession session, Object payload) {
Exchange exchange = createExchange();
exchange.getIn().setHeader(MinaConstants.MINA_IOSESSION, session);
exchange.getIn().setHeader(MinaConstants.MINA_LOCAL_ADDRESS, session.getLocalAddress());
exchange.getIn().setHeader(MinaConstants.MINA_REMOTE_ADDRESS, session.getRemoteAddress());
MinaPayloadHelper.setIn(exchange, payload);
return exchange;
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaTcpLineDelimiterUsingPlainSocketTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// use no delay for fast unit testing
errorHandler(defaultErrorHandler().maximumRedeliveries(2));
from("mina:tcp://localhost:{{port}}?textline=true&textlineDelimiter=MAC&sync=true").process(new Processor() {
public void process(Exchange e) {
String in = e.getIn().getBody(String.class);
if ("force-null-out-body".equals(in)) {
// forcing a null out body
e.getOut().setBody(null);
} else if ("force-exception".equals(in)) {
// clear out before throwing exception
e.getOut().setBody(null);
throw new IllegalArgumentException("Forced exception");
} else {
e.getOut().setBody("Hello " + in);
}
}
});
}
};
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaConverterTest method testToStringTwoTimes.
public void testToStringTwoTimes() throws UnsupportedEncodingException {
String in = "Hello World 你好";
ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
String out = MinaConverter.toString(bb, exchange);
assertEquals("Hello World 你好", out);
// should be possible to convert to string without affecting the ByteBuffer
out = MinaConverter.toString(bb, exchange);
assertEquals("Hello World 你好", out);
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaEncodingTest method testUDPEncodeUTF8InputIsStringNoMock.
@Test
public void testUDPEncodeUTF8InputIsStringNoMock() throws Exception {
// this unit test covers for testUDPEncodeUTF8InputIsString until the encoding is fixed
// include a UTF-8 char in the text จ is a Thai elephant
final String hello = "Hello Thai Elephant จ";
final String bye = "Hello Thai Elephant จ";
final String uri = "mina:udp://localhost:{{port}}?sync=true&encoding=UTF-8";
context.addRoutes(new RouteBuilder() {
public void configure() {
from(uri).process(new Processor() {
public void process(Exchange exchange) throws Exception {
String s = exchange.getIn().getBody(String.class);
assertEquals(hello, s);
exchange.getOut().setBody(bye);
}
});
}
});
Endpoint endpoint = context.getEndpoint(uri);
Producer producer = endpoint.createProducer();
Exchange exchange = producer.createExchange();
exchange.getIn().setBody(hello);
producer.start();
producer.process(exchange);
producer.stop();
String s = exchange.getOut().getBody(String.class);
assertEquals(bye, s);
}
Aggregations