You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/10/09 10:44:51 UTC
svn commit: r1180567 - in /camel/branches/camel-2.8.x: ./
components/camel-http/src/main/java/org/apache/camel/component/http/
components/camel-http/src/main/java/org/apache/camel/component/http/helper/
components/camel-http4/src/main/java/org/apache/c...
Author: ningjiang
Date: Sun Oct 9 08:44:50 2011
New Revision: 1180567
URL: http://svn.apache.org/viewvc?rev=1180567&view=rev
Log:
Merged revisions 1180557 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1180557 | ningjiang | 2011-10-09 15:34:42 +0800 (Sun, 09 Oct 2011) | 1 line
CAMEL-4526 HttpProduder should not ignore the query part of HTTP_URI header
........
Modified:
camel/branches/camel-2.8.x/ (props changed)
camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
camel/branches/camel-2.8.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java
camel/branches/camel-2.8.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Oct 9 08:44:50 2011
@@ -1 +1 @@
-/camel/trunk:1169608,1178509,1179125,1179198,1180321,1180345
+/camel/trunk:1169608,1178509,1179125,1179198,1180321,1180345,1180557
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Sun Oct 9 08:44:50 2011
@@ -22,6 +22,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -318,11 +320,13 @@ public class HttpProducer extends Defaul
* @param exchange the exchange
* @return the created method as either GET or POST
* @throws CamelExchangeException is thrown if error creating RequestEntity
+ * @throws URISyntaxException
*/
@SuppressWarnings("deprecation")
- protected HttpMethod createMethod(Exchange exchange) throws CamelExchangeException {
+ protected HttpMethod createMethod(Exchange exchange) throws CamelExchangeException, URISyntaxException {
String url = HttpHelper.createURL(exchange, getEndpoint());
+ URI uri = new URI(url);
RequestEntity requestEntity = createRequestEntity(exchange);
HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
@@ -333,6 +337,10 @@ public class HttpProducer extends Defaul
if (queryString == null) {
queryString = getEndpoint().getHttpUri().getRawQuery();
}
+ // We should user the query string from the HTTP_URI header
+ if (queryString == null) {
+ queryString = uri.getQuery();
+ }
if (queryString != null) {
// need to make sure the queryString is URI safe
method.setQueryString(queryString);
Modified: camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java (original)
+++ camel/branches/camel-2.8.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java Sun Oct 9 08:44:50 2011
@@ -22,6 +22,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -213,14 +214,28 @@ public final class HttpHelper {
*
* @param exchange the exchange
* @return the created method
+ * @throws URISyntaxException
*/
- public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) {
+ public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ // We need also check the HTTP_URI header query part
+ String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
+ // resolve placeholders in uriString
+ try {
+ uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
+ } catch (Exception e) {
+ throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
+ }
+ if (uriString != null) {
+ URI uri = new URI(uriString);
+ queryString = uri.getQuery();
+ }
if (queryString == null) {
queryString = endpoint.getHttpUri().getQuery();
}
+
// compute what method to use either GET or POST
HttpMethods answer;
Modified: camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java (original)
+++ camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Sun Oct 9 08:44:50 2011
@@ -329,6 +329,11 @@ public class HttpProducer extends Defaul
// is a query string provided in the endpoint URI or in a header (header overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ // We should user the query string from the HTTP_URI header
+ if (queryString == null) {
+ queryString = uri.getQuery();
+ }
+
if (queryString == null) {
queryString = getEndpoint().getHttpUri().getRawQuery();
}
Modified: camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java (original)
+++ camel/branches/camel-2.8.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java Sun Oct 9 08:44:50 2011
@@ -22,6 +22,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -216,11 +217,24 @@ public final class HttpHelper {
*
* @param exchange the exchange
* @return the created method
+ * @throws URISyntaxException
*/
- public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) {
+ public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ // We need also check the HTTP_URI header query part
+ String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
+ // resolve placeholders in uriString
+ try {
+ uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
+ } catch (Exception e) {
+ throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
+ }
+ if (uriString != null) {
+ URI uri = new URI(uriString);
+ queryString = uri.getQuery();
+ }
if (queryString == null) {
queryString = endpoint.getHttpUri().getRawQuery();
}
Modified: camel/branches/camel-2.8.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerSelectMethodTest.java Sun Oct 9 08:44:50 2011
@@ -131,6 +131,23 @@ public class HttpProducerSelectMethodTes
producer.process(exchange);
producer.stop();
}
+
+ @Test
+ public void withHttpURIInHeader() throws Exception {
+ localServer.register("/", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent()));
+
+ HttpComponent component = context.getComponent("http4", HttpComponent.class);
+
+ HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http4://" + getHostName() + ":" + getPort());
+ HttpProducer producer = new HttpProducer(endpoiont);
+
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + getHostName() + ":" + getPort() + "?q=Camel");
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
@Test
public void withQueryInHeaderOverrideEndpoint() throws Exception {
Modified: camel/branches/camel-2.8.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java?rev=1180567&r1=1180566&r2=1180567&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java Sun Oct 9 08:44:50 2011
@@ -86,6 +86,18 @@ public class HttpClientRouteTest extends
template.sendBody("direct:start4", "test");
mockEndpoint.assertIsSatisfied();
}
+
+ @Test
+ public void testHttpRouteWithHttpURI() throws Exception {
+ Exchange exchange = template.send("http://localhost:" + port2 + "/querystring", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("");
+ exchange.getIn().setHeader(Exchange.HTTP_URI, "http://localhost:" + port2 + "/querystring?id=test");
+ }
+ });
+ assertEquals("Get a wrong response.", "test", exchange.getOut().getBody(String.class));
+ }
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {