camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r835332 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/util/ 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-htt...
Date Thu, 12 Nov 2009 10:56:35 GMT
Author: davsclaus
Date: Thu Nov 12 10:56:34 2009
New Revision: 835332

URL: http://svn.apache.org/viewvc?rev=835332&view=rev
Log:
CAMEL-2135: JettyHttpProducer now works properly. Added more unit tests. Fixed issue with GET parameters. HttpOperationFailedException now use java types only so it can be sent over the remote network with API dependency on apache commons http. Also used by JettyHttpProducer.

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProderReturnFaultTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerContentBasedRouteTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamAsExchangeHeaderTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java
      - copied, changed from r835302, 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/jettyproducer/JettyProducerHttpsRouteTest.java
      - copied, changed from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java
Removed:
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.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/JettyHttpBinding.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/HttpsRouteTest.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/JettyResponseBodyWhenErrorTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java Thu Nov 12 10:56:34 2009
@@ -72,7 +72,8 @@
             String schemeSpecificPart = uri.getSchemeSpecificPart();
             int idx = schemeSpecificPart.lastIndexOf('?');
             if (idx < 0) {
-                return Collections.emptyMap();
+                // return an empty map
+                return new LinkedHashMap<String, Object>(0);
             } else {
                 query = schemeSpecificPart.substring(idx + 1);
             }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java Thu Nov 12 10:56:34 2009
@@ -17,35 +17,30 @@
 package org.apache.camel.component.http;
 
 import java.io.InputStream;
+import java.util.Map;
 
 import org.apache.camel.CamelException;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.StatusLine;
 
 public class HttpOperationFailedException extends CamelException {
-    private static final long serialVersionUID = -8721487434390572633L;
+    private static final long serialVersionUID = -8721487434390572634L;
     private final String uri;
     private final String redirectLocation;
     private final int statusCode;
-    private final StatusLine statusLine;
-    private final Header[] responseHeaders;
-    private final InputStream responseBody;
+    private final String statusText;
+    private final Map<String, String> responseHeaders;
+    private final String responseBody;
 
-    public HttpOperationFailedException(String uri, int statusCode, StatusLine statusLine, String location, Header[] responseHeaders, InputStream responseBody) {
-        super("HTTP operation failed invoking " + uri + " with statusCode: " + statusCode + ", status: " + statusLine + (location != null ? ", redirectLocation: " + location : ""));
+    public HttpOperationFailedException(String uri, int statusCode, String statusText, String location, Map<String, String> responseHeaders, String responseBody) {
+        super("HTTP operation failed invoking " + uri + " with statusCode: " + statusCode + (location != null ? ", redirectLocation: " + location : ""));
         this.uri = uri;
         this.statusCode = statusCode;
-        this.statusLine = statusLine;
+        this.statusText = statusText;
         this.redirectLocation = location;
         this.responseHeaders = responseHeaders;
         this.responseBody = responseBody;
     }
 
-    public HttpOperationFailedException(String uri, int statusCode, StatusLine statusLine, Header[] responseHeaders, InputStream responseBody) {
-        this(uri, statusCode, statusLine, null, responseHeaders, responseBody);
-    }
-
     public String getUri() {
         return uri;
     }
@@ -62,19 +57,19 @@
         return redirectLocation;
     }
 
-    public StatusLine getStatusLine() {
-        return statusLine;
-    }
-
     public int getStatusCode() {
         return statusCode;
     }
 
-    public Header[] getResponseHeaders() {
+    public String getStatusText() {
+        return statusText;
+    }
+
+    public Map<String, String> getResponseHeaders() {
         return responseHeaders;
     }
 
-    public InputStream getResponseBody() {
+    public String getResponseBody() {
         return responseBody;
     }
 

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=835332&r1=835331&r2=835332&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 Nov 12 10:56:34 2009
@@ -20,6 +20,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -83,7 +85,7 @@
                 populateResponse(exchange, method, in, strategy, responseCode);
             } else {
                 if (responseCode >= 100 && responseCode < 300) {
-                    // only populate reponse for OK response
+                    // only populate response for OK response
                     populateResponse(exchange, method, in, strategy, responseCode);
                 } else {
                     // operation failed so populate exception to throw
@@ -124,12 +126,13 @@
     protected HttpOperationFailedException populateHttpOperationFailedException(Exchange exchange, HttpMethod method, int responseCode) throws IOException {
         HttpOperationFailedException exception;
         String uri = method.getURI().toString();
-        Header[] headers = method.getResponseHeaders();
+        String statusText = method.getStatusLine() != null ? method.getStatusLine().getReasonPhrase() : null;
+        Map<String, String> headers = extractResponseHeaders(method.getResponseHeaders());
         InputStream is = extractResponseBody(method, exchange);
         // make a defensive copy of the response body in the exception so its detached from the cache
-        InputStream copy = null;
+        String copy = null;
         if (is != null) {
-            copy = new ByteArrayInputStream(exchange.getContext().getTypeConverter().convertTo(byte[].class, is));
+            copy = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, is);
         }
 
         if (responseCode >= 300 && responseCode < 400) {
@@ -137,14 +140,14 @@
             Header locationHeader = method.getResponseHeader("location");
             if (locationHeader != null) {
                 redirectLocation = locationHeader.getValue();
-                exception = new HttpOperationFailedException(uri, responseCode, method.getStatusLine(), redirectLocation, headers, copy);
+                exception = new HttpOperationFailedException(uri, responseCode, statusText, redirectLocation, headers, copy);
             } else {
                 // no redirect location
-                exception = new HttpOperationFailedException(uri, responseCode, method.getStatusLine(), headers, copy);
+                exception = new HttpOperationFailedException(uri, responseCode, statusText, null, headers, copy);
             }
         } else {
             // internal server error (error code 500)
-            exception = new HttpOperationFailedException(uri, responseCode, method.getStatusLine(), headers, copy);
+            exception = new HttpOperationFailedException(uri, responseCode, statusText, null, headers, copy);
         }
 
         return exception;
@@ -162,6 +165,25 @@
     }
 
     /**
+     * Extracts the response headers
+     *
+     * @param responseHeaders the headers
+     * @return the extracted headers or <tt>null</tt> if no headers existed
+     */
+    protected static Map<String, String> extractResponseHeaders(Header[] responseHeaders) {
+        if (responseHeaders == null || responseHeaders.length == 0) {
+            return null;
+        }
+
+        Map<String, String> answer = new HashMap<String, String>();
+        for (Header header : responseHeaders) {
+            answer.put(header.getName(), header.getValue());
+        }
+
+        return answer;
+    }
+
+    /**
      * Extracts the response from the method as a InputStream.
      *
      * @param method  the method that was executed

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java Thu Nov 12 10:56:34 2009
@@ -43,7 +43,7 @@
         }
     }
 
-    public static InputStream toGZIPInputStream(String contentEncoding, byte[] data) throws Exception {
+    public static InputStream toGZIPInputStream(String contentEncoding, byte[] data) throws IOException {
         if (isGzip(contentEncoding)) {
             ByteArrayOutputStream os = null;
             GZIPOutputStream gzip = null;

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java (original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.http;
 
 import java.util.List;
@@ -58,7 +57,7 @@
         int statusCode = exception.getStatusCode();
         assertTrue("The response code should not be 200", statusCode != 200);
 
-        String reason = exception.getStatusLine().getReasonPhrase();
+        String reason = exception.getStatusText();
 
         assertNotNull("Should have a body!", reason);
 

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java Thu Nov 12 10:56:34 2009
@@ -22,6 +22,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.component.http.HttpHeaderFilterStrategy;
+import org.apache.camel.component.http.HttpOperationFailedException;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -79,12 +80,12 @@
 
         answer.setHeaders(in.getHeaders());
         answer.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
-        answer.setBody(httpExchange.getBody());
+        answer.setBody(extractResponseBody(exchange, httpExchange));
 
         // propagate HTTP response headers
-        for (Map.Entry<String, Object> entry : httpExchange.getHeaders().entrySet()) {
+        for (Map.Entry<String, String> entry : httpExchange.getHeaders().entrySet()) {
             String name = entry.getKey();
-            Object value = entry.getValue();
+            String value = entry.getValue();
             if (name.toLowerCase().equals("content-type")) {
                 name = Exchange.CONTENT_TYPE;
             }
@@ -94,28 +95,31 @@
         }
     }
 
-    protected JettyHttpOperationFailedException populateHttpOperationFailedException(Exchange exchange, JettyContentExchange httpExchange,
-                                                                                     int responseCode) throws IOException {
-        JettyHttpOperationFailedException exception;
+    protected HttpOperationFailedException populateHttpOperationFailedException(Exchange exchange, JettyContentExchange httpExchange,
+                                                                                int responseCode) throws IOException {
+        HttpOperationFailedException exception;
         String uri = httpExchange.getUrl();
-        Map<String, Object> headers = httpExchange.getHeaders();
-        String body = httpExchange.getBody();
+        Map<String, String> headers = httpExchange.getHeaders();
+        String body = extractResponseBody(exchange, httpExchange);
 
         if (responseCode >= 300 && responseCode < 400) {
             String locationHeader = httpExchange.getResponseFields().getStringField("location");
             if (locationHeader != null) {
-                exception = new JettyHttpOperationFailedException(uri, responseCode, locationHeader, headers, body);
+                exception = new HttpOperationFailedException(uri, responseCode, null, locationHeader, headers, body);
             } else {
                 // no redirect location
-                exception = new JettyHttpOperationFailedException(uri, responseCode, headers, body);
+                exception = new HttpOperationFailedException(uri, responseCode, null, null, headers, body);
             }
         } else {
             // internal server error (error code 500)
-            exception = new JettyHttpOperationFailedException(uri, responseCode, headers, body);
+            exception = new HttpOperationFailedException(uri, responseCode, null, null, headers, body);
         }
 
         return exception;
     }
 
+    protected String extractResponseBody(Exchange exchange, JettyContentExchange httpExchange) throws IOException {
+        return httpExchange.getBody();
+    }
 
 }

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=835332&r1=835331&r2=835332&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 Thu Nov 12 10:56:34 2009
@@ -44,7 +44,7 @@
 
     private static final transient Log LOG = LogFactory.getLog(JettyContentExchange.class);
 
-    private final Map<String, Object> headers = new LinkedHashMap<String, Object>();
+    private final Map<String, String> headers = new LinkedHashMap<String, String>();
     private volatile Exchange exchange;
     private volatile AsyncCallback callback;
     private volatile JettyHttpBinding jettyBinding;
@@ -96,7 +96,7 @@
         doTaskCompleted(ex);
     }
 
-    public Map<String, Object> getHeaders() {
+    public Map<String, String> getHeaders() {
         return headers;
     }
 
@@ -145,7 +145,10 @@
     protected void doTaskCompleted(Throwable ex) {
         // some kind of other error
         exchange.setException(new CamelExchangeException("JettyClient failed cause by: " + ex.getMessage(), exchange, ex));
-        callback.onTaskCompleted(exchange);
+
+        if (callback != null) {
+            callback.onTaskCompleted(exchange);
+        }
     }
 
 }

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java Thu Nov 12 10:56:34 2009
@@ -52,7 +52,7 @@
     void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy);
 
     /**
-     * Whether to throw {@link org.apache.camel.component.jetty.JettyHttpOperationFailedException}
+     * Whether to throw {@link org.apache.camel.component.http.HttpOperationFailedException}
      * in case of response code != 200.
      *
      * @param throwExceptionOnFailure <tt>true</tt> to throw exception
@@ -60,7 +60,7 @@
     void setThrowExceptionOnFailure(boolean throwExceptionOnFailure);
 
     /**
-     * Whether to throw {@link org.apache.camel.component.jetty.JettyHttpOperationFailedException}
+     * Whether to throw {@link org.apache.camel.component.http.HttpOperationFailedException}
      * in case of response code != 200.
      *
      * @return <tt>true</tt> to throw exception

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=835332&r1=835331&r2=835332&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 Thu Nov 12 10:56:34 2009
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
 
@@ -37,7 +38,6 @@
 import org.apache.camel.util.URISupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.mortbay.io.Buffer;
 import org.mortbay.io.ByteArrayBuffer;
 import org.mortbay.jetty.client.HttpClient;
 import org.mortbay.jetty.client.HttpExchange;
@@ -115,6 +115,9 @@
         httpExchange.setMethod(method);
         httpExchange.setURL(url);
 
+        // set query parameters
+        doSetQueryParameters(exchange, httpExchange);
+
         // if we post then set data
         if (HttpMethods.POST.equals(methodToUse)) {
 
@@ -139,8 +142,6 @@
             }
         }
 
-        doSetQueryParameters(exchange, httpExchange);
-
         // and copy headers from IN message
         Message in = exchange.getIn();
         HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy();
@@ -169,9 +170,18 @@
             return;
         }
 
-        Map<String, Object> parameters = URISupport.parseQuery(queryString);
-        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
-            httpExchange.setRequestHeader(entry.getKey(), entry.getValue().toString());
+        // okay we need to add the query string to the URI so we need to juggle a bit with the parameters
+        String uri = httpExchange.getURI();
+
+        Map parameters = URISupport.parseParameters(new URI(uri));
+        parameters.putAll(URISupport.parseQuery(queryString));
+
+        if (uri.contains("?")) {
+            uri = ObjectHelper.before(uri, "?");
+        }
+        if (!parameters.isEmpty()) {
+            uri = uri + "?" + URISupport.createQueryString(parameters);
+            httpExchange.setURI(uri);
         }
     }
 

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java Thu Nov 12 10:56:34 2009
@@ -43,6 +43,10 @@
     protected String expectedBody = "<hello>world!</hello>";
     protected String pwd = "changeit";
     protected Properties originalValues = new Properties();
+
+    public String getHttpProducerScheme() {
+        return "https://";
+    }
     
     @Override
     @Before
@@ -68,7 +72,7 @@
 
     protected void restoreSystemProperties() {
         for (Object key : originalValues.keySet()) {
-            Object value = (String) originalValues.get(key);  
+            Object value = originalValues.get(key);
             if (NULL_VALUE_MARKER.equals(value)) {
                 System.getProperties().remove(key);    
             } else {
@@ -140,8 +144,8 @@
     }
     
     protected void invokeHttpEndpoint() throws IOException {
-        template.sendBodyAndHeader("https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
-        template.sendBodyAndHeader("https://localhost:9090/test", expectedBody, "Content-Type", "application/xml");
+        template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+        template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:9090/test", expectedBody, "Content-Type", "application/xml");
     }
 
     @Override

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=835332&r1=835331&r2=835332&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 Nov 12 10:56:34 2009
@@ -32,6 +32,10 @@
  */
 public class JettyHandle404Test extends CamelTestSupport {
 
+    public String getProducerUrl() {
+        return "http://localhost:8123/myserver?user=Camel";
+    }
+
     @Test
     public void testSimulate404() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -64,7 +68,7 @@
                 // and set the data back as data on the exchange to not cause the exception to be thrown
                 from("direct:tohttp")
                         .doTry()
-                            .to("http://localhost:8123/myserver?user=Camel")
+                            .to(getProducerUrl())
                         .doCatch(HttpOperationFailedException.class)
                             .process(new Processor() {
                                 public void process(Exchange exchange) {

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java Thu Nov 12 10:56:34 2009
@@ -25,7 +25,7 @@
 import org.junit.Test;
 
 /**
- * Unit test for HttpOperationFailedException should contain reponse body
+ * Unit test for HttpOperationFailedException should contain response body
  */
 public class JettyResponseBodyWhenErrorTest extends CamelTestSupport {
 
@@ -41,7 +41,8 @@
             assertTrue(body.indexOf("Damm") > -1);
             assertTrue(body.indexOf("IllegalArgumentException") > -1);
             assertNotNull(cause.getResponseHeaders());
-            assertTrue("Should have http header with content type set", cause.getResponseHeaders()[0].getValue().indexOf("text/plain") > -1);
+            String type = cause.getResponseHeaders().get(Exchange.CONTENT_TYPE);
+            assertTrue(type.startsWith("text/plain"));
         }
     }
 

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProderReturnFaultTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProderReturnFaultTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProderReturnFaultTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProderReturnFaultTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -25,11 +25,11 @@
 /**
  * @version $Revision$
  */
-public class HttpReturnFaultTest extends CamelTestSupport {
+public class JettyHttpProderReturnFaultTest extends CamelTestSupport {
 
     @Test
     public void testHttpFault() throws Exception {
-        String out = template.requestBody("http://localhost:9080/test", "Hello World", String.class);
+        String out = template.requestBody("jetty://http://localhost:9080/test", "Hello World", String.class);
         assertEquals("This is a fault", out);
     }
 
@@ -48,4 +48,4 @@
             }
         };
     }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerContentBasedRouteTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerContentBasedRouteTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerContentBasedRouteTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerContentBasedRouteTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -24,9 +24,9 @@
 /**
  * Unit test with a simple route test.
  */
-public class JettyContentBasedRouteTest extends CamelTestSupport {
+public class JettyHttpProducerContentBasedRouteTest extends CamelTestSupport {
 
-    private String serverUri = "http://localhost:9080/myservice";
+    private String serverUri = "jetty://http://localhost:9080/myservice";
 
     @Test
     public void testSendOne() throws Exception {
@@ -53,15 +53,13 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                // START SNIPPET: e1
-                from("jetty:" + serverUri)
+                from(serverUri)
                     .choice()
                     .when().simple("in.header.one").to("mock:one")
                     .otherwise()
                     .to("mock:other");
-                // END SNIPPET: e1
             }
         };
     }
 
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamAsExchangeHeaderTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamAsExchangeHeaderTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamAsExchangeHeaderTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamAsExchangeHeaderTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamAsExchangeHeaderTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
@@ -25,9 +25,9 @@
 /**
  * Unit test to verify that we can have URI options for external system (endpoint is lenient)
  */
-public class JettyHttpGetWithParamAsExchangeHeaderTest extends CamelTestSupport {
+public class JettyHttpProducerGetWithParamAsExchangeHeaderTest extends CamelTestSupport {
 
-    private String serverUri = "http://localhost:9080/myservice";
+    private String serverUri = "jetty://http://localhost:9080/myservice";
 
     @Test
     public void testHttpGetWithParamsViaURI() throws Exception {
@@ -67,8 +67,8 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("jetty:" + serverUri).to("mock:result");
+                from(serverUri).to("mock:result");
             }
         };
     }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamTest.java (from r835302, 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/jettyproducer/JettyHttpProducerGetWithParamTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGetWithParamTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpGetWithParamTest.java&r1=835302&r2=835332&rev=835332&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/jettyproducer/JettyHttpProducerGetWithParamTest.java Thu Nov 12 10:56:34 2009
@@ -14,10 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import junit.framework.Assert;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
@@ -29,9 +28,9 @@
 /**
  * Unit test to verify that we can have URI options for external system (endpoint is lenient)
  */
-public class JettyHttpGetWithParamTest extends CamelTestSupport {
+public class JettyHttpProducerGetWithParamTest extends CamelTestSupport {
 
-    private String serverUri = "http://localhost:9080/myservice";
+    private String serverUri = "jetty://http://localhost:9080/myservice";
     private MyParamsProcessor processor = new MyParamsProcessor();
 
     @Test
@@ -61,7 +60,7 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("jetty:" + serverUri).process(processor).to("mock:result");
+                from(serverUri).process(processor).to("mock:result");
             }
         };
     }
@@ -78,4 +77,4 @@
             exchange.getOut().setHeader("two", "zwei");
         }
     }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import java.io.File;
 import java.io.InputStream;
@@ -29,7 +29,7 @@
 /**
  * @version $Revision$
  */
-public class HttpSendFileTest extends CamelTestSupport {
+public class JettyHttpProducerSendFileTest extends CamelTestSupport {
 
     @Test
     public void testSendImage() throws Exception {
@@ -38,7 +38,7 @@
         mock.message(0).body().isInstanceOf(InputStream.class);
         mock.message(0).header("Content-Type").isEqualTo("image/jpeg");
 
-        Exchange out = template.send("http://localhost:9080/myapp/myservice", new Processor() {
+        Exchange out = template.send("jetty://http://localhost:9080/myapp/myservice", new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setBody(new File("src/test/data/logo.jpeg"));
                 exchange.getIn().setHeader("Content-Type", "image/jpeg");
@@ -68,4 +68,4 @@
         };
     }
 
-}
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java Thu Nov 12 10:56:34 2009
@@ -19,7 +19,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jetty.JettyHttpOperationFailedException;
+import org.apache.camel.component.http.HttpOperationFailedException;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -35,9 +35,9 @@
         try {
             template.request(url, null);
         } catch (Exception e) {
-            JettyHttpOperationFailedException cause = assertIsInstanceOf(JettyHttpOperationFailedException.class, e.getCause());
+            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
             assertEquals(404, cause.getStatusCode());
-            assertEquals("http//0.0.0.0:9123/bar", cause.getUrl());
+            assertEquals("http//0.0.0.0:9123/bar", cause.getUri());
             assertEquals("Page not found", cause.getResponseBody());
             assertNotNull(cause.getResponseHeaders());
         }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java?rev=835332&r1=835331&r2=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java Thu Nov 12 10:56:34 2009
@@ -21,6 +21,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -29,11 +30,17 @@
  */
 public class JettyHttpProducerSlowResponseTest extends CamelTestSupport {
 
-    private String url = "jetty://http://0.0.0.0:9123/foo";
+    private String url = "jetty://http://0.0.0.0:9321/foo";
 
     @Test
     public void testSlowReply() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
         Exchange exchange = template.request(url, null);
+
+        assertMockEndpointsSatisfied();
+
         assertNotNull(exchange);
 
         String reply = exchange.getOut().getBody(String.class);
@@ -62,7 +69,7 @@
                         res.getWriter().write("Bye World");
                         res.flushBuffer();
                     }
-                });
+                }).to("mock:result");
             }
         };
     }

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java Thu Nov 12 10:56:34 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
 import java.net.URL;
 
@@ -23,24 +23,24 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Before;
 
-public class HttpsRouteSetupWithSystemPropsTest extends HttpsRouteTest {
-    
+public class JettyHttpsProducerRouteSetupWithSystemPropsTest extends JettyProducerHttpsRouteTest {
+
     @Override
     @Before
-    public void setUp() throws Exception {   
-        // ensure jsse clients can validate the self signed dummy localhost cert, 
+    public void setUp() throws Exception {
+        // ensure jsse clients can validate the self signed dummy localhost cert,
         // use the server keystore as the trust store for these tests
         URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
         setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.getPath());
-        
+
         // setup SSL using system properties
         setSystemProp("jetty.ssl.keystore", trustStoreUrl.getPath());
         setSystemProp("jetty.ssl.keypassword", pwd);
         setSystemProp("jetty.ssl.password", pwd);
 
-        super.setUp();     
+        super.setUp();
     }
-    
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -53,10 +53,9 @@
                     }
                 };
                 from("jetty:https://localhost:9080/hello").process(proc);
-                
+
                 from("jetty:https://localhost:9090/test").to("mock:b");
             }
         };
     }
-}
-
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java (from r835302, 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/jettyproducer/JettyProducerHandle404Test.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java&r1=835302&r2=835332&rev=835332&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/jettyproducer/JettyProducerHandle404Test.java Thu Nov 12 10:56:34 2009
@@ -14,79 +14,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.http.HttpOperationFailedException;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.processor.aggregate.AggregationStrategy;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
+import org.apache.camel.component.jetty.JettyHandle404Test;
 
 /**
  * Based on end user on forum how to get the 404 error code in his enrich aggregator
  *
  * @version $Revision$
  */
-public class JettyHandle404Test extends CamelTestSupport {
+public class JettyProducerHandle404Test extends JettyHandle404Test {
 
-    @Test
-    public void testSimulate404() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Page not found");
-        mock.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 404);
-
-        template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
+    public String getProducerUrl() {
+        return "jetty://http://localhost:8123/myserver?user=Camel";
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                // disable error handling
-                errorHandler(noErrorHandler());
-
-                from("direct:start").enrich("direct:tohttp", new AggregationStrategy() {
-                    public Exchange aggregate(Exchange original, Exchange resource) {
-                        // get the response code
-                        Integer code = resource.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
-                        assertEquals(404, code.intValue());
-                        return resource;
-                    }
-                }).to("mock:result");
-
-                // use this sub route as indirection to handle the HttpOperationFailedException
-                // and set the data back as data on the exchange to not cause the exception to be thrown
-                from("direct:tohttp")
-                        .doTry()
-                            .to("http://localhost:8123/myserver?user=Camel")
-                        .doCatch(HttpOperationFailedException.class)
-                            .process(new Processor() {
-                                public void process(Exchange exchange) {
-                                    // 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(Exchange.HTTP_RESPONSE_CODE, cause.getStatusCode());
-                                    exchange.getOut().setBody(cause.getResponseBody());
-                                }
-                            })
-                        .end();
-
-
-                // this is our jetty server where we simulate the 404
-                from("jetty://http://localhost:8123/myserver")
-                        .process(new Processor() {
-                            public void process(Exchange exchange) throws Exception {
-                                exchange.getOut().setBody("Page not found");
-                                exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
-                            }
-                        });
-            }
-        };
-    }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java (from r835302, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java&r1=835302&r2=835332&rev=835332&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java Thu Nov 12 10:56:34 2009
@@ -14,159 +14,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.jetty;
+package org.apache.camel.component.jetty.jettyproducer;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.SocketException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.HttpsRouteTest;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 
-public class HttpsRouteTest extends CamelTestSupport {
-    private static final String NULL_VALUE_MARKER = CamelTestSupport.class.getCanonicalName();
-    protected String expectedBody = "<hello>world!</hello>";
-    protected String pwd = "changeit";
-    protected Properties originalValues = new Properties();
-    
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();        
-        // ensure jsse clients can validate the self signed dummy localhost cert, 
-        // use the server keystore as the trust store for these tests
-        URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
-        setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());
-    }
-
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        restoreSystemProperties();
-        super.tearDown();
-    }
+public class JettyProducerHttpsRouteTest extends HttpsRouteTest {
 
-    protected void setSystemProp(String key, String value) {
-        String originalValue = System.setProperty(key, value);
-        originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER);
+    public String getHttpProducerScheme() {
+        return "jetty://https://";
     }
 
-    protected void restoreSystemProperties() {
-        for (Object key : originalValues.keySet()) {
-            Object value = (String) originalValues.get(key);  
-            if (NULL_VALUE_MARKER.equals(value)) {
-                System.getProperties().remove(key);    
-            } else {
-                System.setProperty((String)key, (String)value);
-            }
-        }
-    }
-
-    @Test
-    public void testEndpoint() throws Exception {
-        MockEndpoint mockEndpointA = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
-        mockEndpointA.expectedBodiesReceived(expectedBody);
-        MockEndpoint mockEndpointB = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
-        mockEndpointB.expectedBodiesReceived(expectedBody);
-
-        invokeHttpEndpoint();
-
-        mockEndpointA.assertIsSatisfied();
-        mockEndpointB.assertIsSatisfied();
-        List<Exchange> list = mockEndpointA.getReceivedExchanges();
-        Exchange exchange = list.get(0);
-        assertNotNull("exchange", exchange);
-
-        Message in = exchange.getIn();
-        assertNotNull("in", in);
-
-        Map<String, Object> headers = in.getHeaders();
-
-        log.info("Headers: " + headers);
-
-        assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
-    }
-    
     @Test
     public void testEndpointWithoutHttps() {
-        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);    
+        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
         try {
-            template.sendBodyAndHeader("http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+            template.sendBodyAndHeader("jetty://http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
             fail("expect exception on access to https endpoint via http");
         } catch (RuntimeCamelException expected) {
         }
         assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
     }
 
-    @Test
-    public void testHelloEndpoint() throws Exception {
-
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        InputStream is = new URL("https://localhost:9080/hello").openStream();
-        int c;
-        while ((c = is.read()) >= 0) {
-            os.write(c);
-        }
-
-        String data = new String(os.toByteArray());
-        assertEquals("<b>Hello World</b>", data);
-        
-    }
-    
-    @Test
-    public void testHelloEndpointWithoutHttps() throws Exception {
-        try {
-            new URL("http://localhost:9080/hello").openStream();
-            fail("expected SocketException on use ot http");
-        } catch (SocketException expected) {
-        }
-        
-        
-    }
-    
-    protected void invokeHttpEndpoint() throws IOException {
-        template.sendBodyAndHeader("https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
-        template.sendBodyAndHeader("https://localhost:9090/test", expectedBody, "Content-Type", "application/xml");
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() throws URISyntaxException {
-                
-                JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty");
-                componentJetty.setSslPassword(pwd);
-                componentJetty.setSslKeyPassword(pwd);
-                URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
-                componentJetty.setKeystore(keyStoreUrl.toURI().getPath());
-                
-                from("jetty:https://localhost:9080/test").to("mock:a");
-
-                Processor proc = new Processor() {
-                    public void process(Exchange exchange) throws Exception {
-                        exchange.getOut().setBody("<b>Hello World</b>");
-                    }
-                };
-                from("jetty:https://localhost:9080/hello").process(proc);
-                
-                from("jetty:https://localhost:9090/test").to("mock:b");
-            }
-        };
-    }
-}
-
+}
\ No newline at end of file



Mime
View raw message