org.apache.camel.builder.RouteBuilder Java Examples

The following examples show how to use org.apache.camel.builder.RouteBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigFileSedaTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("file:target/inventory?noop=true")
                .log("Starting to process big file: ${header.CamelFileName}")
                .split(body().tokenize("\n")).streaming()
                    .bean(InventoryService.class, "csvToObject")
                    .to("seda:update")
                .end()
                .log("Done processing big file: ${header.CamelFileName}");

            from("seda:update?concurrentConsumers=20")
                .bean(InventoryService.class, "updateInventory");
        }
    };
}
 
Example #2
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteKeyPredicateAndSubPredicate() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "('KLAX')/Location";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_KLAX_LOC);
}
 
Example #3
Source File: FhirJsonIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testFhirJsonMarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal().fhirJson("DSTU3");
        }
    });

    camelctx.start();
    try {
        Patient patient = createPatient();
        ProducerTemplate template = camelctx.createProducerTemplate();
        InputStream inputStream = template.requestBody("direct:start", patient, InputStream.class);
        IBaseResource result = FhirContext.forDstu3().newJsonParser().parseResource(new InputStreamReader(inputStream));
        Assert.assertTrue("Expected marshaled patient to be equal", patient.equalsDeep((Base)result));
    } finally {
        camelctx.close();
    }
}
 
Example #4
Source File: CXFWSSecureProducerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndpointRouteWithValidCredentials() throws Exception {
    deployer.deploy(SIMPLE_WAR);
    try {
        CamelContext camelctx = new DefaultCamelContext();
        camelctx.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                        .to("cxf://" + getEndpointAddress("/simple", "cxfuser", "cxfpassword"));
            }
        });

        camelctx.start();
        try {
            ProducerTemplate producer = camelctx.createProducerTemplate();
            String result = producer.requestBody("direct:start", "Kermit", String.class);
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            camelctx.close();
        }
    } finally {
        deployer.undeploy(SIMPLE_WAR);
    }
}
 
Example #5
Source File: LogProfileIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testWildFlyLogProfileGloabalLogConfig() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.getGlobalOptions().put(Exchange.LOG_EIP_NAME, LogProfileIntegrationTest.class.getName());

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .log("Goodbye ${body}");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.requestBody("direct:start", "Kermit");
        assertLogFileContainsContent(".*LogProfileIntegrationTest.*Goodbye Kermit$");
    } finally {
        camelctx.close();
    }
}
 
Example #6
Source File: AggregateTimeoutThreadpoolTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            ScheduledExecutorService threadPool = context.getExecutorServiceManager().newScheduledThreadPool(this, "MyThreadPool", 2);

            from("direct:start")
                .log("Sending ${body}")
                // aggregate based on xpath expression which extracts from the
                // arrived message body.
                // use class MyAggregationStrategy for aggregation
                .aggregate(xpath("/order/@customer"), new MyAggregationStrategy())
                    // complete either when we have 2 messages or after 5 sec timeout
                    .completionSize(2).completionTimeout(5000)
                    .timeoutCheckerExecutorService(threadPool)
                    // do a little logging for the published message
                    .log("Completed by ${exchangeProperty.CamelAggregatedCompletedBy}")
                    .log("Sending out ${body}")
                    // and send it to the mock
                    .to("mock:result");
        }
     };
}
 
Example #7
Source File: AggregateABCGroupTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                // do a little logging
                .log("Sending ${body} with correlation key ${header.myId}")
                // aggregate based on header correlation key
                // notice we do NOT need to use an AggregationStrategy as we
                // groupExchanges
                .aggregate(header("myId")).completionSize(3).groupExchanges()
                    // do a little logging for the published message
                    .log("Sending out ${body}")
                    // and send it to the mock
                    .to("mock:result");
        }
    };
}
 
Example #8
Source File: SJMSIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessageConsumerRoute() throws Exception {

    CamelContext camelctx = createCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("sjms:queue:" + QUEUE_NAME + "?connectionFactory=#cfactory").
            transform(body().prepend("Hello ")).to("seda:end");
        }
    });

    camelctx.start();

    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();

    try {
        // Send a message to the queue
        ConnectionFactory cfactory = lookupConnectionFactory();
        Connection connection = cfactory.createConnection();
        try {
            sendMessage(connection, QUEUE_JNDI_NAME, "Kermit");
            String result = consumer.receive(3000).getIn().getBody(String.class);
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            connection.close();
        }
    } finally {
        camelctx.close();
    }
}
 
Example #9
Source File: JoltIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoltComponent() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("jolt:classpath:/schema.json?inputType=JsonString&outputType=JsonString");
        }
    });

    camelctx.start();
    try {
        String input = TestUtils.getResourceValue(JoltIntegrationTest.class, "/input.json");
        String output = TestUtils.getResourceValue(JoltIntegrationTest.class, "/output.json");

        ProducerTemplate template = camelctx.createProducerTemplate();
        String result = template.requestBody("direct:start", input, String.class);

        Assert.assertEquals(output, result);
    } finally {
        camelctx.close();
    }
}
 
Example #10
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapMarshal() throws Exception {

    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(format);
        }
    });

    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope.xml")) {
        String expected = XMLUtils.compactXML(input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String customerXML = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(customerXML));
    } finally {
        camelctx.close();
    }
}
 
Example #11
Source File: XmlSecurityIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testXmlSigning() throws Exception {

    CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .to("xmlsecurity-sign://enveloping?keyAccessor=#accessor&schemaResourceUri=");
        }
    });

    try {
        camelctx.start();

        ProducerTemplate producer = camelctx.createProducerTemplate();
        String signedXml = producer.requestBody("direct:start", XML_PAYLOAD, String.class);

        // Make sure the XML was signed
        Assert.assertTrue(signedXml.contains("ds:SignatureValue"));
    } finally {
        camelctx.close();
    }
}
 
Example #12
Source File: CouchbaseIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testComponent() throws Exception {
    initCouchbaseServer();

    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            fromF("couchbase:http://%s/beer-sample?password=&designDocumentName=beer&viewName=brewery_beers&limit=10", TestUtils.getDockerHost())
            .to("mock:result");
        }
    });

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedMessageCount(10);

    camelctx.start();
    try {
        mockEndpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example #13
Source File: FileCopierWithCamel.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create CamelContext
    CamelContext context = new DefaultCamelContext();

    // add our route to the CamelContext
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("file:data/inbox?noop=true").to("file:data/outbox");
        }
    });

    // start the route and let it do its work
    context.start();
    Thread.sleep(10000);

    // stop the CamelContext
    context.stop();
}
 
Example #14
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapV1_2Unmarshal() throws Exception {

    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");
    format.setVersion("1.2");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .unmarshal(format);
        }
    });

    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope-1.2-unmarshal.xml")) {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Element response = producer.requestBody("direct:start", input, Element.class);
        Assert.assertEquals("Customer", response.getLocalName());
    } finally {
        camelctx.close();
    }
}
 
Example #15
Source File: JCacheProducerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testJCacheLoadsCachingProviderEhcache() throws Exception {
	
    try (CamelContext camelctx = new DefaultCamelContext()) {
    	
        camelctx.addRoutes(new RouteBuilder() {
            public void configure() {
                from("jcache://test-cacheB?cachingProvider=org.ehcache.jsr107.EhcacheCachingProvider")
                .to("mock:resultB");
            }
        });
        
        // Just ensure we can start up without any class loading issues
        camelctx.start();
    }
}
 
Example #16
Source File: DropboxIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropboxProducer() throws Exception {
    Assume.assumeNotNull("DROPBOX_ACCESS_TOKEN is null", DROPBOX_ACCESS_TOKEN);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("dropbox://get?accessToken=%s&clientIdentifier=CamelTesting&remotePath=/hello.txt", DROPBOX_ACCESS_TOKEN);
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        byte[] result = template.requestBody("direct:start", null, byte[].class);
        Assert.assertEquals("Hello Kermit\n", new String(result));
    } finally {
        camelctx.close();
    }
}
 
Example #17
Source File: MustacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testMustacheComponent() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("mustache:classpath:template.mustache");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Exchange response = template.request("direct:start", exchange -> {
            exchange.getIn().setHeader("greeting", "Hello");
            exchange.getIn().setHeader("name", "Kermit");
        });

        Assert.assertEquals("Hello Kermit!", response.getOut().getBody(String.class));
    } finally {
        camelctx.close();
    }
}
 
Example #18
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapUnmarshal() throws Exception {

    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .unmarshal(format);
        }
    });

    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope.xml")) {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Element response = producer.requestBody("direct:start", input, Element.class);
        Assert.assertEquals("Customer", response.getLocalName());
    } finally {
        camelctx.close();
    }
}
 
Example #19
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testODataRouteWithKeyPredicate() throws Exception {
    String keyPredicate = "1";
    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, defaultTestServer.servicePlainUri())
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, defaultTestServer.resourcePath());
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, TEST_SERVER_DATA_1);
}
 
Example #20
Source File: RoutesLoaderTest.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@MethodSource("parameters")
public void testLoaders(String location, Class<? extends SourceLoader> type) throws Exception {
    TestRuntime runtime = new TestRuntime();
    Source source = Sources.fromURI(location);
    SourceLoader loader = RoutesConfigurer.load(runtime, source);

    assertThat(loader).isInstanceOf(type);
    assertThat(runtime.builders).hasSize(1);
    assertThat(runtime.builders).first().isInstanceOf(RouteBuilder.class);

    RouteBuilder builder = (RouteBuilder)runtime.builders.get(0);
    builder.setContext(runtime.getCamelContext());
    builder.configure();

    List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
    assertThat(routes).hasSize(1);
    assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick");
    assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}
 
Example #21
Source File: AvroDataFormatTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testMarshalUnmarshal() throws Exception {

    DataFormat avro = new AvroDataFormat(getSchema());
    GenericRecord input = new GenericData.Record(getSchema());
    input.put("name", "Kermit");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(avro).unmarshal(avro);
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        GenericRecord result = producer.requestBody("direct:start", input, GenericRecord.class);
        Assert.assertEquals("Kermit", result.get("name").toString());
    } finally {
        camelctx.close();
    }
}
 
Example #22
Source File: CdiSimpleProcessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
    service1 = (MockEndpoint) camelContext.getEndpoint("mock:service1");
    service1.reset();
    service2 = (MockEndpoint) camelContext.getEndpoint("mock:service2");
    service2.reset();
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("flowable:camelProcess");
            from("flowable:camelProcess:serviceTask1").setBody().exchangeProperty("var1").to("mock:service1").setProperty("var2").constant("var2").setBody().exchangeProperties();
            from("direct:receive").to("flowable:camelProcess:receive");
            from("flowable:camelProcess:serviceTask2?copyVariablesToBodyAsMap=true").to("mock:service2");
        }
    });
}
 
Example #23
Source File: MvelTransformTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTransformFromModule() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mvel:template.mvel");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example #24
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapV1_2Marshal() throws Exception {

    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(format);
        }
    });

    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope-1.2-marshal.xml")) {
        String expected = camelctx.getTypeConverter().mandatoryConvertTo(String.class, input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String customerXML = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(customerXML));
    } finally {
        camelctx.close();
    }
}
 
Example #25
Source File: ClientCamelSplitterParallelITest.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
@Override
public RouteBuilder getRouteBuilder() {
    XPathBuilder xPathBuilder = new XPathBuilder("/order/item");

    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("file:src/test/data/camel/splitter?noop=true")
            .split(xPathBuilder)
            .parallelProcessing()
            .setHeader("LineItemId")
            .xpath("/item/@id", String.class)
            .to("file:target/data/camel/splitter?fileName="
                    + "${in.header.LineItemId}-${date:now:yyyyMMddHHmmssSSSSS}.xml");
        }
    };
}
 
Example #26
Source File: KnativeHttpTest.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(CloudEvents.class)
void testInvokeNotExistingEndpoint(CloudEvent ce) throws Exception {
    configureKnativeComponent(
        context,
        ce,
        endpoint(
            Knative.EndpointKind.sink,
            "test",
            "localhost",
            platformHttpPort,
            mapOf(
                Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
                Knative.CONTENT_TYPE, "text/plain"
            )
        )
    );

    RouteBuilder.addRoutes(context, b -> {
        b.from("direct:start")
            .to("knative:endpoint/test")
            .to("mock:start");
    });

    context.start();

    Exchange exchange = template.request("direct:start", e -> e.getMessage().setBody(""));
    assertThat(exchange.isFailed()).isTrue();
    assertThat(exchange.getException()).isInstanceOf(CamelException.class);
    assertThat(exchange.getException()).hasMessageStartingWith("HTTP operation failed invoking http://localhost:" + platformHttpPort + "/");
}
 
Example #27
Source File: SplunkIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSalesforceQuery() throws Exception {

    String SPLUNK_USERNAME = System.getenv("SPLUNK_USERNAME");
    String SPLUNK_PASSWORD = System.getenv("SPLUNK_PASSWORD");
    Assume.assumeNotNull("[#1673] Enable Splunk testing in Jenkins", SPLUNK_USERNAME, SPLUNK_PASSWORD);

    SplunkEvent splunkEvent = new SplunkEvent();
    splunkEvent.addPair("key1", "value1");
    splunkEvent.addPair("key2", "value2");
    splunkEvent.addPair("key3", "value1");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:submit")
            .to("splunk://submit?username=" + SPLUNK_USERNAME + "&password=" + SPLUNK_PASSWORD + "&sourceType=testSource&source=test")
            .to("mock:result");
        }
    });

    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMinimumMessageCount(1);

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:submit", splunkEvent);
        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example #28
Source File: PurchaseOrderBindyTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public RouteBuilder createRoute() {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:toCsv")
                    .marshal().bindy(BindyType.Csv, camelinaction.bindy.PurchaseOrder.class)
                    .to("mock:result");
        }
    };
}
 
Example #29
Source File: MetricsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetricsJsonSerialization() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    MetricRegistry metricRegistry = new MetricRegistry();
    registry.bind("metricRegistry", metricRegistry);

    MetricsMessageHistoryFactory messageHistoryFactory = new MetricsMessageHistoryFactory();
    messageHistoryFactory.setMetricsRegistry(metricRegistry);

    CamelContext camelctx = new DefaultCamelContext(registry);
    camelctx.setMessageHistoryFactory(messageHistoryFactory);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("metrics:counter:simple.counter?increment=5");
        }
    });

    camelctx.start();
    try {
        MetricsMessageHistoryService service = camelctx.hasService(MetricsMessageHistoryService.class);
        String json = service.dumpStatisticsAsJson();
        Assert.assertTrue(json.contains("\"gauges\":{},\"counters\":{},\"histograms\":{},\"meters\":{},\"timers\":{}"));
    } finally {
        camelctx.close();
    }
}
 
Example #30
Source File: ParameterBindingTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterBinding() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").bean(OrderBean.class);
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBodyAndHeader("direct:start", 100, "customerId", 200, String.class);
        Assert.assertEquals("Order 100 from customer 200", result);
    } finally {
        camelctx.close();
    }
}