本文整理汇总了Java中org.apache.camel.ProducerTemplate.requestBody方法的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate.requestBody方法的具体用法?Java ProducerTemplate.requestBody怎么用?Java ProducerTemplate.requestBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.ProducerTemplate
的用法示例。
在下文中一共展示了ProducerTemplate.requestBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
/**
* Get the name parameter sent on the POST request
*/
String name = request.getParameter("name");
/**
* Create a ProducerTemplate to invoke the direct:start endpoint, which will
* result in the greeting REST service 'greet' method being invoked.
*
* The service parameters are sent to camel as an object array which is
* set as the request message body.
*
* The REST service result string is returned back for display on the UI.
*/
ProducerTemplate producer = camelContext.createProducerTemplate();
Object[] serviceParams = new Object[] {name};
String result = producer.requestBody("direct:start", serviceParams, String.class);
request.setAttribute("greeting", result);
request.getServletContext().getRequestDispatcher("/greeting.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 {
/**
* Get message and name parameters sent on the POST request
*/
String message = request.getParameter("message");
String name = request.getParameter("name");
/**
* Create a ProducerTemplate to invoke the direct:start endpoint, which will
* result in the greeting web service 'greet' method being invoked.
*
* The web service parameters are sent to camel as an object array which is
* set as the request message body.
*
* The web service result string is returned back for display on the UI.
*/
ProducerTemplate producer = camelContext.createProducerTemplate();
Object[] serviceParams = new Object[] { message, name };
String result = producer.requestBody("direct:start", serviceParams, String.class);
request.setAttribute("greeting", result);
request.getRequestDispatcher("/greeting.jsp").forward(request, response);
}
示例3: testMarshalToInterfaceViaDozer
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMarshalToInterfaceViaDozer() throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").convertBodyTo(Map.class);
}
});
DozerBeanMapperConfiguration mconfig = new DozerBeanMapperConfiguration();
mconfig.setMappingFiles(Arrays.asList("bean-to-map-dozer-mappings.xml"));
new DozerTypeConverterLoader(context, mconfig);
context.start();
try {
ProducerTemplate producer = context.createProducerTemplate();
Map<?, ?> result = producer.requestBody("direct:start", new Customer("John", "Doe", null), Map.class);
Assert.assertEquals("John", result.get("firstName"));
Assert.assertEquals("Doe", result.get("lastName"));
} finally {
context.stop();
}
}
示例4: testCxfProducer
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCxfProducer() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("cxf://" + getEndpointAddress("/") + "?serviceClass=" + Endpoint.class.getName());
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", "Kermit", String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
camelctx.stop();
}
}
示例5: testJettyMulticastJmsFile
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testJettyMulticastJmsFile() throws Exception {
TestSupport.deleteDirectory("target/jetty");
ProducerTemplate template = camelContext.createProducerTemplate();
String out = template.requestBody(URL, "Hello World", String.class);
assertEquals("Bye World", out);
template.stop();
ConsumerTemplate consumer = camelContext.createConsumerTemplate();
String in = consumer.receiveBody("jms:queue:foo", 5000, String.class);
assertEquals("Hello World", in);
String in2 = consumer.receiveBody("file://target/jetty?noop=true&readLock=none", 5000, String.class);
assertEquals("Hello World", in2);
consumer.stop();
}
示例6: testMyMain
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMyMain() throws Exception {
Main main = new Main();
main.setBundleName("MyMainBundle");
// as we run this test without packing ourselves as bundle, then include ourselves
main.setIncludeSelfAsBundle(true);
// setup the blueprint file here
main.setDescriptors("org/apache/camel/test/blueprint/main-no-pid-loadfile.xml");
main.start();
ProducerTemplate template = main.getCamelTemplate();
assertNotNull("We should get the template here", template);
String result = template.requestBody("direct:start", "hello", String.class);
assertEquals("Get a wrong response", "Good morning hello", result);
main.stop();
}
示例7: marshalAndUnmarshal
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public static void marshalAndUnmarshal(
CamelContext context, Object body, String mockName, String directIn, String directBack, String expected) throws Exception {
MockEndpoint mock = context.getEndpoint(mockName, MockEndpoint.class);
assertNotNull(mock);
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(body.getClass());
mock.message(0).body().isEqualTo(body);
ProducerTemplate template = context.createProducerTemplate();
String result = template.requestBody(directIn, body, String.class);
assertNotNull(result);
assertEquals(expected, result.trim());
template.sendBody(directBack, result);
mock.assertIsSatisfied();
}
示例8: testMyMain
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMyMain() throws Exception {
Main main = new Main();
main.setBundleName("MyMainBundle");
// as we run this test without packing ourselves as bundle, then include ourselves
main.setIncludeSelfAsBundle(true);
// setup the blueprint file here
main.setDescriptors("org/apache/camel/test/blueprint/main-no-reload-loadfile.xml");
// set the configAdmin persistent id
main.setConfigAdminPid("stuff");
// set the configAdmin persistent file name
main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
main.start();
ProducerTemplate template = main.getCamelTemplate();
assertNotNull("We should get the template here", template);
String result = template.requestBody("direct:start", "hello", String.class);
assertEquals("Get a wrong response", "Bye hello", result);
main.stop();
}
示例9: testMyMain
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMyMain() throws Exception {
Main main = new Main();
main.setBundleName("MyMainBundle");
// as we run this test without packing ourselves as bundle, then include ourselves
main.setIncludeSelfAsBundle(true);
// setup the blueprint file here
main.setDescriptors("org/apache/camel/test/blueprint/main-loadfile.xml");
// set the configAdmin persistent id
main.setConfigAdminPid("stuff");
// set the configAdmin persistent file name
main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
main.start();
ProducerTemplate template = main.getCamelTemplate();
assertNotNull("We should get the template here", template);
String result = template.requestBody("direct:start", "hello", String.class);
assertEquals("Get a wrong response", "Bye hello", result);
main.stop();
}
示例10: requestBody
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public Object requestBody(String endpointUri, Object body) throws Exception {
ProducerTemplate template = context.createProducerTemplate();
Object answer = null;
try {
answer = template.requestBody(endpointUri, body);
} finally {
template.stop();
}
return answer;
}
示例11: testRequestUsingDefaultEndpoint
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testRequestUsingDefaultEndpoint() throws Exception {
ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:out"));
producer.start();
Object out = producer.requestBody("Hello");
assertEquals("Bye Bye World", out);
out = producer.requestBodyAndHeader("Hello", "foo", 123);
assertEquals("Bye Bye World", out);
Map<String, Object> headers = new HashMap<String, Object>();
out = producer.requestBodyAndHeaders("Hello", headers);
assertEquals("Bye Bye World", out);
out = producer.requestBodyAndHeaders("Hello", null);
assertEquals("Bye Bye World", out);
producer.stop();
}
示例12: doGet
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String name = req.getParameter("name");
if (name == null || name.isEmpty()) {
// Default to Hello world output
name = "world";
}
ServletOutputStream out = res.getOutputStream();
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", name, String.class);
out.print(result);
}
示例13: testSimpleTransform
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testSimpleTransform() throws Exception {
CamelContextRegistry contextRegistry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
CamelContext camelctx = contextRegistry.getCamelContext("camel-1");
Assert.assertEquals(CamelContextRegistry.class.getClassLoader(), camelctx.getApplicationContextClassLoader());
Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", "Kermit", String.class);
Assert.assertEquals("Hello Kermit", result);
}
示例14: findByCondition
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private List<DBObject> findByCondition(String mongoDatabase, String collection, MongoDbOperation operation,
ProducerTemplate producerTemplate, Map<String, String> conditions)
throws Exception
{
List<DBObject> list=null;
DBObject query = BasicDBObjectBuilder.start(conditions).get();
Object result = producerTemplate.requestBody(getQuery(mongoDatabase, collection, operation), query);
if (result == null)
{
logger.warn("Nothing found in Mongo for " + conditions);
return null;
// throw new Exception("Nothing found in Mongo for " + conditions);
}
if (result instanceof DBObject)
{
list = new ArrayList<>(1);
list.add((DBObject) result);
}
else
{
list = (List) result;
}
if (logger.isDebugEnabled())
{
logger.debug("findByCondition {} returned the following results:", operation);
for (DBObject obj : list)
{
for (String key : obj.keySet())
logger.debug("key = " + key + " value = " + obj.get(key));
}
}
return list;
}
示例15: testCamelGreeter
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCamelGreeter() throws Exception {
TestSupport.deleteDirectory("target/greeter/response");
assertNotNull(camelContext);
ProducerTemplate template = camelContext.createProducerTemplate();
Object result = template.requestBody("direct:start", REQUEST);
template.stop();
assertEquals("The result is wrong.", "Hello Willem", result);
File file = new File("target/greeter/response/response.txt");
assertTrue("File " + file + " should be there.", file.exists());
}