Author: ningjiang Date: Wed Jan 27 13:40:14 2010 New Revision: 903638 URL: http://svn.apache.org/viewvc?rev=903638&view=rev Log: CAMEL-2412 DefaultHttpBinding should parser the URI's parameter without checking HttpMethod
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=903638&r1=903637&r2=903638&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Wed Jan 27 13:40:14 2010 @@ -78,18 +78,15 @@ } } - //we populate the http request parameters for GET and POST + //we populate the http request parameters without checking the request method - String method = request.getMethod(); - if (method.equalsIgnoreCase("GET") || (method.equalsIgnoreCase("POST"))) { - names = request.getParameterNames(); - while (names.hasMoreElements()) { - String name = (String)names.nextElement(); - Object value = request.getParameter(name); - if (headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) { - headers.put(name, value); - } + names = request.getParameterNames(); + while (names.hasMoreElements()) { + String name = (String)names.nextElement(); + Object value = request.getParameter(name); + if (headerFilterStrategy != null + && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) { + headers.put(name, value); } } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java?rev=903638&r1=903637&r2=903638&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java Wed Jan 27 13:40:14 2010 @@ -37,6 +37,7 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.junit.Test; @@ -94,7 +95,7 @@ NameValuePair[] data = {new NameValuePair("request", "PostParameter"), new NameValuePair("others", "bloggs")}; HttpClient client = new HttpClient(); - PostMethod post = new PostMethod("http://localhost:9080/post"); + PostMethod post = new PostMethod("http://localhost:9080/parameter"); post.setRequestBody(data); client.executeMethod(post); InputStream response = post.getResponseBodyAsStream(); @@ -117,7 +118,7 @@ @Test public void testPostParameterInURI() throws Exception { HttpClient client = new HttpClient(); - PostMethod post = new PostMethod("http://localhost:9080/post?request=PostParameter&others=bloggs"); + PostMethod post = new PostMethod("http://localhost:9080/parameter?request=PostParameter&others=bloggs"); StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8"); post.setRequestEntity(entity); client.executeMethod(post); @@ -125,6 +126,18 @@ String out = context.getTypeConverter().convertTo(String.class, response); assertEquals("Get a wrong output " , "PostParameter", out); } + + @Test + public void testPutParameterInURI() throws Exception { + HttpClient client = new HttpClient(); + PutMethod put = new PutMethod("http://localhost:9080/parameter?request=PutParameter&others=bloggs"); + StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8"); + put.setRequestEntity(entity); + client.executeMethod(put); + InputStream response = put.getResponseBodyAsStream(); + String out = context.getTypeConverter().convertTo(String.class, response); + assertEquals("Get a wrong output " , "PutParameter", out); + } protected void invokeHttpEndpoint() throws IOException { template.requestBodyAndHeader("http://localhost:9080/test", expectedBody, "Content-Type", "application/xml"); @@ -167,7 +180,7 @@ from("jetty:http://localhost:9080/echo").process(printProcessor).process(printProcessor); - Processor procPostParameters = new Processor() { + Processor procParameters = new Processor() { public void process(Exchange exchange) throws Exception { HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); String value = req.getParameter("request"); @@ -181,7 +194,7 @@ } }; - from("jetty:http://localhost:9080/post").process(procPostParameters); + from("jetty:http://localhost:9080/parameter").process(procParameters); from("jetty:http://localhost:9080/postxml").process(new Processor() {