Search in sources :

Example 6 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class RouteBuilderRefTest method testUsingRouteBuilderRefInCamelXml.

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
    IOHelper.close(applicationContext);
}
Also used : CamelContext(org.apache.camel.CamelContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 7 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class ProducerBeanInjectTest method checkProducerBeanInjection.

@Test
public void checkProducerBeanInjection() {
    AbstractApplicationContext applicationContext = createApplicationContext();
    MyProduceBean bean = applicationContext.getBean("myProduceBean", MyProduceBean.class);
    assertNotNull("The producerTemplate should not be null.", bean.getProducerTemplate());
    assertEquals("Get a wrong response", "Camel rocks!", bean.getProducerTemplate().requestBody("Camel"));
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Test(org.junit.Test)

Example 8 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class Main method createDefaultApplicationContext.

protected AbstractApplicationContext createDefaultApplicationContext() throws IOException {
    ApplicationContext parentContext = getParentApplicationContext();
    // file based
    if (getFileApplicationContextUri() != null) {
        String[] args = getFileApplicationContextUri().split(";");
        if (parentContext != null) {
            return new FileSystemXmlApplicationContext(args, parentContext);
        } else {
            return new FileSystemXmlApplicationContext(args);
        }
    }
    // default to classpath based
    String[] args = getApplicationContextUri().split(";");
    if (parentContext != null) {
        return new ClassPathXmlApplicationContext(args, parentContext);
    } else {
        return new ClassPathXmlApplicationContext(args);
    }
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 9 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class CamelSpringTestSupport method doCreateApplicationContext.

private AbstractApplicationContext doCreateApplicationContext() {
    AbstractApplicationContext context = createApplicationContext();
    assertNotNull("Should have created a valid Spring application context", context);
    String[] profiles = activeProfiles();
    if (profiles != null && profiles.length > 0) {
        // the context must not be active
        if (context.isActive()) {
            throw new IllegalStateException("Cannot active profiles: " + Arrays.asList(profiles) + " on active Spring application context: " + context + ". The code in your createApplicationContext() method should be adjusted to create the application context with refresh = false as parameter");
        }
        log.info("Spring activating profiles: {}", Arrays.asList(profiles));
        context.getEnvironment().setActiveProfiles(profiles);
    }
    // ensure the context has been refreshed at least once
    if (!context.isActive()) {
        context.refresh();
    }
    return context;
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext)

Example 10 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class CamelClientEndpoint method main.

// 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
    IOHelper.close(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Endpoint(org.apache.camel.Endpoint)

Aggregations

AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)27 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 Test (org.junit.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)6 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)3 ComponentLifecycle (com.cloud.utils.component.ComponentLifecycle)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 Method (java.lang.reflect.Method)2 AfterClass (org.junit.AfterClass)2 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)2 StopWatch (org.springframework.util.StopWatch)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 Result (com.openmeap.services.dto.Result)1 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)1