Search in sources :

Example 56 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class JettyRecipientListCxfIssueTest method testJettyRecipientListCxf.

@Test
public void testJettyRecipientListCxf() throws Exception {
    final String request = context().getTypeConverter().convertTo(String.class, new File("src/test/resources/greetMe.xml"));
    assertNotNull(request);
    // send a message to jetty
    Exchange out = template.request("jetty:http://0.0.0.0:{{RecipientListCxfTest.port3}}/myapp", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("operationName", "greetMe");
            exchange.getIn().setBody(request);
        }
    });
    assertNotNull(out);
    assertTrue("Should have out", out.hasOut());
    String body = out.getOut().getBody(String.class);
    log.info("Reply from jetty call:\n{}", body);
    // we get the last reply as response
    assertNotNull(body);
    assertTrue("Should have Bye Camel", body.contains("Bye Camel"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) File(java.io.File) Test(org.junit.Test)

Example 57 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class HttpRouteContentLengthTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            port1 = AvailablePortFinder.getNextAvailable(8000);
            port2 = AvailablePortFinder.getNextAvailable(9000);
            // use jetty as server as it supports sending response as chunked encoding
            from("jetty:http://localhost:" + port1 + "/test").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    String contentLength = exchange.getIn().getHeader(Exchange.CONTENT_LENGTH, String.class);
                    String request = exchange.getIn().getBody(String.class);
                    exchange.getOut().setBody(request + ": " + contentLength);
                }
            }).transform().simple("Bye ${body}");
            // set up a netty http proxy
            from("jetty:http://localhost:" + port2 + "/test").to(getHttpEndpointScheme() + port1 + "/test?bridgeEndpoint=true&throwExceptionOnFailure=false");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 58 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class HttpRouteContentLengthTest method invokeService.

private void invokeService(int port) {
    Exchange out = template.request("http://localhost:" + port + "/test", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Camel request.");
        }
    });
    assertNotNull(out);
    assertEquals("Bye Camel request.: 14", out.getOut().getBody(String.class));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 59 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class JettyHttpFileCacheTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jetty:http://localhost:8201/clipboard/download?chunked=true&matchOnUriPrefix=true").to("http://localhost:9101?bridgeEndpoint=true");
            from("jetty:http://localhost:9101?chunked=true&matchOnUriPrefix=true").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setBody(TEST_STRING);
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 60 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class JettyHttpTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from(targetConsumerUri).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    String path = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
                    exchange.getOut().setBody("Hi! " + path);
                }
            });
            from(sourceUri).to(targetProducerUri);
            from("direct:root").to(sourceProducerUri).to("mock:result");
            from("direct:relative").to(sourceProducerUri + "/relative").to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Aggregations

Processor (org.apache.camel.Processor)1469 Exchange (org.apache.camel.Exchange)1369 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)544 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)66 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)35 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24