Package org.springframework.context.support

Examples of org.springframework.context.support.AbstractApplicationContext


    // 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");
        CamelContext camel = context.getBean("camel-client", CamelContext.class);

        // get the endpoint from the camel context
        Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");

        // create the exchange used for the communication
        // we use the in out pattern for a synchronized exchange where we expect a response
        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
        // set the input on the in body
        // must be correct type to match the expected type of an Integer object
        exchange.getIn().setBody(11);

        // to send the exchange we need an producer to do it for us
        Producer producer = endpoint.createProducer();
        // start the producer so it can operate
        producer.start();

        // let the producer process the exchange where it does all the work in this oneline of code
        System.out.println("Invoking the multiply with 11");
        producer.process(exchange);

        // get the response from the out body and cast it to an integer
        int response = exchange.getOut().getBody(Integer.class);
        System.out.println("... the result is: " + response);

        // stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly
        // closed, making this client not to try any further reads for the replies from the server
        producer.stop();

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


    }

    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)
        final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);

        // now send a lot of messages
        System.out.println("Sending ...");

        final CountDownLatch latch = new CountDownLatch(POOL);

        ExecutorService executors = Executors.newFixedThreadPool(POOL);
        for (int i = 0; i < POOL; i++) {
            final Integer idx = i;
            executors.execute(new Runnable() {
                public void run() {
                    try {
                        for (int j = 0; j < SIZE / POOL; j++) {
                            producer.sendBody("jms:queue:inbox", "Message " + idx.intValue() * j + j);
                        }
                    } finally {
                        latch.countDown();
                    }
                }
            });
        }

        latch.await(300, TimeUnit.SECONDS);
        System.out.println("... Send " + SIZE + " message to JMS broker");
        executors.shutdownNow();

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

    private CamelFileClient() {
        // Helper class
    }

    public static void main(final String[] args) throws Exception {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");

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

        // now send a lot of messages
        System.out.println("Writing files ...");

        for (int i = 0; i < SIZE; i++) {
            producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
        }

        System.out.println("... Wrote " + SIZE + " files");

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

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

    private CamelContext context1;
    private ProducerTemplate template1;

    @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 CamelContext context2;
    private ProducerTemplate template2;

    @Before
    public void setUp() throws Exception {
        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml");
        context2 = SpringCamelContext.springCamelContext(ac, false);
        context2.start();

        template2 = context2.createProducerTemplate();
        template2.start();
View Full Code Here

public class DefaultStreamCachingTest extends TestCase {
   
   
    public void testStreamCaching() throws Exception {
        AbstractApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"org/apache/camel/spring/streamCaching.xml"});
        CamelContext camelContext = appContext.getBean("camelContext", CamelContext.class);
        assertFalse("StreamCaching should not be enabled", camelContext.isStreamCaching());

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

* @version
*/
public class RouteBuilderRefTest extends XmlConfigTestSupport {

    public void testUsingRouteBuilderRefInCamelXml() throws Exception {
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/routeBuilderRef.xml");

        CamelContext context = applicationContext.getBean("camel5", CamelContext.class);
        assertValidContext(context);

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

* @version
*/
public class CamelProxyTest extends TestSupport {

    public void testCamelProxy() throws Exception {
        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml");

        MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
        String reply = sender.hello("World");

        assertEquals("Hello World", reply);
       
        // test sending inOnly message
        MyProxySender anotherSender = ac.getBean("myAnotherProxySender", MyProxySender.class);
        SpringCamelContext context = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
        MockEndpoint result = resolveMandatoryEndpoint(context, "mock:result", MockEndpoint.class);
        result.expectedBodiesReceived("Hello my friends!");
       
        anotherSender.greeting("Hello my friends!");
        result.assertIsSatisfied();
       
        result.reset();
        // test sending inOnly message with other sender
        MyProxySender myProxySenderWithCamelContextId = ac.getBean("myProxySenderWithCamelContextId", MyProxySender.class);
       
        result.expectedBodiesReceived("Hello my friends again!");
        myProxySenderWithCamelContextId.greeting("Hello my friends again!");
        result.assertIsSatisfied();

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

*/
public class AnotherCamelProxyTest extends TestCase {

    public void testAnotherCamelProxy() throws Exception {
        // START SNIPPET: e1
        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");

        MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
        String reply = sender.hello("Camel");

        assertEquals("Bye Camel", reply);

        // we're done so let's properly close the application context
        ac.close();
        // END SNIPPET: e1
    }
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.