本文整理汇总了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);
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
}