use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class NettySSLContextParametersTest method testSSLInOutWithNettyConsumer.
@Test
public void testSSLInOutWithNettyConsumer() throws Exception {
// ibm jdks dont have sun security algorithms
if (isJavaVendor("ibm")) {
return;
}
context.addRoutes(new RouteBuilder() {
public void configure() {
from("netty4:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#sslContextParameters").process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.");
}
});
}
});
context.start();
String response = template.requestBody("netty4:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#sslContextParameters", "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds", String.class);
assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class NettySSLTest method testSSLInOutWithNettyConsumer.
@Test
public void testSSLInOutWithNettyConsumer() throws Exception {
// ibm jdks dont have sun security algorithms
if (isJavaVendor("ibm")) {
return;
}
context.addRoutes(new RouteBuilder() {
public void configure() {
// needClientAuth=true so we can get the client certificate details
from("netty4:tcp://localhost:{{port}}?sync=true&ssl=true&passphrase=changeit&keyStoreFile=#ksf&trustStoreFile=#tsf&needClientAuth=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
if (session != null) {
javax.security.cert.X509Certificate cert = session.getPeerCertificateChain()[0];
Principal principal = cert.getSubjectDN();
log.info("Client Cert SubjectDN: {}", principal.getName());
exchange.getOut().setBody("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.");
} else {
exchange.getOut().setBody("Cannot start conversion without SSLSession");
}
}
});
}
});
context.start();
String response = template.requestBody("netty4:tcp://localhost:{{port}}?sync=true&ssl=true&passphrase=changeit&keyStoreFile=#ksf&trustStoreFile=#tsf", "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds", String.class);
assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class NettyTextlineInOutNonBlockingTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("log:before").process(new Processor() {
public void process(Exchange exchange) throws Exception {
beforeThreadName = Thread.currentThread().getName();
}
}).to("netty4:tcp://localhost:{{port}}?textline=true&sync=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
afterThreadName = Thread.currentThread().getName();
}
}).to("log:after").to("mock:result");
from("netty4:tcp://localhost:{{port}}?textline=true&sync=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
beforeThreadName2 = Thread.currentThread().getName();
}
}).validate(body().isInstanceOf(String.class)).delay(100).asyncDelayed().process(new Processor() {
public void process(Exchange exchange) throws Exception {
afterThreadName2 = Thread.currentThread().getName();
}
}).transform(body().regexReplaceAll("Hello", "Bye"));
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class RabbitMQInOutIntTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:rabbitMQ").id("producingRoute").setHeader("routeHeader", simple("routeHeader")).inOut(rabbitMQEndpoint);
from(rabbitMQEndpoint).id("consumingRoute").log("Receiving message").process(new Processor() {
public void process(Exchange exchange) throws Exception {
if (exchange.getIn().getBody(TestSerializableObject.class) != null) {
TestSerializableObject foo = exchange.getIn().getBody(TestSerializableObject.class);
foo.setDescription("foobar");
} else if (exchange.getIn().getBody(TestPartiallySerializableObject.class) != null) {
TestPartiallySerializableObject foo = exchange.getIn().getBody(TestPartiallySerializableObject.class);
foo.setNonSerializableObject(new TestNonSerializableObject());
foo.setDescription("foobar");
} else if (exchange.getIn().getBody(String.class) != null) {
if (exchange.getIn().getBody(String.class).contains("header")) {
assertEquals(exchange.getIn().getHeader("String"), "String");
assertEquals(exchange.getIn().getHeader("routeHeader"), "routeHeader");
}
if (exchange.getIn().getBody(String.class).contains("Exception")) {
throw new IllegalArgumentException("Boom");
}
if (exchange.getIn().getBody(String.class).contains("TimeOut")) {
Thread.sleep(TIMEOUT_MS * 2);
}
exchange.getIn().setBody(exchange.getIn().getBody(String.class) + " response");
}
}
});
from("direct:rabbitMQNoAutoAck").id("producingRouteNoAutoAck").setHeader("routeHeader", simple("routeHeader")).inOut(noAutoAckEndpoint);
from(noAutoAckEndpoint).id("consumingRouteNoAutoAck").to(resultEndpoint).throwException(new IllegalStateException("test exception"));
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CamelReactiveStreamsServiceImpl method from.
@Override
public Publisher<Exchange> from(String uri) {
publishedUriToStream.computeIfAbsent(uri, u -> {
try {
String uuid = context.getUuidGenerator().generateUuid();
new RouteBuilder() {
@Override
public void configure() throws Exception {
from(u).to("reactive-streams:" + uuid);
}
}.addRoutesToCamelContext(context);
return uuid;
} catch (Exception e) {
throw new IllegalStateException("Unable to create source reactive stream from direct URI: " + uri, e);
}
});
return fromStream(publishedUriToStream.get(uri));
}
Aggregations