use of org.apache.camel.Exchange in project camel by apache.
the class MinaExchangeTimeOutTest method testUsingTimeoutParameter.
@Test
public void testUsingTimeoutParameter() throws Exception {
// use a timeout value of 2 seconds (timeout is in millis) so we should actually get a response in this test
Endpoint endpoint = context.getEndpoint("mina:tcp://localhost:{{port}}?textline=true&sync=true&timeout=2000");
Producer producer = endpoint.createProducer();
producer.start();
Exchange exchange = producer.createExchange();
exchange.getIn().setBody("Hello World");
try {
producer.process(exchange);
fail("Should have thrown an ExchangeTimedOutException wrapped in a RuntimeCamelException");
} catch (Exception e) {
assertTrue("Should have thrown an ExchangeTimedOutException", e instanceof ExchangeTimedOutException);
}
producer.stop();
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaFiltersTest method testFilter.
private void testFilter(final String uri) throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
assertMockEndpointsSatisfied();
assertEquals("The filter should have been called twice (producer and consumer)", 2, TestFilter.called);
producer.stop();
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaLoggerOptionTest method testNoLoggerOption.
@Test
public void testNoLoggerOption() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Exchange in project camel by apache.
the class MinaLoggerOptionTest method testLoggerOptionFalse.
@Test
public void testLoggerOptionFalse() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Exchange in project camel by apache.
the class Mina2TcpLineDelimiterUsingPlainSocketTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// use no delay for fast unit testing
errorHandler(defaultErrorHandler().maximumRedeliveries(2));
from(String.format("mina2:tcp://localhost:%1$s?textline=true&minaLogger=true&textlineDelimiter=MAC&sync=true", getPort())).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);
}
}
});
}
};
}
Aggregations