use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.
the class BeanCallTest method beanCallTest.
@Test
public void beanCallTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBody").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("HelloBody 1", exchange.getIn().getBody());
}
use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.
the class BeanCallTest method beanCallWithErrorTest.
@Test
public void beanCallWithErrorTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBodyWrongType").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("ERR", exchange.getIn().getBody());
}
use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.
the class BeanCallTest method beanCallEmptyPublisherTest.
@Test
public void beanCallEmptyPublisherTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBodyEmpty").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
Object body = exchange.getIn().getBody();
// unchanged
assertEquals(new Integer(1), body);
}
use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.
the class BeanCallTest method beanCallHeaderMappingTest.
@Test
public void beanCallHeaderMappingTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processHeader").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBodyAndHeader("direct:num", 1, "myheader", 2);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("HelloHeader 2", exchange.getIn().getBody());
}
use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.
the class CamelReactiveStreamsServiceImpl method process.
@Override
public void process(String uri, Function<? super Publisher<Exchange>, ?> processor) {
try {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from(uri).process(exchange -> {
Exchange copy = exchange.copy();
Object result = processor.apply(new MonoPublisher<>(copy));
exchange.getIn().setBody(result);
}).process(new UnwrapStreamProcessor());
}
}.addRoutesToCamelContext(context);
} catch (Exception e) {
throw new IllegalStateException("Unable to add reactive stream processor to the direct URI: " + uri, e);
}
}
Aggregations