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