camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r787384 - in /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/main/java/org/apache/camel/component/jetty/ camel-jetty/src/test/java/...
Date Mon, 22 Jun 2009 20:27:56 GMT
Author: hadrian
Date: Mon Jun 22 20:27:56 2009
New Revision: 787384

URL: http://svn.apache.org/viewvc?rev=787384&view=rev
Log:
CAMEL-1078.  Removed the HttpExchange and used DefaultExchange instead preserving semantics.

Removed:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpExchange.java
Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
Mon Jun 22 20:27:56 2009
@@ -24,11 +24,16 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.DefaultExchange;
+
 /**
  * @version $Revision$
  */
 public class CamelServlet extends HttpServlet {
 
+    private static final long serialVersionUID = -7061982839117697829L;
+
     private ConcurrentHashMap<String, HttpConsumer> consumers = new ConcurrentHashMap<String,
HttpConsumer>();
     private boolean matchOnUriPrefix;
 
@@ -48,7 +53,10 @@
             }
 
             // Have the camel process the HTTP exchange.
-            HttpExchange exchange = new HttpExchange(consumer.getEndpoint(), request, response);
+            DefaultExchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
+            exchange.setProperty(HttpConstants.SERVLET_REQUEST, request);
+            exchange.setProperty(HttpConstants.SERVLET_RESPONSE, response);
+            exchange.setIn(new HttpMessage(exchange, request));
             consumer.getProcessor().process(exchange);
 
             // HC: The getBinding() is interesting because it illustrates the
@@ -94,5 +102,4 @@
     public void setMatchOnUriPrefix(boolean matchOnUriPrefix) {
         this.matchOnUriPrefix = matchOnUriPrefix;
     }
-
 }

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=787384&r1=787383&r2=787384&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
Mon Jun 22 20:27:56 2009
@@ -95,7 +95,7 @@
         headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
     }
 
-    public void writeResponse(HttpExchange exchange, HttpServletResponse response) throws
IOException {
+    public void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException
{
         if (exchange.isFailed()) {
             if (exchange.hasFault()) {
                 doWriteFaultResponse(exchange.getFault(), response, exchange);

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
Mon Jun 22 20:27:56 2009
@@ -65,7 +65,7 @@
      * @param response the http response
      * @throws java.io.IOException can be thrown from http response
      */
-    void writeResponse(HttpExchange exchange, HttpServletResponse response) throws IOException;
+    void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException;
 
     /**
      * Strategy method that writes the response to the http response stream when an exception
occuerd

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
Mon Jun 22 20:27:56 2009
@@ -21,10 +21,11 @@
  */
 public final class HttpConstants {
 
+    public static final String SERVLET_REQUEST = "Servlet-Request";
+    public static final String SERVLET_RESPONSE = "Servlet-Response";
     public static final String CONTENT_ENCODING = "Content-Encoding";
 
     private HttpConstants() {
         // utility class
     }
-
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Mon Jun 22 20:27:56 2009
@@ -25,6 +25,7 @@
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.impl.DefaultPollingEndpoint;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
@@ -78,11 +79,15 @@
     }
 
     public Exchange createExchange(ExchangePattern pattern) {
-        return new HttpExchange(this, pattern);
+        return new DefaultExchange(this, pattern);
     }
 
-    public HttpExchange createExchange(HttpServletRequest request, HttpServletResponse response)
{
-        return new HttpExchange(this, request, response);
+    public Exchange createExchange(HttpServletRequest request, HttpServletResponse response)
{
+        DefaultExchange exchange = new DefaultExchange(this, ExchangePattern.InOut);
+        exchange.setProperty(HttpConstants.SERVLET_REQUEST, request);
+        exchange.setProperty(HttpConstants.SERVLET_RESPONSE, response);
+        exchange.setIn(new HttpMessage(exchange, request));
+        return exchange;
     }
 
     /**

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
Mon Jun 22 20:27:56 2009
@@ -17,11 +17,10 @@
 package org.apache.camel.component.http;
 
 import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultMessage;
 
@@ -31,18 +30,13 @@
 public class HttpMessage extends DefaultMessage {
     private HttpServletRequest request;
 
-    public HttpMessage(HttpExchange exchange, HttpServletRequest request) {
+    public HttpMessage(Exchange exchange, HttpServletRequest request) {
         setExchange(exchange);
         this.request = request;
 
         // use binding to read the request allowing end users to use their
         // implementation of the binding
-        getExchange().getEndpoint().getBinding().readRequest(request, this);
-    }
-
-    @Override
-    public HttpExchange getExchange() {
-        return (HttpExchange)super.getExchange();
+        getEndpoint().getBinding().readRequest(request, this);
     }
 
     public HttpServletRequest getRequest() {
@@ -52,9 +46,13 @@
     @Override
     protected Object createBody() {
         try {
-            return getExchange().getEndpoint().getBinding().parseBody(this);
+            return getEndpoint().getBinding().parseBody(this);
         } catch (IOException e) {
             throw new RuntimeCamelException(e);
         }
-    }   
+    }
+    
+    private HttpEndpoint getEndpoint() {
+        return (HttpEndpoint) getExchange().getFromEndpoint();
+    }
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
Mon Jun 22 20:27:56 2009
@@ -55,7 +55,7 @@
     }
 
     public Exchange receiveNoWait() {
-        HttpExchange exchange = (HttpExchange) endpoint.createExchange();
+        Exchange exchange = endpoint.createExchange();
         HttpMethod method = createMethod();
 
         try {

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
(original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
Mon Jun 22 20:27:56 2009
@@ -38,7 +38,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody(null);
         try {
             producer.process(exchange);
@@ -56,7 +56,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("This is some data to post");
         try {
             producer.process(exchange);
@@ -74,7 +74,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "POST", null);
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("");
         exchange.getIn().setHeader(Exchange.HTTP_METHOD, POST);
         try {
@@ -93,7 +93,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", null);
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("");
         exchange.getIn().setHeader(Exchange.HTTP_METHOD, GET);
         try {
@@ -112,7 +112,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Camel");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("");
         try {
             producer.process(exchange);
@@ -130,7 +130,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("");
         exchange.getIn().setHeader(Exchange.HTTP_QUERY, "q=Camel");
         try {
@@ -149,7 +149,7 @@
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://www.google.com?q=Donkey");
         MyHttpProducer producer = new MyHttpProducer(endpoiont, "GET", "q=Camel");
 
-        HttpExchange exchange = (HttpExchange) producer.createExchange();
+        Exchange exchange = producer.createExchange();
         exchange.getIn().setBody("");
         exchange.getIn().setHeader(Exchange.HTTP_QUERY, "q=Camel");
         try {

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=787384&r1=787383&r2=787384&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
Mon Jun 22 20:27:56 2009
@@ -22,9 +22,10 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.component.http.CamelServlet;
 import org.apache.camel.component.http.HttpConsumer;
-import org.apache.camel.component.http.HttpExchange;
+import org.apache.camel.component.http.HttpMessage;
 import org.mortbay.util.ajax.Continuation;
 import org.mortbay.util.ajax.ContinuationSupport;
 
@@ -53,9 +54,11 @@
 
             final Continuation continuation = ContinuationSupport.getContinuation(request,
null);
             if (continuation.isNew()) {
-
                 // Have the camel process the HTTP exchange.
-                // final HttpExchange exchange = new HttpExchange(consumer.getEndpoint(),
request, response);
+                // final DefaultExchange exchange = new DefaultExchange(consumer.getEndpoint(),
ExchangePattern.InOut);
+                // exchange.setProperty(HttpConstants.SERVLET_REQUEST, request);
+                // exchange.setProperty(HttpConstants.SERVLET_RESPONSE, response);
+                // exchange.setIn(new HttpMessage(exchange, request));
                 // boolean sync = consumer.getAsyncProcessor().process(exchange, new AsyncCallback()
{
                 //     public void done(boolean sync) {
                 //        if (sync) {
@@ -83,15 +86,13 @@
             }
 
             if (continuation.isResumed()) {
-                HttpExchange exchange = (HttpExchange)continuation.getObject();
+                Exchange exchange = (Exchange)continuation.getObject();
                 // now lets output to the response
                 consumer.getBinding().writeResponse(exchange, response);
                 return;
             }
-
         } catch (Exception e) {
             throw new ServletException(e);
         }
     }
-
 }

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=787384&r1=787383&r2=787384&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
Mon Jun 22 20:27:56 2009
@@ -23,13 +23,14 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.http.HttpExchange;
+import org.apache.camel.component.http.HttpConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.stream.InputStreamCache;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -98,8 +99,9 @@
                 Processor proc = new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         try {
-                            HttpSession session =
-                                ((HttpExchange)exchange).getRequest().getSession();
+                            HttpServletRequest request = (HttpServletRequest)
+                                exchange.getProperty(HttpConstants.SERVLET_REQUEST);
+                            HttpSession session = request.getSession();
                             assertNotNull("we should get session here", session);
                         } catch (Exception e) {
                             exchange.getFault().setBody(e);

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java?rev=787384&r1=787383&r2=787384&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java
Mon Jun 22 20:27:56 2009
@@ -16,12 +16,13 @@
  */
 package org.apache.camel.component.jetty;
 
+import javax.servlet.http.HttpServletRequest;
+
 import junit.framework.Assert;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.http.HttpConstants;
-import org.apache.camel.component.http.HttpExchange;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -38,8 +39,8 @@
     public void testHttpGetWithParamsViaURI() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Bye World");
-        mock.expectedHeaderReceived("one", "einz");
-        mock.expectedHeaderReceived("two", "twei");
+        mock.expectedHeaderReceived("one", "eins");
+        mock.expectedHeaderReceived("two", "zwei");
 
         template.requestBody(serverUri + "?one=uno&two=dos", "Hello World");
 
@@ -50,8 +51,8 @@
     public void testHttpGetWithParamsViaHeader() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Bye World");
-        mock.expectedHeaderReceived("one", "einz");
-        mock.expectedHeaderReceived("two", "twei");
+        mock.expectedHeaderReceived("one", "eins");
+        mock.expectedHeaderReceived("two", "zwei");
 
         template.requestBodyAndHeader(serverUri, "Hello World", Exchange.HTTP_QUERY, "one=uno&two=dos");
 
@@ -68,15 +69,15 @@
 
     private class MyParamsProcessor implements Processor {
         public void process(Exchange exchange) throws Exception {
-            HttpExchange http = (HttpExchange) exchange;
-            Assert.assertNotNull(http.getRequest());
-            Assert.assertEquals("uno", http.getRequest().getParameter("one"));
-            Assert.assertEquals("dos", http.getRequest().getParameter("two"));
+            HttpServletRequest request = (HttpServletRequest)
+                exchange.getProperty(HttpConstants.SERVLET_REQUEST);
+            Assert.assertNotNull(request);
+            Assert.assertEquals("uno", request.getParameter("one"));
+            Assert.assertEquals("dos", request.getParameter("two"));
 
             exchange.getOut().setBody("Bye World");
-            exchange.getOut().setHeader("one", "einz");
-            exchange.getOut().setHeader("two", "twei");
+            exchange.getOut().setHeader("one", "eins");
+            exchange.getOut().setHeader("two", "zwei");
         }
     }
-
 }



Mime
View raw message