Package org.springframework.context.support

Examples of org.springframework.context.support.AbstractApplicationContext


    }

    public void configure(Object beanInstance) {
        // check the ApplicationContext states first , and call the refresh if necessary
        if (((SpringCamelContext)getCamelContext()).getApplicationContext() instanceof AbstractApplicationContext) {
            AbstractApplicationContext context = (AbstractApplicationContext)((SpringCamelContext)getCamelContext()).getApplicationContext();
            if (!context.isActive()) {
                context.refresh();
            }
        }
        configurer.configureBean(beanId, beanInstance);
    }
View Full Code Here


     * @throws Exception the test failed
     */
    public void testAvalonIntoSpringIntegration() throws Exception
    {
        SpringFrameworkService service = (SpringFrameworkService) this.container.lookup("springFrameworkService");
        AbstractApplicationContext ctx = service.getAbstractApplicationContext();
       
        // ensure that the Avalon SystemPropertyService updated the system properties (so it was properly started)
        assertTrue(System.getProperty("FOO").equals("BAR"));

        CustomAvalonService customAvalonService;
        CustomSpringService customSpringService;
        SystemPropertyService systemPropertyService;
        ServiceManager serviceManager = (ServiceManager) ctx.getBean("avalonContainerBean");

        // lookup and use the Spring bean using Spring's context
        systemPropertyService = (SystemPropertyService) ctx.getBean("systemPropertyService");
        assertNotNull(systemPropertyService);

        // lookup and use the Spring bean using Spring's context
        customSpringService = (CustomSpringService) ctx.getBean("customSpringService");
        customSpringService.sayGretting();
        assertEquals(customSpringService.getGreeting(), GREETING);

        // lookup and use the Spring bean using Avalon's Service Manager
        customSpringService = (CustomSpringService) serviceManager.lookup("customSpringService");
        customSpringService.sayGretting();
        assertEquals(customSpringService.getGreeting(), GREETING);

        // lookup and use the Avalon service using Spring's context
        customAvalonService = (CustomAvalonService) ctx.getBean("customAvalonService");
        customAvalonService.sayGretting();
        assertEquals(customAvalonService.getGreeting(), GREETING);
       
        // lookup and use the Avalon service using Avalon's Service Manager
        customAvalonService = (CustomAvalonService) serviceManager.lookup("customAvalonService");
        customAvalonService.sayGretting();
        assertEquals(customAvalonService.getGreeting(), GREETING);

        // try to find a non-existing service using Avalon's Service Manager
        try
        {
            serviceManager.lookup("foo");
            fail("Looking up a non-existing service must throw a ServiceException");
        }
        catch(ServiceException e)
        {
            // nothing to do
        }
        catch(Exception e)
        {
            fail("Looking up a non-existing service must throw a ServiceException");
        }

        // try to find a non-existing service using Spring's context
        try
        {
            ctx.getBean("foo");
            fail("Looking up a non-existing service must throw a BeansException");
        }
        catch(BeansException e)
        {
            // nothing to do
View Full Code Here

    private ProducerTemplate template1;
    private ProducerTemplate template2;

    @Before
    public void setUp() throws Exception {
        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest1.xml");
        context1 = SpringCamelContext.springCamelContext(ac, false);
        context1.start();
       
        template1 = context1.createProducerTemplate();
        template1.start();
View Full Code Here

//    private Object createApplicationContext(SCAParentApplicationContext scaParentContext) {

    private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, URL resource) {

        XmlBeanFactory beanFactory = new XmlBeanFactory(new UrlResource(resource));
        AbstractApplicationContext appContext = null;
       
        for (String bean : beanFactory.getBeanDefinitionNames()) {
                String beanClassName = (beanFactory.getType(bean)).getName();
                if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1 ||
                                beanClassName.indexOf(".FileSystemXmlApplicationContext") != -1)
                {
                        BeanDefinition beanDef = beanFactory.getBeanDefinition(bean);                          
                        String[] listValues = null;
                        List<ConstructorArgumentValues.ValueHolder> conArgs =
                                beanDef.getConstructorArgumentValues().getGenericArgumentValues();
                        for (ConstructorArgumentValues.ValueHolder conArg : conArgs) {
                                if (conArg.getValue() instanceof TypedStringValue) {
                                        TypedStringValue value = (TypedStringValue) conArg.getValue();
                                        if (value.getValue().indexOf(".xml") != -1)
                                                listValues = new String[]{value.getValue()};
                                }
                                if (conArg.getValue() instanceof ManagedList) {
                                        Iterator itml = ((ManagedList)conArg.getValue()).iterator();
                                        StringBuffer values = new StringBuffer();
                                        while (itml.hasNext()) {
                                                TypedStringValue next = (TypedStringValue)itml.next();
                                                if (next.getValue().indexOf(".xml") != -1) {
                                                        values.append(next.getValue());
                                                        values.append("~");
                                                }
                                        }
                                        listValues = (values.toString()).split("~");                                   
                                }
                        }
                       
                        if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {                                                                  
                                appContext = new ClassPathXmlApplicationContext(listValues, false, scaParentContext);                                  
                                appContext.refresh();
                                includeAnnotationProcessors(appContext.getBeanFactory());
                                return appContext;
                        } else {
                                appContext = new FileSystemXmlApplicationContext(listValues, false, scaParentContext);                                 
                                appContext.refresh();
                                includeAnnotationProcessors(appContext.getBeanFactory());
                                return appContext;
                        }
                }              
        }
       
View Full Code Here

     * with the main configuration context as the parent
     * of the embedded Web Service context.
     */
    @BeforeClass
    public static void init() throws Exception {
        AbstractApplicationContext ctx =
            new ClassPathXmlApplicationContext("/org/springbyexample/ws/embedded/embedded-jetty-context.xml");
        ctx.registerShutdownHook();
       
        Server server = (Server) ctx.getBean("jettyServer");
       
        ServletContext servletContext = null;
       
        for (Handler handler : server.getHandlers()) {
            if (handler instanceof Context) {
View Full Code Here

   
    @Test
    public void startLoanBroker() throws Exception {
        deleteDirectory("activemq-data");

        AbstractApplicationContext applicationContext =
            new ClassPathXmlApplicationContext(new String[]{"/META-INF/spring/queueCamelContext.xml"});

        CamelContext camelContext = (CamelContext)applicationContext.getBean("myCamel");
        assertNotNull("The camel context should not be null", camelContext);

        Thread.sleep(2000);
        camelContext.stop();
        applicationContext.stop();       
    }
View Full Code Here

//    private Object createApplicationContext(SCAParentApplicationContext scaParentContext) {

    private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, URL resource) {

        XmlBeanFactory beanFactory = new XmlBeanFactory(new UrlResource(resource));
        AbstractApplicationContext appContext = null;
       
        for (String bean : beanFactory.getBeanDefinitionNames()) {
                String beanClassName = (beanFactory.getType(bean)).getName();
                if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1 ||
                                beanClassName.indexOf(".FileSystemXmlApplicationContext") != -1)
                {
                        BeanDefinition beanDef = beanFactory.getBeanDefinition(bean);                          
                        String[] listValues = null;
                        List<ConstructorArgumentValues.ValueHolder> conArgs =
                                beanDef.getConstructorArgumentValues().getGenericArgumentValues();
                        for (ConstructorArgumentValues.ValueHolder conArg : conArgs) {
                                if (conArg.getValue() instanceof TypedStringValue) {
                                        TypedStringValue value = (TypedStringValue) conArg.getValue();
                                        if (value.getValue().indexOf(".xml") != -1)
                                                listValues = new String[]{value.getValue()};
                                }
                                if (conArg.getValue() instanceof ManagedList) {
                                        Iterator itml = ((ManagedList)conArg.getValue()).iterator();
                                        StringBuffer values = new StringBuffer();
                                        while (itml.hasNext()) {
                                                TypedStringValue next = (TypedStringValue)itml.next();
                                                if (next.getValue().indexOf(".xml") != -1) {
                                                        values.append(next.getValue());
                                                        values.append("~");
                                                }
                                        }
                                        listValues = (values.toString()).split("~");                                   
                                }
                        }
                       
                        if (beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {                                                                  
                                appContext = new ClassPathXmlApplicationContext(listValues, false, scaParentContext);                                  
                                appContext.refresh(); // TODO why is this needed here now?
                                includeAnnotationProcessors(appContext.getBeanFactory());
                                return appContext;
                        } else {
                                appContext = new FileSystemXmlApplicationContext(listValues, false, scaParentContext);                                 
                                appContext.refresh(); // TODO why is this needed here now?
                                includeAnnotationProcessors(appContext.getBeanFactory());
                                return appContext;
                        }
                }              
        }
       
View Full Code Here

        deleteDirectory("activemq-data");
       
        JmsBroker broker = new JmsBroker("tcp://localhost:61616");
        broker.start();
        try {
            AbstractApplicationContext applicationContext =
                new ClassPathXmlApplicationContext(new String[]{"/META-INF/spring/queueCamelContext.xml"});
   
            CamelContext camelContext = (CamelContext)applicationContext.getBean("queue");
            assertNotNull("The camel context should not be null", camelContext);
   
            Thread.sleep(2000);
            camelContext.stop();
            applicationContext.stop();
        } finally {
            broker.stop();
        }
    }
View Full Code Here

    // START SNIPPET: e1
    public static void main(final String[] args) {
        System.out.println("Notice this client requires that the CamelServer is already running!");

        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
        // just get the proxy to the service and we as the client can use the "proxy" as it was
        // a local object we are invoking. Camel will under the covers do the remote communication
        // to the remote ActiveMQ server and fetch the response.
        Multiplier multiplier = context.getBean("multiplierProxy", Multiplier.class);

        System.out.println("Invoking the multiply with 33");
        int response = multiplier.multiply(33);
        System.out.println("... the result is: " + response);

        // we're done so let's properly close the application context
        context.close();
    }
View Full Code Here

    // START SNIPPET: e1
    public static void main(final String[] args) throws Exception {
        System.out.println("Notice this client requires that the CamelServer is already running!");

        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

        // get the camel template for Spring template style sending of messages (= producer)
        ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

        System.out.println("Invoking the multiply with 22");
        // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
        int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
        System.out.println("... the result is: " + response);

        // we're done so let's properly close the application context
        context.close();
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.support.AbstractApplicationContext

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.