Java Code Examples for org.apache.camel.ProducerTemplate#request()
The following examples show how to use
org.apache.camel.ProducerTemplate#request() .
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: 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 2
Source File: StringTemplateIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testStringTemplateComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("string-template:classpath:template.tm"); } }); 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!", response.getOut().getBody(String.class)); } finally { camelctx.close(); } }
Example 3
Source File: MustacheIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMustacheComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("mustache:classpath:template.mustache"); } }); 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!", response.getOut().getBody(String.class)); } finally { camelctx.close(); } }
Example 4
Source File: LogsAndErrorsTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testRoute() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = newIntegrationRouteBuilder( new io.syndesis.common.model.integration.Step.Builder() .id("s1") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("direct") .putConfiguredProperty("name", "expression") .build()) .build()) .build(), new io.syndesis.common.model.integration.Step.Builder() .id("s2") .stepKind(StepKind.extension) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(StepAction.Kind.STEP) .entrypoint(LogExtension.class.getName()) .build()) .build()) .build(), new io.syndesis.common.model.integration.Step.Builder() .id("s3") .stepKind(StepKind.extension) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(StepAction.Kind.STEP) .entrypoint(ErrorExtension.class.getName()) .build()) .build()) .build(), new io.syndesis.common.model.integration.Step.Builder() .id("s4") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("mock") .putConfiguredProperty("name", "expression") .build()) .build()) .build() ); // Set up the camel context context.addRoutes(routes); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); final ProducerTemplate template = context.createProducerTemplate(); final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class); result.expectedBodiesReceived("1","3"); Exchange e1 = template.request("direct:expression", e -> e.getIn().setBody("1")); assertThat(e1.isFailed()).isFalse(); Exchange e2 = template.request("direct:expression", e -> e.getIn().setBody("2")); assertThat(e2.isFailed()).isTrue(); Exchange e3 = template.request("direct:expression", e -> e.getIn().setBody("3")); assertThat(e3.isFailed()).isFalse(); result.assertIsSatisfied(); } finally { context.stop(); } }
Example 5
Source File: GeocoderIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testGeocoderComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("geocoder:address:London, England?apiKey=" + GEOCODER_API_KEY); } }); camelctx.start(); try { // Geocoder API is sometimes flaky so retry the request if necessary Exchange exchange = null; int count = 0; while (count < 5) { ProducerTemplate template = camelctx.createProducerTemplate(); exchange = template.request("direct:start", null); Assert.assertNotNull("Exchange is null", exchange); GeocoderStatus status = exchange.getIn().getHeader(GeoCoderConstants.STATUS, GeocoderStatus.class); Assert.assertNotNull("Geocoder status is null", status); if (status.equals(GeocoderStatus.OK)) { break; } Thread.sleep(1000); count++; } Assert.assertNotNull("Gave up attempting to get successful Geocoder API response", exchange); String latitude = exchange.getIn().getHeader(GeoCoderConstants.LAT, String.class); Assert.assertNotNull("Geocoder " + GeoCoderConstants.LAT + " header is null", latitude); String longitude = exchange.getIn().getHeader(GeoCoderConstants.LNG, String.class); Assert.assertNotNull("Geocoder " + GeoCoderConstants.LNG + " header is null", latitude); Assert.assertEquals("51.50735090", latitude); Assert.assertEquals("-0.12775830", longitude); } finally { camelctx.close(); } }