camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r774740 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/util/ components/camel-http/src/main/java/org/apache/camel/component/http/ components/camel-jetty/src/test/java/org/apache/camel...
Date Thu, 14 May 2009 12:08:08 GMT
Author: ningjiang
Date: Thu May 14 12:08:08 2009
New Revision: 774740

URL: http://svn.apache.org/viewvc?rev=774740&view=rev
Log:
CAMEL-1594 Finished the camel-jhc part, also fixed the camel-jhc unit test error

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.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/HttpConstants.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java
    camel/trunk/components/camel-jhc/pom.xml
    camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConsumer.java
    camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConverter.java
    camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcHeaderFilterStrategy.java
    camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcProducer.java
    camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcServerEngine.java
    camel/trunk/components/camel-jhc/src/test/java/org/apache/camel/component/jhc/HttpTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Thu May 14 12:08:08
2009
@@ -31,7 +31,9 @@
 public interface Exchange {
 
     String ASYNC_WAIT = "CamelAsyncWait";
-    String CAMEL_CONTENT_TYPE = "CamelConentType";
+    String CONTENT_TYPE = "CamelConentType";
+    String HTTP_RESPONSE_CODE = "CamelHttpResponseCode";
+    String HTTP_URI = "CamelHttpUri";
 
     String BEAN_METHOD_NAME = "CamelBeanMethodName";
     String BEAN_HOLDER = "CamelBeanHolder";

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java Thu May
14 12:08:08 2009
@@ -103,7 +103,7 @@
      * Returns the MIME content type on the message or null if one is not defined
      */
     public static String getContentType(Message message) {        
-        String contentType = message.getHeader(Exchange.CAMEL_CONTENT_TYPE, String.class);
+        String contentType = message.getHeader(Exchange.CONTENT_TYPE, String.class);
         if (contentType == null) {
             // fallback with the Content-Type
             contentType = message.getHeader("Content-Type", String.class);

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=774740&r1=774739&r2=774740&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
Thu May 14 12:08:08 2009
@@ -63,7 +63,7 @@
             Object value = request.getHeader(name);
             // mapping the content-type 
             if (name.toLowerCase().equals("content-type")) {
-                name = Exchange.CAMEL_CONTENT_TYPE;
+                name = Exchange.CONTENT_TYPE;
             }
             if (headerFilterStrategy != null
                 && !headerFilterStrategy.applyFilterToExternalHeaders(name, value,
message.getExchange())) {
@@ -88,7 +88,7 @@
         headers.put(HttpConstants.HTTP_METHOD, request.getMethod());
         headers.put(HttpConstants.HTTP_QUERY, request.getQueryString());
         headers.put(HttpConstants.HTTP_PATH, request.getPathInfo());
-        headers.put(HttpConstants.HTTP_CONTENT_TYPE, request.getContentType());
+        headers.put(Exchange.CONTENT_TYPE, request.getContentType());
         headers.put(HttpConstants.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
         
     }
@@ -134,8 +134,8 @@
 
     public void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange)
throws IOException {
         // set the status code in the response. Default is 200.
-        if (message.getHeader(HttpConstants.HTTP_RESPONSE_CODE) != null) {
-            int code = message.getHeader(HttpConstants.HTTP_RESPONSE_CODE, Integer.class);
+        if (message.getHeader(Exchange.HTTP_RESPONSE_CODE) != null) {
+            int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
             response.setStatus(code);
         }
         // set the content type in the response.

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=774740&r1=774739&r2=774740&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
Thu May 14 12:08:08 2009
@@ -19,9 +19,7 @@
 /**
  * Constants
  */
-public final class HttpConstants {
-
-    public static final String HTTP_CONTENT_TYPE = "CamelHttpContentType";
+public final class HttpConstants {    
 
     public static final String HTTP_CHARACTER_ENCODING = "CamelHttpCharacterEncoding";
 
@@ -31,10 +29,6 @@
 
     public static final String HTTP_QUERY = "CamelHttpQuery";
 
-    public static final String HTTP_RESPONSE_CODE = "CamelHttpResponseCode";
-
-    public static final String HTTP_URI = "CamelHttpUri";
-
     private HttpConstants() {
         // utility class
     }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
Thu May 14 12:08:08 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.http;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultHeaderFilterStrategy;
 
 /**
@@ -31,8 +32,7 @@
         getOutFilter().add("content-length");
         getOutFilter().add("content-type");
         getOutFilter().add(HttpConstants.HTTP_METHOD.toLowerCase());
-        getOutFilter().add(HttpConstants.HTTP_QUERY);
-        getOutFilter().add(HttpConstants.HTTP_RESPONSE_CODE.toLowerCase());
+        getOutFilter().add(HttpConstants.HTTP_QUERY);        
         setLowerCase(true);
         
         // filter headers begin with "Camel" or "org.apache.camel"

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=774740&r1=774739&r2=774740&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
Thu May 14 12:08:08 2009
@@ -83,7 +83,7 @@
                 }
             }
         
-            message.setHeader(HttpConstants.HTTP_RESPONSE_CODE, responseCode);
+            message.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
             return exchange;
         } catch (IOException e) {
             throw new RuntimeCamelException(e);

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Thu May 14 12:08:08 2009
@@ -99,7 +99,7 @@
         Message answer = exchange.getOut();
 
         //answer.setHeaders(in.getHeaders());
-        answer.setHeader(HttpConstants.HTTP_RESPONSE_CODE, responseCode);
+        answer.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
         answer.setBody(extractResponseBody(method, exchange));
 
         // propagate HTTP response headers
@@ -108,7 +108,7 @@
             String name = header.getName();
             String value = header.getValue();
             if (name.toLowerCase().equals("content-type")) {
-                name = Exchange.CAMEL_CONTENT_TYPE;
+                name = Exchange.CONTENT_TYPE;
             }
             if (strategy != null && !strategy.applyFilterToExternalHeaders(name,
value, exchange)) {
                 answer.setHeader(name, value);
@@ -200,7 +200,7 @@
             methodToUse = requestEntity != null ? HttpMethods.POST : HttpMethods.GET;
         }
 
-        String uri = exchange.getIn().getHeader(HttpConstants.HTTP_URI, String.class);
+        String uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
         if (uri == null) {
             uri = ((HttpEndpoint)getEndpoint()).getHttpUri().toString();
         }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
Thu May 14 12:08:08 2009
@@ -84,7 +84,7 @@
                 exchange.getOut().setHeader("Content-Type", "text/xml");
             } else {
                 exchange.getOut().setBody("FAIL");
-                exchange.getOut().setHeader(Exchange.CAMEL_CONTENT_TYPE, "text/plain");
+                exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
             }
         }
     }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
Thu May 14 12:08:08 2009
@@ -35,7 +35,7 @@
     public void testSimulate404() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Page not found");
-        mock.expectedHeaderReceived(HttpConstants.HTTP_RESPONSE_CODE, 404);
+        mock.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 404);
 
         template.sendBody("direct:start", "Hello World");
 
@@ -53,7 +53,7 @@
                 from("direct:start").enrich("direct:tohttp", new AggregationStrategy() {
                     public Exchange aggregate(Exchange original, Exchange resource) {
                         // get the response code
-                        Integer code = resource.getOut().getHeader(HttpConstants.HTTP_RESPONSE_CODE,
Integer.class);
+                        Integer code = resource.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE,
Integer.class);
                         assertEquals(404, code.intValue());
                         return resource;
                     }
@@ -70,7 +70,7 @@
                                     // copy the caused exception values to the exchange as
we want the response in the regular exchange
                                     // instead as an exception that will get thrown and thus
the route breaks
                                     HttpOperationFailedException cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
HttpOperationFailedException.class);
-                                    exchange.getOut().setHeader(HttpConstants.HTTP_RESPONSE_CODE,
cause.getStatusCode());
+                                    exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
cause.getStatusCode());
                                     exchange.getOut().setBody(cause.getResponseBody());
                                 }
                             })
@@ -82,7 +82,7 @@
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 exchange.getOut().setBody("Page not found");
-                                exchange.getOut().setHeader(HttpConstants.HTTP_RESPONSE_CODE,
404);
+                                exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
404);
                             }
                         });
             }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java
Thu May 14 12:08:08 2009
@@ -34,7 +34,7 @@
     public void testSimulate404() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Page not found");
-        mock.expectedHeaderReceived(HttpConstants.HTTP_RESPONSE_CODE, 404);
+        mock.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 404);
 
         template.sendBody("direct:start", "Hello World");
 
@@ -57,7 +57,7 @@
                 from("direct:start").enrich("http://localhost:8222/myserver?throwExceptionOnFailure=false&user=Camel",
new AggregationStrategy() {
                     public Exchange aggregate(Exchange original, Exchange resource) {
                         // get the response code
-                        Integer code = resource.getOut().getHeader(HttpConstants.HTTP_RESPONSE_CODE,
Integer.class);
+                        Integer code = resource.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE,
Integer.class);
                         assertEquals(404, code.intValue());
                         return resource;
                     }
@@ -68,7 +68,7 @@
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 exchange.getOut().setBody("Page not found");
-                                exchange.getOut().setHeader(HttpConstants.HTTP_RESPONSE_CODE,
404);
+                                exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
404);
                             }
                         });
                 // END SNIPPET: e1

Modified: camel/trunk/components/camel-jhc/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/pom.xml?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/pom.xml (original)
+++ camel/trunk/components/camel-jhc/pom.xml Thu May 14 12:08:08 2009
@@ -60,6 +60,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-http</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
@@ -90,7 +95,7 @@
           </includes>
           <excludes>
             <!-- TODO disable for now as its causing the CI build to hang -->
-            <exclude>**/HttpTest.*</exclude>
+            <!--  exclude>**/HttpTest.*</exclude-->
           </excludes>
         </configuration>
       </plugin>

Modified: camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConsumer.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConsumer.java
(original)
+++ camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConsumer.java
Thu May 14 12:08:08 2009
@@ -155,8 +155,11 @@
             LOG.debug("handleExchange");
             // create the default response to this request
             ProtocolVersion httpVersion = (HttpVersion)request.getRequestLine().getProtocolVersion();
-
-            HttpResponse response = responseFactory.newHttpResponse(httpVersion, HttpStatus.SC_OK,
context);
+            Integer responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE,
Integer.class);
+            if (responseCode == null) {
+                responseCode = HttpStatus.SC_OK;
+            }
+            HttpResponse response = responseFactory.newHttpResponse(httpVersion, responseCode,
context);
             response.setParams(params);
             HttpEntity entity = exchange.getOut().getBody(HttpEntity.class);
             response.setEntity(entity);
@@ -164,7 +167,7 @@
             try {
                 handler.sendResponse(response);
             } catch (Exception e) {
-                LOG.info(e);
+                LOG.info("Get exception when send the reponse" + e);
             }
         }
 

Modified: camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConverter.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConverter.java
(original)
+++ camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcConverter.java
Thu May 14 12:08:08 2009
@@ -21,6 +21,7 @@
 import java.io.UnsupportedEncodingException;
 
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
@@ -60,7 +61,8 @@
     }
 
     @Converter
-    public static HttpEntity toEntity(String str) throws UnsupportedEncodingException {
-        return new StringEntity(str);
+    public static HttpEntity toEntity(String str, Exchange exchange) throws UnsupportedEncodingException
{
+        String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+        return new StringEntity(str, charset);
     }
 }

Modified: camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcHeaderFilterStrategy.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcHeaderFilterStrategy.java
(original)
+++ camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcHeaderFilterStrategy.java
Thu May 14 12:08:08 2009
@@ -32,8 +32,7 @@
         // We could import filters from http component but that also means
         // a new dependency on camel-http
         getOutFilter().add("content-length");
-        getOutFilter().add("content-type");
-        getOutFilter().add(JhcProducer.HTTP_RESPONSE_CODE);
+        getOutFilter().add("content-type");        
         setLowerCase(true);
 
         // filter headers begin with "Camel" or "org.apache.camel"

Modified: camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcProducer.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcProducer.java
(original)
+++ camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcProducer.java
Thu May 14 12:08:08 2009
@@ -28,6 +28,7 @@
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.MessageHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
@@ -59,8 +60,7 @@
 import org.apache.http.protocol.RequestUserAgent;
 
 public class JhcProducer extends DefaultProducer implements Processor {
-
-    public static final String HTTP_RESPONSE_CODE = "http.responseCode";
+    
     private static final transient Log LOG = LogFactory.getLog(JhcProducer.class);
 
     private int nbThreads = 2;
@@ -160,7 +160,7 @@
                 return null;
             }
             entity = new ByteArrayEntity(data);
-            String contentType = in.getHeader("Content-Type", String.class);
+            String contentType = MessageHelper.getContentType(in);
             if (contentType != null) {
                 ((ByteArrayEntity) entity).setContentType(contentType);
             }
@@ -233,6 +233,7 @@
             httpContext.setAttribute(RESPONSE_RECEIVED, Boolean.TRUE);
             Exchange e = (Exchange) httpContext.getAttribute(Exchange.class.getName());
             e.getOut().setBody(httpResponse.getEntity());
+            System.out.println("the response is " + e.getOut().getBody(String.class));
             
             HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy();
             for (Iterator it = httpResponse.headerIterator(); it.hasNext();) {
@@ -242,7 +243,7 @@
                 }
             }
             
-            e.getOut().setHeader(HTTP_RESPONSE_CODE, httpResponse.getStatusLine().getStatusCode());
+            e.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponse.getStatusLine().getStatusCode());
         }
 
         public void finalizeContext(HttpContext httpContext) {

Modified: camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcServerEngine.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcServerEngine.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcServerEngine.java
(original)
+++ camel/trunk/components/camel-jhc/src/main/java/org/apache/camel/component/jhc/JhcServerEngine.java
Thu May 14 12:08:08 2009
@@ -21,6 +21,8 @@
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import javax.net.ssl.SSLContext;
 
 import org.apache.commons.logging.Log;
@@ -30,6 +32,7 @@
 import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListeningIOReactor;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpRequestHandlerRegistry;
@@ -46,7 +49,7 @@
     private SSLContext sslContext;
     private AsyncBufferingHttpServiceHandler serviceHandler;
     private HttpRequestHandlerRegistry handlerRegistry;
-    private boolean isStarted;
+    private AtomicBoolean isStarted = new AtomicBoolean(false);
     private int referenceCounter;
 
     JhcServerEngine(HttpParams params, int port, String protocol) {
@@ -90,7 +93,7 @@
     }
 
     public boolean isStarted() {
-        return isStarted;
+        return isStarted.get();
     }
 
     public void start() throws IOReactorException {
@@ -106,9 +109,10 @@
         runner = new Thread() {
             public void run() {
                 try {
-                    ioReactor.listen(addr);
-                    isStarted = true;
-                    ioReactor.execute(ioEventDispatch);
+                    if (!isStarted.getAndSet(true)) {
+                        ioReactor.listen(addr);
+                        ioReactor.execute(ioEventDispatch);
+                    }
                 } catch (InterruptedIOException ex) {
                     LOG.info("Interrupted");
                 } catch (IOException e) {
@@ -129,7 +133,7 @@
         } catch (InterruptedException e) {
             //do nothing here
         }
-        isStarted = false;
+        isStarted.getAndSet(false);
         LOG.debug("Runner stopped");
     }
 }

Modified: camel/trunk/components/camel-jhc/src/test/java/org/apache/camel/component/jhc/HttpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jhc/src/test/java/org/apache/camel/component/jhc/HttpTest.java?rev=774740&r1=774739&r2=774740&view=diff
==============================================================================
--- camel/trunk/components/camel-jhc/src/test/java/org/apache/camel/component/jhc/HttpTest.java
(original)
+++ camel/trunk/components/camel-jhc/src/test/java/org/apache/camel/component/jhc/HttpTest.java
Thu May 14 12:08:08 2009
@@ -25,6 +25,7 @@
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -46,7 +47,7 @@
         mockEndpoint.expectedMessageCount(1);
 
         template.sendBody("direct:start", null);
-
+        
         mockEndpoint.assertIsSatisfied();
         List<Exchange> list = mockEndpoint.getReceivedExchanges();
         Exchange exchange = list.get(0);
@@ -56,8 +57,7 @@
         assertNotNull("in", in);
 
         String body = in.getBody(String.class);
-
-        log.debug("Body: " + body);
+        
         assertNotNull("Should have a body!", body);
         assertTrue("body should contain: " + expectedText, body.contains(expectedText));
     }
@@ -75,7 +75,7 @@
             con.setDoInput(true);
             con.setDoOutput(false);
             con.connect();
-            System.err.println("Message: " + con.getResponseMessage());
+            log.info("Message: " + con.getResponseMessage());
             InputStream is = con.getInputStream();
             byte[] buf = new byte[8192];
             int len;
@@ -88,7 +88,7 @@
                 baos.write(buf, 0, len);
             }
             String str = baos.toString();
-            System.err.println("Response: " + str);
+            log.info("Response: " + str);
             assertEquals("request using url" + url + "can't get the expert result", 
                          expect, str);
         }
@@ -99,8 +99,10 @@
         return new RouteBuilder() {
             public void configure() {
                 from("jhc:http://localhost:8192/test1").transform(constant("<response>
Test1<response/>"));
-                from("direct:start").to("jhc:http://localhost:8192/test1/pom.xml").to("mock:results");
                 from("jhc:http://localhost:8192/test2").transform(constant("<response>
Test2<response/>"));
+                //TODO we need revisit this test when the call back Done API is finished
in Camel 2.0
+                from("direct:start").to("http://localhost:8192/test1/pom.xml").to("mock:results");
+                
             }
         };
     }



Mime
View raw message