camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r706005 - in /activemq/camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-http/src/test/java/org/apache/camel/component/http/ camel-jetty/src/test/java/org/apache/camel/component/jetty/
Date Sun, 19 Oct 2008 13:16:19 GMT
Author: davsclaus
Date: Sun Oct 19 06:16:19 2008
New Revision: 706005

URL: http://svn.apache.org/viewvc?rev=706005&view=rev
Log:
CAMEL-997: HttpProducer reworked how either GET or POST is select to be used.

Added:
    activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
  (with props)
    activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
  (with props)
Modified:
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java?rev=706005&r1=706004&r2=706005&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
Sun Oct 19 06:16:19 2008
@@ -74,10 +74,17 @@
                 // Try to stream the body since that would be the most efficient
                 InputStream is = out.getBody(InputStream.class);
                 if (is != null) {
-                    ServletOutputStream os = response.getOutputStream();
-                    int c;
-                    while ((c = is.read()) >= 0) {
-                        os.write(c);
+                    ServletOutputStream os = null;
+                    try {
+                        os = response.getOutputStream();
+                        int c;
+                        while ((c = is.read()) >= 0) {
+                            os.write(c);
+                        }
+                        os.flush();
+                    } finally {
+                        os.close();
+                        is.close();
                     }
                 } else {
                     String data = out.getBody(String.class);

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=706005&r1=706004&r2=706005&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Sun Oct 19 06:16:19 2008
@@ -22,6 +22,7 @@
 import org.apache.camel.Endpoint;
 import org.apache.camel.HeaderFilterStrategyAware;
 import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.IntrospectionSupport;

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java?rev=706005&r1=706004&r2=706005&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
Sun Oct 19 06:16:19 2008
@@ -25,11 +25,11 @@
     private final int statusCode;
     private final StatusLine statusLine;
 
-
     public HttpOperationFailedException(int statusCode, StatusLine statusLine, String location)
{
+        super("HTTP operation failed with statusCode: " + statusCode + ", status: " + statusLine
+ (location != null ? ", redirectLocation: " + location : ""));
         this.statusCode = statusCode;
         this.statusLine = statusLine;
-        redirectLocation = location;
+        this.redirectLocation = location;
     }
 
     public HttpOperationFailedException(int statusCode, StatusLine statusLine) {
@@ -56,5 +56,4 @@
         return statusCode;
     }
 
-
-}
+}
\ No newline at end of file

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=706005&r1=706004&r2=706005&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Sun Oct 19 06:16:19 2008
@@ -17,6 +17,7 @@
 package org.apache.camel.component.http;
 
 import java.io.InputStream;
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -26,9 +27,11 @@
 import org.apache.camel.Message;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
@@ -36,6 +39,8 @@
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
 
 import static org.apache.camel.component.http.HttpMethods.HTTP_METHOD;
 
@@ -43,6 +48,7 @@
  * @version $Revision$
  */
 public class HttpProducer extends DefaultProducer<HttpExchange> implements Producer<HttpExchange>
{
+    private static final transient Log LOG = LogFactory.getLog(HttpProducer.class);
     public static final String HTTP_RESPONSE_CODE = "http.responseCode";
     public static final String QUERY = "org.apache.camel.component.http.query";
 
@@ -72,17 +78,21 @@
 
         // lets store the result in the output message.
         try {
-            int responseCode = httpClient.executeMethod(method);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Executing http " + method.getName() + " method: " + method.getURI().toString());
+            }
+            int responseCode = executeMethod(method);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Http responseCode: " + responseCode);
+            }
+
             if (responseCode >= 100 && responseCode < 300) {
                 Message answer = exchange.getOut(true);
+
                 answer.setHeaders(in.getHeaders());
                 answer.setHeader(HTTP_RESPONSE_CODE, responseCode);
-                LoadingByteArrayOutputStream bos = new LoadingByteArrayOutputStream();
-                InputStream is = method.getResponseBodyAsStream();
-                IOUtils.copy(is, bos);
-                bos.flush();
-                is.close();
-                answer.setBody(bos.createInputStream());
+                answer.setBody(extractResponseBody(method));
+
                 // propagate HTTP response headers
                 Header[] headers = method.getResponseHeaders();
                 for (Header header : headers) {
@@ -121,24 +131,64 @@
         this.httpClient = httpClient;
     }
 
-    protected HttpMethod createMethod(Exchange exchange) {
-        String uri = ((HttpEndpoint)getEndpoint()).getHttpUri().toString();
+    /**
+     * Strategy when executing the method (calling the remote server).
+     *
+     * @param method    the method to execute
+     * @return the response code
+     * @throws IOException can be thrown
+     */
+    protected int executeMethod(HttpMethod method) throws IOException {
+        return httpClient.executeMethod(method);
+    }
+
+    protected static InputStream extractResponseBody(HttpMethod method) throws IOException
{
+        LoadingByteArrayOutputStream bos = null;
+        InputStream is = null;
+        try {
+            bos = new LoadingByteArrayOutputStream();
+            is = method.getResponseBodyAsStream();
+            IOUtils.copy(is, bos);
+            bos.flush();
+            return bos.createInputStream();
+        } finally {
+            ObjectHelper.close(is, "Extracting response body", LOG);
+            ObjectHelper.close(bos, "Extracting response body", LOG);
+        }
+    }
 
+    protected HttpMethod createMethod(Exchange exchange) {
+        // is a query string provided in the endpoint URI or in a header (header overrules
endpoint)
+        String queryString = exchange.getIn().getHeader(QUERY, String.class);
+        if (queryString == null) {
+            queryString = ((HttpEndpoint)getEndpoint()).getHttpUri().getQuery();
+        }
         RequestEntity requestEntity = createRequestEntity(exchange);
-        Object m = exchange.getIn().getHeader(HTTP_METHOD);
 
-        HttpMethods ms = requestEntity == null ? HttpMethods.GET : HttpMethods.POST;
-        ms = m instanceof HttpMethods ? (HttpMethods)m
-            : m == null ? ms : HttpMethods.valueOf(m.toString());
+        // compute what method to use either GET or POST
+        HttpMethods methodToUse;
+        HttpMethods m = exchange.getIn().getHeader(HTTP_METHOD, HttpMethods.class);
+        if (m != null) {
+            // always use what end-user provides in a header
+            methodToUse = m;
+        } else if (queryString != null) {
+            // if a query string is provided then use GET
+            methodToUse = HttpMethods.GET;
+        } else {
+            // fallback to POST if data, otherwise GET
+            methodToUse = requestEntity != null ? HttpMethods.POST : HttpMethods.GET;
+        }
 
-        HttpMethod method = ms.createMethod(uri);
+        String uri = ((HttpEndpoint)getEndpoint()).getHttpUri().toString();
+        HttpMethod method = methodToUse.createMethod(uri);
 
-        if (exchange.getIn().getHeader(QUERY) != null) {
-            method.setQueryString(exchange.getIn().getHeader(QUERY, String.class));
+        if (queryString != null) {
+            method.setQueryString(queryString);
         }
-        if (ms.isEntityEnclosing()) {
+        if (methodToUse.isEntityEnclosing()) {
             ((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
         }
+
         return method;
     }
 
@@ -150,12 +200,18 @@
         try {
             return in.getBody(RequestEntity.class);
         } catch (NoTypeConversionAvailableException ex) {
-            String data = in.getBody(String.class);
-            String contentType = in.getHeader("Content-Type", String.class);
             try {
-                return new StringRequestEntity(data, null, null);
+                String data = in.getBody(String.class);
+                if (data != null) {
+                    String contentType = in.getHeader("Content-Type", String.class);
+                    String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+                    return new StringRequestEntity(data, contentType, charset);
+                } else {
+                    // no data
+                    return null;
+                }
             } catch (UnsupportedEncodingException e) {
-                throw new RuntimeException(e);
+                throw new RuntimeCamelException(e);
             }
         }
     }

Added: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java?rev=706005&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
(added)
+++ activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
Sun Oct 19 06:16:19 2008
@@ -0,0 +1,173 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+import org.apache.camel.ContextTestSupport;
+import static org.apache.camel.component.http.HttpMethods.*;
+import org.apache.commons.httpclient.HttpMethod;
+
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Unit test to verify the algorithm for selecting either GET or POST.
+ */
+public class HttpProducerSelectMethodTest extends ContextTestSupport {
+
+    public void testNoDataDefaultIsGet() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody(null);
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testDataDefaultIsPost() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("This is some data to post");
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testWithMethodPostInHeader() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("");
+        exchange.getIn().setHeader(HTTP_METHOD, POST);
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testWithMethodGetInHeader() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("");
+        exchange.getIn().setHeader(HTTP_METHOD, GET);
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testWithEndpointQuery() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Camel",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("");
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testWithQueryInHeader() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("");
+        exchange.getIn().setHeader(HttpProducer.QUERY, "q=Camel");
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    public void testWithQueryInHeaderOverrideEndpoint() throws Exception {
+        HttpComponent component = new HttpComponent();
+        component.setCamelContext(context);
+        HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Donkey",
"", Collections.EMPTY_MAP);
+        MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
+
+        HttpExchange exchange = producer.createExchange();
+        exchange.getIn().setBody("");
+        exchange.getIn().setHeader(HttpProducer.QUERY, "q=Camel");
+        try {
+            producer.process(exchange);
+            fail("Should have thrown HttpOperationFailedException");
+        } catch (HttpOperationFailedException e) {
+            assertEquals(500, e.getStatusCode());
+        }
+        producer.stop();
+    }
+
+    private static class MyHttpProducer extends HttpProducer {
+        private String name;
+        private String queryString;
+
+        public MyHttpProducer(HttpEndpoint endpoint, String name, String queryString) {
+            super(endpoint);
+            this.name = name;
+            this.queryString = queryString;
+        }
+
+        @Override
+        protected int executeMethod(HttpMethod method) throws IOException {
+            // do the assertion what to expected either GET or POST
+            assertEquals(name, method.getName());
+            assertEquals(queryString, method.getQueryString());
+            // return 500 to not extract response as we dont have any
+            return 500;
+        }
+    }
+}

Propchange: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java?rev=706005&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
(added)
+++ activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
Sun Oct 19 06:16:19 2008
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+import org.apache.camel.ContextTestSupport;
+
+/**
+ * Unit test to query Google using GET with endpoint having the query parameters.
+ */
+public class HttpQueryGoogleTest extends ContextTestSupport {
+
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testQueryGoogle() throws Exception {
+        Object out = template.sendBody("http://www.google.com/search?q=Camel", "");
+        assertNotNull(out);
+        String data = context.getTypeConverter().convertTo(String.class, out);
+        assertTrue("Camel should be in search result from Google", data.indexOf("Camel")
> -1);
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java?rev=706005&r1=706004&r2=706005&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java
(original)
+++ activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java
Sun Oct 19 06:16:19 2008
@@ -31,24 +31,32 @@
 
     public void testHttpGetWithParamsViaURI() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
         mock.expectedHeaderReceived("one", "einz");
         mock.expectedHeaderReceived("two", "twei");
-        mock.expectedHeaderReceived(HttpMethods.HTTP_METHOD, "POST");
+        mock.expectedHeaderReceived(HttpMethods.HTTP_METHOD, "GET");
 
-        template.sendBody(serverUri + "?one=einz&two=twei", "Hello World");
+        template.sendBody(serverUri + "?one=einz&two=twei", null);
 
         assertMockEndpointsSatisfied();
     }
 
     public void testHttpGetWithParamsViaHeader() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
         mock.expectedHeaderReceived("one", "uno");
         mock.expectedHeaderReceived("two", "dos");
+        mock.expectedHeaderReceived(HttpMethods.HTTP_METHOD, "GET");
+
+        template.sendBodyAndHeader(serverUri, null, HttpProducer.QUERY, "one=uno&two=dos");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testHttpPost() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
         mock.expectedHeaderReceived(HttpMethods.HTTP_METHOD, "POST");
 
-        template.sendBodyAndHeader(serverUri, "Hello World", HttpProducer.QUERY, "one=uno&two=dos");
+        template.sendBody(serverUri, "Hello World");
 
         assertMockEndpointsSatisfied();
     }



Mime
View raw message