use of org.apache.camel.CamelContext in project camel by apache.
the class MainTest method createCamelContext.
private CamelContext createCamelContext(String[] options) throws Exception {
Main main = new Main();
main.parseArguments(options);
ApplicationContext applicationContext = main.createDefaultApplicationContext();
CamelContext context = SpringCamelContext.springCamelContext(applicationContext);
return context;
}
use of org.apache.camel.CamelContext in project camel by apache.
the class SpringLdapComponent method createEndpoint.
/**
* creates a Spring LDAP endpoint
* @param remaining name of the Spring LDAP template bean to be used for the LDAP operation
* @param parameters key-value pairs to be set on @see org.apache.camel.component.springldap.SpringLdapEndpoint.
* Currently supported keys are operation and scope.
* 'operation' is defined in org.apache.camel.component.springldap.LdapOperation.
* 'scope' must be one of "object", "onelevel", or "subtree".
*/
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
CamelContext camelContext = getCamelContext();
Registry registry = camelContext.getRegistry();
LdapTemplate ldapTemplate = registry.lookupByNameAndType(remaining, LdapTemplate.class);
Endpoint endpoint = new SpringLdapEndpoint(remaining, ldapTemplate);
setProperties(endpoint, parameters);
return endpoint;
}
use of org.apache.camel.CamelContext in project camel by apache.
the class MyObject method deserialize.
@Test
public void deserialize() throws IOException, ClassNotFoundException {
CamelContext context = new DefaultCamelContext();
final DefaultExchange exchange = new DefaultExchange(context);
final List<MyObject> objects = new ArrayList<>();
final MyObject o = new MyObject("leb", "hello".getBytes());
objects.add(o);
exchange.getIn().setBody(objects);
final DefaultExchangeHolder deh = DefaultExchangeHolder.marshal(exchange);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(deh);
oos.flush();
final byte[] serialized = baos.toByteArray();
final ObjectInputStream bis = new ClassLoadingAwareObjectInputStream(context, new ByteArrayInputStream(serialized));
final DefaultExchangeHolder deserialized = (DefaultExchangeHolder) bis.readObject();
final DefaultExchange exchange2 = new DefaultExchange(context);
DefaultExchangeHolder.unmarshal(exchange2, deserialized);
List<MyObject> receivedObjects = exchange2.getIn().getBody(List.class);
assertEquals(1, receivedObjects.size());
assertEquals(o, receivedObjects.get(0));
}
use of org.apache.camel.CamelContext in project camel by apache.
the class CamelTestSupport method doSetUp.
private void doSetUp() throws Exception {
log.debug("setUp test");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext) c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
threadCamelContext.set(context);
assertNotNull(context, "No context found!");
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(getShutdownTimeout());
// set debugger if enabled
if (isUseDebugger()) {
context.setDebugger(new DefaultDebugger());
context.getDebugger().addBreakpoint(breakpoint);
// note: when stopping CamelContext it will automatic remove the breakpoint
}
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
threadTemplate.set(template);
threadConsumer.set(consumer);
// enable auto mocking if enabled
String pattern = isMockEndpoints();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
}
pattern = isMockEndpointsAndSkip();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true));
}
// configure properties component (mandatory for testing)
context.getComponent("properties", PropertiesComponent.class);
postProcessTest();
if (isUseRouteBuilder()) {
RoutesBuilder[] builders = createRouteBuilders();
for (RoutesBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
} else if (isUseAdviceWith()) {
log.info("Skipping starting CamelContext as isUseAdviceWith is set to true.");
} else {
startCamelContext();
}
} else {
log.debug("Using route builder from the created context: " + context);
}
log.debug("Routing Rules are: " + context.getRoutes());
assertValidContext(context);
INIT.set(true);
}
use of org.apache.camel.CamelContext in project camel by apache.
the class TestSupport method getRouteList.
/**
* A helper method to create a list of Route objects for a given route builder
*/
public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(builder);
context.start();
List<Route> answer = context.getRoutes();
context.stop();
return answer;
}
Aggregations