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


Java ProducerTemplate.requestBody方法代码示例

本文整理汇总了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);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:24,代码来源:CamelCxfRsServlet.java

示例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);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:25,代码来源:CamelCxfWsServlet.java

示例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();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:DozerBeanMappingTest.java

示例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();
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-camel,代码行数:20,代码来源:CXFWSProducerIntegrationTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JettyMulticastJmsFileTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:MainNoPidTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:SnakeYAMLMarshalTestHelper.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MainNoReloadTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MainTest.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:ManagedCamelContext.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:DefaultProducerTemplateTest.java

示例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);
   }
 
开发者ID:wildfly-extras,项目名称:wildfly-camel-examples,代码行数:14,代码来源:SimpleServlet.java

示例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);
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-camel,代码行数:13,代码来源:SystemContextTransformTest.java

示例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;
    }
 
开发者ID:eurohlam,项目名称:rss2kindle,代码行数:36,代码来源:MongoHelper.java

示例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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:CamelGreeterFileDomTest.java


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