当前位置: 首页>>代码示例>>Java>>正文


Java ProducerTemplate.sendBodyAndHeaders方法代码示例

本文整理汇总了Java中org.apache.camel.ProducerTemplate.sendBodyAndHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate.sendBodyAndHeaders方法的具体用法?Java ProducerTemplate.sendBodyAndHeaders怎么用?Java ProducerTemplate.sendBodyAndHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.ProducerTemplate的用法示例。


在下文中一共展示了ProducerTemplate.sendBodyAndHeaders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPost

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    Map<String, Object> headers = new HashMap<>();

    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = parameterNames.nextElement();
        String parameterValue = request.getParameter(parameterName);
        headers.put(parameterName, parameterValue);
    }

    try {
        ProducerTemplate producer = camelContext.createProducerTemplate();
        producer.sendBodyAndHeaders("direct:sendmail", request.getParameter("message"), headers);
        request.getRequestDispatcher("/success.jsp").forward(request, response);
    } catch (CamelExecutionException e) {
        request.setAttribute("error", e);
        request.getRequestDispatcher("/error.jsp").forward(request, response);
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:21,代码来源:MailSendServlet.java

示例2: doPost

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
  Map<String, Object> headers = new HashMap<>();

  Enumeration<String> parameterNames = request.getParameterNames();
  while(parameterNames.hasMoreElements()) {
    String parameterName = parameterNames.nextElement();
    String parameterValue = request.getParameter(parameterName);
    headers.put(parameterName, parameterValue);
  }

  try {
    ProducerTemplate producer = camelContext.createProducerTemplate();
    producer.sendBodyAndHeaders("direct:sendmail", request.getParameter("message"), headers);
    request.getRequestDispatcher("/success.jsp").forward(request, response);
  } catch (CamelExecutionException e) {
    request.setAttribute("error", e);
    request.getRequestDispatcher("/error.jsp").forward(request, response);
  }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:21,代码来源:MailSendServlet.java

示例3: doSignatureRouteTest

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.addRoutes(builder);
        context.start();

        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.setExpectedMessageCount(1);

        ProducerTemplate template = context.createProducerTemplate();
        if (e != null) {
            template.send("direct:in", e);
        } else {
            template.sendBodyAndHeaders("direct:in", payload, headers);
        }
        assertMockEndpointsSatisfied();
        return mock.getReceivedExchanges().get(0);
    } finally {
        context.stop();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:XmlSignatureTest.java

示例4: sendBodyAndHeaders

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws Exception {
    ProducerTemplate template = context.createProducerTemplate();
    try {
        template.sendBodyAndHeaders(endpointUri, body, headers);
    } finally {
        template.stop();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:ManagedCamelContext.java

示例5: testSendUsingDefaultEndpoint

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testSendUsingDefaultEndpoint() throws Exception {
    ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:in"));
    producer.start();

    getMockEndpoint("mock:result").expectedMessageCount(3);

    producer.sendBody("Hello");
    producer.sendBodyAndHeader("Hello", "foo", 123);
    Map<String, Object> headers = new HashMap<String, Object>();
    producer.sendBodyAndHeaders("Hello", headers);

    assertMockEndpointsSatisfied();

    producer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DefaultProducerTemplateTest.java

示例6: sendMessagesInRoute

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private void sendMessagesInRoute(int messages, ProducerTemplate template, Object bodyOther, Map<String, Object> headerMap) {
    for (int k = 0; k < messages; k++) {
        template.sendBodyAndHeaders(bodyOther, headerMap);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:KafkaProducerFullTest.java

示例7: testPutMultiRows

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testPutMultiRows() throws Exception {
    if (systemReady) {
        ProducerTemplate template = context.createProducerTemplate();
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(), key[0]);
        headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(), INFO_FAMILY);
        headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(), column[0]);
        headers.put(HBaseAttribute.HBASE_VALUE.asHeader(), body[0]);

        headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(2), key[1]);
        headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(2), INFO_FAMILY);
        headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(2), column[0]);
        headers.put(HBaseAttribute.HBASE_VALUE.asHeader(2), body[1]);

        headers.put(HBaseAttribute.HBASE_ROW_ID.asHeader(3), key[2]);
        headers.put(HBaseAttribute.HBASE_FAMILY.asHeader(3), INFO_FAMILY);
        headers.put(HBaseAttribute.HBASE_QUALIFIER.asHeader(3), column[0]);
        headers.put(HBaseAttribute.HBASE_VALUE.asHeader(3), body[2]);

        headers.put(HBaseConstants.OPERATION, HBaseConstants.PUT);

        template.sendBodyAndHeaders("direct:start", null, headers);

        Configuration configuration = hbaseUtil.getHBaseAdmin().getConfiguration();
        HTable bar = new HTable(configuration, PERSON_TABLE.getBytes());
        Get get = new Get(Bytes.toBytes((Integer) key[0]));

        //Check row 1
        get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
        Result result = bar.get(get);
        byte[] resultValue = result.value();
        assertArrayEquals(Bytes.toBytes((Long) body[0]), resultValue);

        //Check row 2
        get = new Get(Bytes.toBytes((String) key[1]));
        get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
        result = bar.get(get);
        resultValue = result.value();
        assertArrayEquals(Bytes.toBytes((Boolean) body[1]), resultValue);

        //Check row 3
        get = new Get(Bytes.toBytes((String) key[2]));
        get.addColumn(INFO_FAMILY.getBytes(), column[0].getBytes());
        result = bar.get(get);
        resultValue = result.value();
        assertArrayEquals(Bytes.toBytes((String) body[2]), resultValue);

        IOHelper.close(bar);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:52,代码来源:HBaseConvertionsTest.java


注:本文中的org.apache.camel.ProducerTemplate.sendBodyAndHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。