Search in sources :

Example 26 with CamelContext

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ApplicationContext(org.springframework.context.ApplicationContext)

Example 27 with CamelContext

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) Registry(org.apache.camel.spi.Registry) LdapTemplate(org.springframework.ldap.core.LdapTemplate)

Example 28 with CamelContext

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));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchangeHolder(org.apache.camel.impl.DefaultExchangeHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 29 with CamelContext

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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) InterceptSendToMockEndpointStrategy(org.apache.camel.impl.InterceptSendToMockEndpointStrategy) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RoutesBuilder(org.apache.camel.RoutesBuilder) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 30 with CamelContext

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Route(org.apache.camel.Route)

Aggregations

CamelContext (org.apache.camel.CamelContext)1478 Test (org.junit.Test)691 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)684 RouteBuilder (org.apache.camel.builder.RouteBuilder)448 ProducerTemplate (org.apache.camel.ProducerTemplate)434 ConnectionFactory (javax.jms.ConnectionFactory)220 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)210 Exchange (org.apache.camel.Exchange)109 HashMap (java.util.HashMap)93 Endpoint (org.apache.camel.Endpoint)52 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 IOException (java.io.IOException)46 Map (java.util.Map)45 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)44 CountDownLatch (java.util.concurrent.CountDownLatch)42 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)42 ArrayList (java.util.ArrayList)41 Processor (org.apache.camel.Processor)40 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)37 CamelExecutionException (org.apache.camel.CamelExecutionException)33