Java Code Examples for org.apache.camel.ProducerTemplate

The following examples show how to use org.apache.camel.ProducerTemplate. These examples are extracted from open source projects. 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 Project: wildfly-camel   Source File: XSLTIntegrationTest.java    License: Apache License 2.0 7 votes vote down vote up
@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 Project: wildfly-camel   Source File: BindyIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
@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 Project: wildfly-camel   Source File: LogProfileIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: activiti6-boot2   Source File: CamelVariableTransferTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: camelinaction2   Source File: PaxExamIT.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: activiti6-boot2   Source File: InitiatorCamelCallTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: SimpleTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: TidyMarkupIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: flowable-engine   Source File: CamelVariableTransferTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: activiti6-boot2   Source File: EmptyProcessTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: vertx-camel-bridge   Source File: InboundReplyTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: ICalFormatTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: DigitalOceanIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: activiti6-boot2   Source File: CamelVariableTransferTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 16
Source Project: wildfly-camel   Source File: XmlSecurityIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: JingIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: ExplicitCamelDependencyTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: CSVIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: camelinaction2   Source File: PurchaseOrderBindyTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: flowable-engine   Source File: CamelVariableTransferTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: BeanTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: Base64IntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: SimpleCamelTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: DigitalOceanIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: flowable-engine   Source File: CamelVariableTransferTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: ChunkIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: incubator-batchee   Source File: CamelReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: wildfly-camel   Source File: SecuredSpringRouteTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRoleBasedAccess() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("contextB");
    ProducerTemplate producer = camelctx.createProducerTemplate();
    Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD);
    String result = producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example 30
Source Project: camel-quarkus   Source File: CamelProducers.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
ProducerTemplate camelProducerTemplate(InjectionPoint injectionPoint) {
    final ProducerTemplate template = this.context.createProducerTemplate();
    final Produce produce = injectionPoint.getAnnotated().getAnnotation(Produce.class);

    if (ObjectHelper.isNotEmpty(produce) && ObjectHelper.isNotEmpty(produce.value())) {
        template.setDefaultEndpointUri(produce.value());
    }

    return template;
}