org.apache.camel.ProducerTemplate Java Examples
The following examples show how to use
org.apache.camel.ProducerTemplate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XSLTIntegrationTest.java From wildfly-camel with Apache License 2.0 | 7 votes |
@Test public void testQueryTransform() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { Namespaces ns = new Namespaces("ns", "http://org/wildfly/test/jaxb/model/Customer"); from("direct:start").transform().xquery("/ns:customer/ns:firstName", String.class, ns) .to("mock:result"); } }); camelctx.start(); try { //System.out.println(readCustomerXml()); ProducerTemplate producer = camelctx.createProducerTemplate(); String customer = producer.requestBody("direct:start", readCustomerXml("/customer.xml"), String.class); Assert.assertEquals("John", customer); } finally { camelctx.close(); } }
Example #2
Source File: CamelVariableTransferTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = {"org/activiti5/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml"}) public void testCamelHeadersFiltered() throws Exception { ProducerTemplate tpl = camelContext.createProducerTemplate(); Exchange exchange = camelContext.getEndpoint("direct:startFilteredHeaders").createExchange(); tpl.send("direct:startFilteredHeaders", 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")); assertNull(variables.get("property3")); }
Example #3
Source File: XChangeMetadataIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testCurrencyPairs() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); List<CurrencyPair> pairs = template.requestBody("direct:currencyPairs", null, List.class); Assert.assertNotNull("Pairs not null", pairs); Assert.assertTrue("Contains EOS/ETH", pairs.contains(CurrencyPair.EOS_ETH)); } }
Example #4
Source File: LogProfileIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testWildFlyLogProfileGloabalLogConfig() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.getGlobalOptions().put(Exchange.LOG_EIP_NAME, LogProfileIntegrationTest.class.getName()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .log("Goodbye ${body}"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.requestBody("direct:start", "Kermit"); assertLogFileContainsContent(".*LogProfileIntegrationTest.*Goodbye Kermit$"); } finally { camelctx.close(); } }
Example #5
Source File: CamelVariableTransferTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = {"org/activiti/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml"}) public void testCamelHeadersAll() 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")); }
Example #6
Source File: PaxExamIT.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testPaxExam() throws Exception { // we should have completed 0 exchange long total = camelContext.getManagedCamelContext().getExchangesTotal(); assertEquals("Should be 0 exchanges completed", 0, total); // need a little delay to be ready Thread.sleep(2000); // call the servlet, and log what it returns String url = "http4://localhost:8181/camel/say"; ProducerTemplate template = camelContext.createProducerTemplate(); String json = template.requestBody(url, null, String.class); System.out.println("Wiseman says: " + json); LOG.info("Wiseman says: {}", json); // and we should have completed 1 exchange total = camelContext.getManagedCamelContext().getExchangesTotal(); assertEquals("Should be 1 exchanges completed", 1, total); }
Example #7
Source File: InitiatorCamelCallTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@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); }
Example #8
Source File: SimpleTransformTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSimpleTransform() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #9
Source File: TidyMarkupIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testUnmarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .unmarshal().tidyMarkup(); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "<body><a href=foo></body>", String.class).trim(); Assert.assertTrue("Starts with html: " + result, result.startsWith("<html ")); Assert.assertTrue("Contains end link: " + result, result.contains("</a>")); Assert.assertTrue("Ends with html: " + result, result.endsWith("</html>")); } finally { camelctx.close(); } }
Example #10
Source File: CamelVariableTransferTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/flowable/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml" }) public void testCamelPropertiesAndBody() throws Exception { ProducerTemplate tpl = camelContext.createProducerTemplate(); Exchange exchange = camelContext.getEndpoint("direct:startAllProperties").createExchange(); tpl.send("direct:startAllProperties", exchange); assertThat(taskService).isNotNull(); assertThat(runtimeService).isNotNull(); assertThat(taskService.createTaskQuery().count()).isEqualTo(1); Task task = taskService.createTaskQuery().singleResult(); assertThat(task).isNotNull(); Map<String, Object> variables = runtimeService.getVariables(task.getExecutionId()); assertThat(variables) .contains( entry("property1", "sampleValueForProperty1"), entry("property2", "sampleValueForProperty2"), entry("property3", "sampleValueForProperty3"), entry("camelBody", "sampleBody") ); }
Example #11
Source File: EmptyProcessTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = { "process/empty.bpmn20.xml" }) public void testObjectAsStringVariable() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); Object expectedObj = new Long(99); Exchange exchange = ctx.getEndpoint("direct:startEmptyBodyAsString").createExchange(); exchange.getIn().setBody(expectedObj); tpl.send("direct:startEmptyBodyAsString", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); assertProcessEnded(instanceId); HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult(); assertNotNull(var); assertEquals(expectedObj.toString(), var.getValue().toString()); }
Example #12
Source File: InboundReplyTest.java From vertx-camel-bridge with Apache License 2.0 | 6 votes |
@Test public void testReplyWithCustomType() throws Exception { Endpoint endpoint = camel.getEndpoint("direct:stuff"); vertx.eventBus().registerDefaultCodec(Person.class, new PersonCodec()); bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel) .addInboundMapping(new InboundMapping().setAddress("test-reply").setEndpoint(endpoint))); vertx.eventBus().consumer("test-reply", message -> { message.reply(new Person().setName("alice")); }); camel.start(); BridgeHelper.startBlocking(bridge); ProducerTemplate template = camel.createProducerTemplate(); Future<Object> future = template.asyncRequestBody(endpoint, new Person().setName("bob")); Person response = template.extractFutureBody(future, Person.class); assertThat(response.getName()).isEqualTo("alice"); }
Example #13
Source File: ICalFormatTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:marshal").marshal("ical").to("mock:result"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Calendar calendar = createTestCalendar(); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedBodiesReceived(calendar.toString()); producer.sendBody("direct:marshal", calendar); mock.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #14
Source File: DigitalOceanIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void getRegions() throws Exception { CamelContext camelctx = createCamelContext(oauthToken); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); try { MockEndpoint mockResult = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockResult.expectedMinimumMessageCount(1); ProducerTemplate producer = camelctx.createProducerTemplate(); List<Region> regions = producer.requestBody("direct:getRegions", null, List.class); Assert.assertNotEquals(1, regions.size()); mockResult.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #15
Source File: BindyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshal() throws Exception { final DataFormat bindy = new BindyCsvDataFormat(Customer.class); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .marshal(bindy); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class); Assert.assertEquals("John,Doe", result.trim()); } finally { camelctx.close(); } }
Example #16
Source File: XmlSecurityIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testXmlVerifySigning() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("xmlsecurity-sign://enveloping?keyAccessor=#accessor&schemaResourceUri=") .to("xmlsecurity-verify://enveloping?keySelector=#selector"); } }); try { camelctx.start(); ProducerTemplate producer = camelctx.createProducerTemplate(); String verifiedXml = producer.requestBody("direct:start", XML_PAYLOAD, String.class); // Make sure the XML was unsigned Assert.assertEquals(XML_PAYLOAD, verifiedXml); } finally { camelctx.close(); } }
Example #17
Source File: JingIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJingRngSchemaValidationSuccess() throws Exception { CamelContext camelctx = createCamelContext(false); MockEndpoint mockEndpointValid = camelctx.getEndpoint("mock:valid", MockEndpoint.class); mockEndpointValid.expectedMessageCount(1); MockEndpoint mockEndpointInvalid = camelctx.getEndpoint("mock:invalid", MockEndpoint.class); mockEndpointInvalid.expectedMessageCount(0); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", ORDER_XML_VALID); mockEndpointValid.assertIsSatisfied(); mockEndpointInvalid.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #18
Source File: ExplicitCamelDependencyTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCamelDependency() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").transform(body().prepend("Hello ")); } }); camelctx.start(); try { // Deployment is not camel enabled ClassLoader appcl = camelctx.getApplicationContextClassLoader(); Assert.assertNull("ApplicationContextClassLoader is null", appcl); ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #19
Source File: CSVIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshalMap() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").marshal().csv(); } }); Map<String, String> map = new LinkedHashMap<>(); map.put("firstName", "John"); map.put("lastName", "Doe"); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", map, String.class); Assert.assertEquals("John,Doe", result.trim()); } finally { camelctx.close(); } }
Example #20
Source File: PurchaseOrderBindyTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testBindy() throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(createRoute()); context.start(); MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedBodiesReceived("Camel in Action,69.99,1\n"); PurchaseOrder order = new PurchaseOrder(); order.setAmount(1); order.setPrice(new BigDecimal("69.99")); order.setName("Camel in Action"); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:toCsv", order); mock.assertIsSatisfied(); }
Example #21
Source File: CamelVariableTransferTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/flowable/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml" }) public void testCamelHeadersFiltered() throws Exception { ProducerTemplate tpl = camelContext.createProducerTemplate(); Exchange exchange = camelContext.getEndpoint("direct:startFilteredHeaders").createExchange(); tpl.send("direct:startFilteredHeaders", exchange); assertThat(taskService).isNotNull(); assertThat(runtimeService).isNotNull(); assertThat(taskService.createTaskQuery().count()).isEqualTo(1); Task task = taskService.createTaskQuery().singleResult(); assertThat(task).isNotNull(); Map<String, Object> variables = runtimeService.getVariables(task.getExecutionId()); assertThat(variables) .contains( entry("property1", "sampleValueForProperty1"), entry("property2", "sampleValueForProperty2") ) .doesNotContainKey("property3"); }
Example #22
Source File: BeanTransformTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSimpleTransformFromModule() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").bean(HelloBean.class); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #23
Source File: Base64IntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testBase64Marshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").marshal().base64(); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); String result = template.requestBody("direct:start", "Hello Kermit!", String.class); Assert.assertEquals("SGVsbG8gS2VybWl0IQ==", result.trim()); } finally { camelctx.close(); } }
Example #24
Source File: SimpleCamelTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testRandomConversion() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .setBody().simple("${random(500)}"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Integer result = producer.requestBody("direct:start", null, Integer.class); Assert.assertNotNull(result); Assert.assertTrue(0 < result); } finally { camelctx.close(); } }
Example #25
Source File: DigitalOceanIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void getSizes() throws Exception { CamelContext camelctx = createCamelContext(oauthToken); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); try { MockEndpoint mockResult = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockResult.expectedMinimumMessageCount(1); ProducerTemplate producer = camelctx.createProducerTemplate(); List<Size> sizes = producer.requestBody("direct:getSizes", null, List.class); Assert.assertNotEquals(1, sizes.size()); mockResult.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #26
Source File: CamelVariableTransferTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Deployment(resources = { "org/activiti/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml" }) public void testCamelPropertiesFiltered() throws Exception { ProducerTemplate tpl = camelContext.createProducerTemplate(); Exchange exchange = camelContext.getEndpoint("direct:startFilteredProperties").createExchange(); tpl.send("direct:startFilteredProperties", 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")); assertNull(variables.get("property3")); }
Example #27
Source File: ChunkIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testChunkComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("chunk:template"); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Exchange response = template.request("direct:start", exchange -> { exchange.getIn().setHeader("greeting", "Hello"); exchange.getIn().setHeader("name", "Kermit"); }); Assert.assertEquals("Hello Kermit!\n", response.getOut().getBody(String.class)); } finally { camelctx.close(); } }
Example #28
Source File: CamelReaderTest.java From incubator-batchee with Apache License 2.0 | 6 votes |
@Test public void read() throws Exception { final ProducerTemplate tpl = CamelBridge.CONTEXT.createProducerTemplate(); final JobOperator jobOperator = BatchRuntime.getJobOperator(); final long id = jobOperator.start("camel-reader", new Properties()); while (DirectEndpoint.class.cast(CamelBridge.CONTEXT.getEndpoint("direct:reader")).getConsumer() == null) { Thread.sleep(100); } tpl.sendBody("direct:reader", "input#1"); tpl.sendBody("direct:reader", null); Batches.waitForEnd(jobOperator, id); assertEquals(StoreItems.ITEMS.size(), 1); assertEquals("input#1", StoreItems.ITEMS.get(0)); }
Example #29
Source File: JsonValidatorIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInvalidMessage() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("file:target/validator?noop=true") .doTry() .to("json-validator:jsonvalidator/schema.json") .doCatch(ValidationException.class) .to("mock:invalid") .end(); } }); MockEndpoint mockInvalid = camelctx.getEndpoint("mock:invalid", MockEndpoint.class); mockInvalid.expectedMessageCount(1); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("file:target/validator", "{ \"name\": \"Joe Doe\", \"id\": \"AA1\", \"price\": 12.5 }", Exchange.FILE_NAME, "invalid.json"); mockInvalid.assertIsSatisfied(); Assert.assertTrue("Can delete the file", FileUtil.deleteFile(new File("target/validator/invalid.json"))); } finally { camelctx.close(); } }
Example #30
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test chains of split/aggregate where a 2nd split directly follows on the 1st aggregate. * direct -> split -> log -> aggregate -> split -> log -> aggregate -> mock */ @Test public void testSplitAggregateChain() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/split-chain.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); addBodyLogger(context); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); final ProducerTemplate template = context.createProducerTemplate(); final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class); final List<String> body = Arrays.asList("a,b,c", "de", "f,g"); result.expectedBodiesReceived(body); template.sendBody("direct:expression", body); result.assertIsSatisfied(); } finally { context.stop(); } }