當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。