Search in sources :

Example 41 with RouteBuilder

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Example 42 with RouteBuilder

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) SSLSession(javax.net.ssl.SSLSession) Principal(java.security.Principal) Test(org.junit.Test)

Example 43 with RouteBuilder

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"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 44 with RouteBuilder

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"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) Processor(org.apache.camel.Processor) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) RouteBuilder(org.apache.camel.builder.RouteBuilder) TestNonSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 45 with RouteBuilder

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));
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26