Search in sources :

Example 26 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class ExecJava8IssueTest method test.

@Test
public void test() throws Exception {
    if (!OS.isFamilyUnix()) {
        System.err.println("The test 'CamelExecTest' does not support the following OS : " + System.getProperty("os.name"));
        return;
    }
    String tempFilePath = tempDir.getAbsolutePath() + "/" + tempFileName;
    final File script = File.createTempFile("script", ".sh", tempDir);
    writeScript(script);
    final String exec = "bash?args=" + script.getAbsolutePath() + " " + tempFilePath + "&outFile=" + tempFilePath;
    DefaultCamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:source").to("file:" + tempDir.getAbsolutePath() + "?fileName=" + tempFileName).to("exec:" + exec).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    String output = exchange.getIn().getBody(String.class);
                    assertEquals("hello world\n", output);
                }
            });
        }
    });
    context.start();
    ProducerTemplate pt = context.createProducerTemplate();
    String payload = "hello";
    pt.sendBody("direct:source", payload);
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class Main method getCamelContextMap.

protected Map<String, CamelContext> getCamelContextMap() {
    Map<String, CamelContext> answer = new HashMap<String, CamelContext>();
    CamelContext camelContext = createContext();
    if (registry.size() > 0) {
        // set the registry through which we've already bound some beans
        if (DefaultCamelContext.class.isAssignableFrom(camelContext.getClass())) {
            CompositeRegistry compositeRegistry = new CompositeRegistry();
            // make sure camel look up the Object from the registry first
            compositeRegistry.addRegistry(registry);
            // use the camel old registry as a fallback
            compositeRegistry.addRegistry(((DefaultCamelContext) camelContext).getRegistry());
            ((DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
        }
    }
    answer.put("camel-1", camelContext);
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CompositeRegistry(org.apache.camel.impl.CompositeRegistry) HashMap(java.util.HashMap) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 28 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class BeanLookupUsingJndiRegistryIssueTest method testCamelWithJndi.

public void testCamelWithJndi() throws Exception {
    JndiContext jndi = new JndiContext();
    jndi.bind("foo", new MyOtherDummyBean());
    CamelContext camel = new DefaultCamelContext(jndi);
    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").bean("foo");
        }
    });
    camel.start();
    String reply = camel.createProducerTemplate().requestBody("direct:start", "Camel", String.class);
    assertEquals("Hello Camel", reply);
    camel.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) JndiContext(org.apache.camel.util.jndi.JndiContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 29 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class ComponentDiscoveryTest method testComponentDiscovery.

@Test
public void testComponentDiscovery() throws Exception {
    CamelContext context = new DefaultCamelContext();
    SortedMap<String, Properties> map = CamelContextHelper.findComponents(context);
    assertNotNull("Should never return null", map);
    assertTrue("Component map should never be empty", !map.isEmpty());
    String[] expectedComponentNames = { "file", "vm" };
    for (String expectedName : expectedComponentNames) {
        Properties properties = map.get(expectedName);
        assertTrue("Component map contain component: " + expectedName, properties != null);
    }
    Set<Map.Entry<String, Properties>> entries = map.entrySet();
    for (Map.Entry<String, Properties> entry : entries) {
        LOG.info("Found component " + entry.getKey() + " with properties: " + entry.getValue());
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Properties(java.util.Properties) Map(java.util.Map) SortedMap(java.util.SortedMap) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 30 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class RefInvalidTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = new DefaultCamelContext(registry);
    registry.put("foo", context.getEndpoint("seda:foo"));
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)474 CamelContext (org.apache.camel.CamelContext)206 Test (org.junit.Test)183 DefaultExchange (org.apache.camel.impl.DefaultExchange)128 RouteBuilder (org.apache.camel.builder.RouteBuilder)101 Exchange (org.apache.camel.Exchange)91 Before (org.junit.Before)70 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)61 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)38 ESMClass (org.jsmpp.bean.ESMClass)30 ProducerTemplate (org.apache.camel.ProducerTemplate)27 CountDownLatch (java.util.concurrent.CountDownLatch)15 Endpoint (org.apache.camel.Endpoint)13 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)13 Processor (org.apache.camel.Processor)12 RouteStartupOrder (org.apache.camel.spi.RouteStartupOrder)12 Address (org.jsmpp.bean.Address)11 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)11 Date (java.util.Date)10