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);
}
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"));
}
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);
}
}
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;
}
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);
}
Aggregations