camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1066039 - in /camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-http/src/main/java/org/apache/camel/component/http/helper/ camel-jetty/src/main/java/org/apache/camel/component/jetty/ camel-jetty/src/te...
Date Tue, 01 Feb 2011 13:30:46 GMT
Author: ningjiang
Date: Tue Feb  1 13:30:45 2011
New Revision: 1066039

URL: http://svn.apache.org/viewvc?rev=1066039&view=rev
Log:
CAMEL-3608 HttpProducer should keep the content-type when it is working as a proxy

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
  (with props)
Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
Tue Feb  1 13:30:45 2011
@@ -61,7 +61,12 @@ public class RequestEntityConverter {
                 .getHeader(Exchange.CONTENT_ENCODING, String.class), in), ExchangeHelper
                 .getContentType(exchange));
         } else {
-            return new InputStreamRequestEntity(in);
+            // should set the content type here
+            if (exchange != null) {
+                return new InputStreamRequestEntity(in, ExchangeHelper.getContentType(exchange));
+            } else {
+                return new InputStreamRequestEntity(in);
+            }
         }
     }
 
@@ -72,7 +77,12 @@ public class RequestEntityConverter {
                 .getHeader(Exchange.CONTENT_ENCODING, String.class), data), ExchangeHelper
                 .getContentType(exchange));
         } else {
-            return new InputStreamRequestEntity(new ByteArrayInputStream(data));
+            // should set the content type here
+            if (exchange != null) {
+                return new InputStreamRequestEntity(new ByteArrayInputStream(data), ExchangeHelper.getContentType(exchange));
+            } else {
+                return new InputStreamRequestEntity(new ByteArrayInputStream(data));
+            }
         }
     }
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
Tue Feb  1 13:30:45 2011
@@ -51,7 +51,7 @@ public final class HttpHelper {
             }
         }
     }
-
+    
     /**
      * Writes the given object as response body to the servlet response
      * <p/>

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
Tue Feb  1 13:30:45 2011
@@ -27,6 +27,7 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.component.http.CamelServlet;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpMessage;
+import org.apache.camel.component.http.helper.HttpHelper;
 import org.apache.camel.impl.DefaultExchange;
 import org.eclipse.jetty.continuation.Continuation;
 import org.eclipse.jetty.continuation.ContinuationSupport;
@@ -87,6 +88,8 @@ public class CamelContinuationServlet ex
             if (consumer.getEndpoint().isDisableStreamCache()) {
                 exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE);
             }
+            
+            HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
             exchange.setIn(new HttpMessage(exchange, request, response));
 
             if (log.isTraceEnabled()) {

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
Tue Feb  1 13:30:45 2011
@@ -22,20 +22,19 @@ import java.io.UnsupportedEncodingExcept
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangeTimedOutException;
 import org.apache.camel.util.IOHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.client.ContentExchange;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.HttpExchange;
 import org.eclipse.jetty.http.HttpHeaders;
 import org.eclipse.jetty.io.Buffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Jetty specific exchange which keeps track of the the request and response.

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Tue Feb  1 13:30:45 2011
@@ -39,8 +39,6 @@ import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.client.Address;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.jmx.MBeanContainer;
@@ -60,6 +58,8 @@ import org.eclipse.jetty.servlets.MultiP
 import org.eclipse.jetty.util.component.LifeCycle;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.util.thread.ThreadPool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * An HttpComponent which starts an embedded Jetty for to handle consuming from

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
Tue Feb  1 13:30:45 2011
@@ -39,11 +39,10 @@ import org.apache.camel.util.ExchangeHel
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Revision$

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java
Tue Feb  1 13:30:45 2011
@@ -21,9 +21,9 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.junit.Test;
 
 /**
  * @version $Revision$

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java?rev=1066039&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
(added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
Tue Feb  1 13:30:45 2011
@@ -0,0 +1,54 @@
+/**
+ * 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.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.StopWatch;
+import org.apache.camel.util.TimeUtils;
+import org.junit.Test;
+
+public class HttpProxyRouteContentTypeTest extends BaseJettyTest {
+
+    @Test
+    public void testHttpProxyWithContentType() throws Exception {
+       
+        String out = template.requestBodyAndHeader("http://localhost:{{port}}/hello", "test",
 "Content-Type", "application/xml", String.class);
+
+        assertEquals("Get a wrong response ", "application/xml", out);
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("jetty://http://localhost:{{port}}/hello").to("http://localhost:{{port}}/bye?throwExceptionOnFailure=false&bridgeEndpoint=true");
+
+                from("jetty://http://localhost:{{port}}/bye").process(new Processor() {
+
+                    public void process(Exchange exchange) throws Exception {
+                        
+                        exchange.getOut().setBody(ExchangeHelper.getContentType(exchange));
+                    }
+                    
+                });
+            }
+        };
+    }    
+
+}

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java?rev=1066039&r1=1066038&r2=1066039&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
Tue Feb  1 13:30:45 2011
@@ -30,12 +30,12 @@ import org.apache.camel.RuntimeCamelExce
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.test.junit4.TestSupport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 



Mime
View raw message