Search in sources :

Example 51 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class MainTest method testMyMain.

@Test
public void testMyMain() throws Exception {
    Main main = new Main();
    main.setBundleName("MyMainBundle");
    // as we run this test without packing ourselves as bundle, then include ourselves
    main.setIncludeSelfAsBundle(true);
    // setup the blueprint file here
    main.setDescriptors("org/apache/camel/test/blueprint/main-loadfile.xml");
    // set the configAdmin persistent id
    main.setConfigAdminPid("stuff");
    // set the configAdmin persistent file name
    main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
    main.start();
    ProducerTemplate template = main.getCamelTemplate();
    assertNotNull("We should get the template here", template);
    String result = template.requestBody("direct:start", "hello", String.class);
    assertEquals("Get a wrong response", "Bye hello", result);
    main.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 52 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class MainTest method testMainWithoutIncludingTestBundle.

@Test
public void testMainWithoutIncludingTestBundle() throws Exception {
    TinyBundle bundle = TinyBundles.newBundle();
    bundle.add("OSGI-INF/blueprint/camel.xml", getClass().getResourceAsStream("main-loadfile.xml"));
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", SYMBOLIC_NAME).set("Bundle-Version", "1.0.0");
    File tb = File.createTempFile(SYMBOLIC_NAME + "-", ".jar", new File("target"));
    FileOutputStream out = new FileOutputStream(tb);
    IOUtils.copy(bundle.build(), out);
    out.close();
    // simulate `camel:run` which is run after packaging the artifact, so a "bundle" (location with
    // META-INF/MANIFEST.MF) is detected in target/classes
    URLClassLoader loader = new URLClassLoader(new URL[] { tb.toURI().toURL() }, getClass().getClassLoader());
    Main main = new Main();
    main.setLoader(loader);
    // bundle name will be used as filter for blueprint container filter
    main.setBundleName(SYMBOLIC_NAME);
    // don't include test bundle (which is what `mvn camel:run` actually does)
    main.setIncludeSelfAsBundle(false);
    // don't setup the blueprint file here - it'll be picked up from a bundle on classpath
    //main.setDescriptors("none!");
    // set the configAdmin persistent id
    main.setConfigAdminPid("stuff");
    // set the configAdmin persistent file name
    main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
    main.doStart();
    ProducerTemplate template = main.getCamelTemplate();
    assertNotNull("We should get the template here", template);
    String result = template.requestBody("direct:start", "hello", String.class);
    assertEquals("Get a wrong response", "Bye hello", result);
    main.stop();
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) ProducerTemplate(org.apache.camel.ProducerTemplate) FileOutputStream(java.io.FileOutputStream) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Test(org.junit.Test)

Example 53 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class CamelFileClient method main.

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

Example 54 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project Activiti by Activiti.

the class InitiatorCamelCallTest method testInitiatorCamelCall.

@Deployment
public void testInitiatorCamelCall() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    String body = "body text";
    Exchange exchange = ctx.getEndpoint("direct:startWithInitiatorHeader").createExchange();
    exchange.getIn().setBody(body);
    tpl.send("direct:startWithInitiatorHeader", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    String initiator = (String) runtimeService.getVariable(instanceId, "initiator");
    assertEquals("kermit", initiator);
    Object camelInitiatorHeader = runtimeService.getVariable(instanceId, "CamelProcessInitiatorHeader");
    assertNull(camelInitiatorHeader);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 55 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project Activiti by Activiti.

the class CamelVariableTransferTest method testCamelPropertiesAll.

// check that at least all properties are passed from camel to activiti when copyVariablesFromProperties=true is simply true
@Deployment
public void testCamelPropertiesAll() throws Exception {
    ProducerTemplate tpl = camelContext.createProducerTemplate();
    Exchange exchange = camelContext.getEndpoint("direct:startAllProperties").createExchange();
    tpl.send("direct:startAllProperties", exchange);
    assertNotNull(taskService);
    assertNotNull(runtimeService);
    assertEquals(1, taskService.createTaskQuery().count());
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    Map<String, Object> variables = runtimeService.getVariables(task.getExecutionId());
    assertEquals("sampleValueForProperty1", variables.get("property1"));
    assertEquals("sampleValueForProperty2", variables.get("property2"));
    assertEquals("sampleValueForProperty3", variables.get("property3"));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Task(org.activiti.engine.task.Task) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3