Package org.apache.camel.spring

Examples of org.apache.camel.spring.SpringCamelContext


        try {
            List<CamelJbiEndpoint> services = new ArrayList<CamelJbiEndpoint>(activatedEndpoints);
            activatedEndpoints.clear();

            ApplicationContext applicationContext = springLoader.getApplicationContext();
            SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);

            // now lets iterate through all the endpoints
            Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();

            for (Endpoint endpoint : endpoints) {
                if (component.isEndpointExposedOnNmr(endpoint)) {
                    services.add(component.createJbiEndpointFromCamel(endpoint));
                }
            }

            // lets add a control bus endpoint to ensure we have at least one endpoint to deploy
            BeanComponent beanComponent = camelContext.getComponent("bean", BeanComponent.class);
            Endpoint endpoint = beanComponent.createEndpoint(new CamelControlBus(camelContext),
                                                             "camel:" + serviceUnitName + "-controlBus");
            services.add(component.createJbiEndpointFromCamel(endpoint));

            return services;
View Full Code Here


    };
  }
 
    protected CamelContext createCamelContext() throws Exception {
        spring = new ClassPathXmlApplicationContext("org/apache/camel/component/jms/spring.xml");
        SpringCamelContext ctx =  SpringCamelContext.springCamelContext(spring);
        PlatformTransactionManager transactionManager = (PlatformTransactionManager) spring.getBean("jmsTransactionManager");
        ConnectionFactory connectionFactory = (ConnectionFactory) spring.getBean("jmsConnectionFactory");
        JmsComponent component = JmsComponent.jmsComponentTransacted(connectionFactory, transactionManager);
        component.getConfiguration().setConcurrentConsumers(1);
    ctx.addComponent("activemq", component);
        return ctx;
    }
View Full Code Here

    }

    protected List<Route> getRoutesFromContext(String classpathConfigFile) {
        applicationContext = new ClassPathXmlApplicationContext(classpathConfigFile);
        String name = "camel";
        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean(name);
        assertNotNull("No Camel Context for name: " + name + " in file: " + classpathConfigFile, context);
        List<Route> routes = context.getRoutes();
        assertNotNull("No routes available for context: " + name + " in file: " + classpathConfigFile, routes);
        return routes;
    }
View Full Code Here

        }
        this.bundleContext = bundleContext;
    }
   
    protected SpringCamelContext createContext() {
        SpringCamelContext context = super.createContext();
        if (bundleContext != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Using OSGI resolvers");
            }
            updateRegistry(context);
            LOG.debug("Using OsgiFactoryFinderResolver");
            context.setFactoryFinderResolver(new OsgiFactoryFinderResolver());
            LOG.debug("Using OsgiPackageScanClassResolver");
            context.setPackageScanClassResolver(new OsgiPackageScanClassResolver(bundleContext));
            LOG.debug("Using OsgiComponentResolver");
            context.setComponentResolver(new OsgiComponentResolver());
            LOG.debug("Using OsgiLanguageResolver");
            context.setLanguageResolver(new OsgiLanguageResolver());
            addOsgiAnnotationTypeConverterLoader(context);
        } else {
            // TODO: should we not thrown an exception to not allow it to startup
            LOG.warn("BundleContext not set, cannot run in OSGI container");
        }
View Full Code Here

        this.applicationContext = context;
    }
   
    @Override
    protected DefaultCamelContext newCamelContext() {
        return new SpringCamelContext(applicationContext);
    }
View Full Code Here

    private static final transient Log LOG = LogFactory.getLog(CamelContextAutoStartupTest.class);

    public void testAutoStartupFalse() throws Exception {
        ApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml");

        SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
        assertEquals("myCamel", camel.getName());
        assertEquals(false, camel.isStarted());
        assertEquals(false, camel.isAutoStartup());
        assertEquals(0, camel.getRoutes().size());

        // now start Camel
        LOG.info("******** now starting Camel manually *********");
        camel.start();

        // now its started
        assertEquals(true, camel.isStarted());
        // but auto startup is still fasle
        assertEquals(false, camel.isAutoStartup());
        // but now we have one route
        assertEquals(1, camel.getRoutes().size());

        // and now we can send a message to the route and see that it works
        MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMessageCount(1);

        camel.createProducerTemplate().sendBody("direct:start", "Hello World");

        mock.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testAutoStartupTrue() throws Exception {
        ApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestTrue.xml");

        SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
        assertEquals("myCamel", camel.getName());
        assertEquals(true, camel.isStarted());
        assertEquals(true, camel.isAutoStartup());
        assertEquals(1, camel.getRoutes().size());

        // send a message to the route and see that it works
        MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMessageCount(1);

        camel.createProducerTemplate().sendBody("direct:start", "Hello World");

        mock.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testAutoStartup() throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml");

        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean("camel4");
        assertNotNull("No context found!", context);       
        assertFalse("The context should not start yet", context.isAutoStartup());
        assertEquals("There should have not route", context.getRoutes().size(), 0);
        context = (SpringCamelContext) applicationContext.getBean("camel3");
        assertTrue("The context should started",  context.isAutoStartup());
        assertEquals("There should have one route", context.getRoutes().size(), 1);
    }
View Full Code Here

    protected void setupCamelContext(CamelContext camelContext) throws Exception {
       
    }
   
    protected CamelContext createCamelContext() throws Exception {
        return new SpringCamelContext(getApplicationContext());
    }
View Full Code Here

        BusFactory busFactory = BusFactory.newInstance();
        // need to check if the camelContext is SpringCamelContext and
        // update the bus configuration with the applicationContext
        // which SpringCamelContext holds
        if (getCamelContext() instanceof SpringCamelContext) {
            SpringCamelContext springCamelContext = (SpringCamelContext) getCamelContext();
            ApplicationContext applicationContext = springCamelContext.getApplicationContext();
            busFactory = new org.apache.cxf.bus.spring.SpringBusFactory(applicationContext);
        }
        return busFactory.createBus();
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.spring.SpringCamelContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.