Author: davsclaus
Date: Mon Dec 27 09:34:44 2010
New Revision: 1053029

URL: http://svn.apache.org/viewvc?rev=1053029&view=rev
Log:
CAMEL-3218: Added transferException option to http,jetty,servlet components. 
Added support for application/x-java-serialized-object content type for 
response body supported by http proucer. It will automatic deserialize the java 
object.

Added:
    
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java
Modified:
    
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/HttpComponent.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/HttpProducer.java
    camel/trunk/components/camel-jetty/src/test/resources/log4j.properties

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=1053029&r1=1053028&r2=1053029&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 Dec 27 09:34:44 2010
@@ -17,19 +17,15 @@
 package org.apache.camel.component.http;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.Enumeration;
 import java.util.Map;
-
 import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-import javax.activation.FileTypeMap;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -56,14 +52,22 @@ public class DefaultHttpBinding implemen
 
     private boolean useReaderForPayload;
     private HeaderFilterStrategy headerFilterStrategy = new 
HttpHeaderFilterStrategy();
+    private HttpEndpoint endpoint;
 
+    @Deprecated
     public DefaultHttpBinding() {
     }
 
+    @Deprecated
     public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
         this.headerFilterStrategy = headerFilterStrategy;
     }
 
+    public DefaultHttpBinding(HttpEndpoint endpoint) {
+        this.endpoint = endpoint;
+        this.headerFilterStrategy = endpoint.getHeaderFilterStrategy();
+    }
+
     public void readRequest(HttpServletRequest request, HttpMessage message) {
         
         // lets force a parse of the body and headers
@@ -91,7 +95,7 @@ public class DefaultHttpBinding implemen
             message.getExchange().setProperty(Exchange.CHARSET_NAME, 
request.getCharacterEncoding());
         }
 
-        popluateRequestParameters(request, message);        
+        populateRequestParameters(request, message);
         
         Object body = message.getBody();
         // reset the stream cache if the body is the instance of StreamCache
@@ -107,10 +111,10 @@ public class DefaultHttpBinding implemen
         headers.put(Exchange.HTTP_PATH, request.getPathInfo());
         headers.put(Exchange.CONTENT_TYPE, request.getContentType());
         
-        popluateAttachments(request, message);
+        populateAttachments(request, message);
     }
     
-    protected void popluateRequestParameters(HttpServletRequest request, 
HttpMessage message) {
+    protected void populateRequestParameters(HttpServletRequest request, 
HttpMessage message) {
         //we populate the http request parameters without checking the request 
method
         Map<String, Object> headers = message.getHeaders();
         Enumeration names = request.getParameterNames();
@@ -123,7 +127,8 @@ public class DefaultHttpBinding implemen
             }
         }
         
-        if (request.getMethod().equals("POST") && request.getContentType() != 
null && 
request.getContentType().startsWith("application/x-www-form-urlencoded")) {
+        if (request.getMethod().equals("POST") && request.getContentType() != 
null
+                && 
request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED))
 {
             String charset = request.getCharacterEncoding();
             if (charset == null) {
                 charset = "UTF-8";
@@ -147,7 +152,7 @@ public class DefaultHttpBinding implemen
         
     }
     
-    protected void popluateAttachments(HttpServletRequest request, HttpMessage 
message) {
+    protected void populateAttachments(HttpServletRequest request, HttpMessage 
message) {
         // check if there is multipart files, if so will put it into 
DataHandler
         Enumeration names = request.getAttributeNames();
         while (names.hasMoreElements()) {
@@ -189,14 +194,23 @@ public class DefaultHttpBinding implemen
     }
 
     public void doWriteExceptionResponse(Throwable exception, 
HttpServletResponse response) throws IOException {
-        response.setStatus(500); // 500 for internal server error
-        response.setContentType("text/plain");
+        // 500 for internal server error
+        response.setStatus(500);
 
-        // append the stacktrace as response
-        PrintWriter pw = response.getWriter();
-        exception.printStackTrace(pw);
-
-        pw.flush();
+        if (endpoint != null && endpoint.isTransferException()) {
+            // transfer the exception as a serialized java object
+            
response.setContentType(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
+            ObjectOutputStream oos = new 
ObjectOutputStream(response.getOutputStream());
+            oos.writeObject(exception);
+            oos.flush();
+            IOHelper.close(oos);
+        } else {
+            // write stacktrace as plain text
+            response.setContentType("text/plain");
+            PrintWriter pw = response.getWriter();
+            exception.printStackTrace(pw);
+            pw.flush();
+        }
     }
 
     public void doWriteFaultResponse(Message message, HttpServletResponse 
response, Exchange exchange) throws IOException {
@@ -331,7 +345,6 @@ public class DefaultHttpBinding implemen
                     is.close();
                 }
             }
-             
         }
     }
 

Modified: 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=1053029&r1=1053028&r2=1053029&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 (original)
+++ 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 Mon Dec 27 09:34:44 2010
@@ -208,6 +208,7 @@ public class HttpComponent extends Heade
             binding = resolveAndRemoveReferenceParameter(parameters, 
"httpBinding", HttpBinding.class);
         }
         Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters, 
"throwExceptionOnFailure", Boolean.class);
+        Boolean transferException = getAndRemoveParameter(parameters, 
"transferException", Boolean.class);
         Boolean bridgeEndpoint = getAndRemoveParameter(parameters, 
"bridgeEndpoint", Boolean.class);
         Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, 
"matchOnUriPrefix", Boolean.class);
         Boolean disableStreamCache = getAndRemoveParameter(parameters, 
"disableStreamCache", Boolean.class);
@@ -254,6 +255,10 @@ public class HttpComponent extends Heade
         if (throwExceptionOnFailure != null) {
             endpoint.setThrowExceptionOnFailure(throwExceptionOnFailure);
         }
+        // should we transfer exception as serialized object
+        if (transferException != null) {
+            endpoint.setTransferException(transferException);
+        }
         if (bridgeEndpoint != null) {
             endpoint.setBridgeEndpoint(bridgeEndpoint);
         }

Added: 
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=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
 (added)
+++ 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+/**
+ * @version $Revision$
+ */
+public final class HttpConstants {
+
+    public static final String CONTENT_TYPE_JAVA_SERIALIZED_OBJECT = 
"application/x-java-serialized-object";
+    public static final String CONTENT_TYPE_WWW_FORM_URLENCODED = 
"application/x-www-form-urlencoded";
+
+    private HttpConstants() {
+    }
+}

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=1053029&r1=1053028&r2=1053029&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 Dec 27 09:34:44 2010
@@ -58,6 +58,7 @@ public class HttpEndpoint extends Defaul
     private String proxyHost;
     private int proxyPort;
     private String authMethodPriority;
+    private boolean transferException;
 
     public HttpEndpoint() {
     }
@@ -197,7 +198,7 @@ public class HttpEndpoint extends Defaul
 
     public HttpBinding getBinding() {
         if (binding == null) {
-            binding = new DefaultHttpBinding(getHeaderFilterStrategy());
+            binding = new DefaultHttpBinding(this);
         }
         return binding;
     }
@@ -312,4 +313,12 @@ public class HttpEndpoint extends Defaul
     public void setAuthMethodPriority(String authMethodPriority) {
         this.authMethodPriority = authMethodPriority;
     }
+
+    public boolean isTransferException() {
+        return transferException;
+    }
+
+    public void setTransferException(boolean transferException) {
+        this.transferException = transferException;
+    }
 }

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=1053029&r1=1053028&r2=1053029&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
 Mon Dec 27 09:34:44 2010
@@ -19,6 +19,7 @@ package org.apache.camel.component.http;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Map;
@@ -57,11 +58,13 @@ public class HttpProducer extends Defaul
     private static final transient Log LOG = 
LogFactory.getLog(HttpProducer.class);
     private HttpClient httpClient;
     private boolean throwException;
+    private boolean transferException;
 
     public HttpProducer(HttpEndpoint endpoint) {
         super(endpoint);
         this.httpClient = endpoint.createHttpClient();
         this.throwException = endpoint.isThrowExceptionOnFailure();
+        this.transferException = endpoint.isTransferException();
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -119,7 +122,7 @@ public class HttpProducer extends Defaul
         return (HttpEndpoint) super.getEndpoint();
     }
 
-    protected void populateResponse(Exchange exchange, HttpMethod method, 
Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException 
{
+    protected void populateResponse(Exchange exchange, HttpMethod method, 
Message in, HeaderFilterStrategy strategy, int responseCode) throws 
IOException, ClassNotFoundException {
         Message answer = exchange.getOut();
 
         answer.setHeaders(in.getHeaders());
@@ -140,16 +143,23 @@ public class HttpProducer extends Defaul
         }
     }
 
-    protected HttpOperationFailedException 
populateHttpOperationFailedException(Exchange exchange, HttpMethod method, int 
responseCode) throws IOException {
-        HttpOperationFailedException exception;
+    protected Exception populateHttpOperationFailedException(Exchange 
exchange, HttpMethod method, int responseCode) throws IOException, 
ClassNotFoundException {
+        Exception answer;
+
         String uri = method.getURI().toString();
         String statusText = method.getStatusLine() != null ? 
method.getStatusLine().getReasonPhrase() : null;
         Map<String, String> headers = 
extractResponseHeaders(method.getResponseHeaders());
-        InputStream is = extractResponseBody(method, exchange);
+
+        Object responseBody = extractResponseBody(method, exchange);
+        if (transferException && responseBody != null && responseBody 
instanceof Exception) {
+            // if the response was a serialized exception then use that
+            return (Exception) responseBody;
+        }
+
         // make a defensive copy of the response body in the exception so its 
detached from the cache
         String copy = null;
-        if (is != null) {
-            copy = 
exchange.getContext().getTypeConverter().convertTo(String.class, exchange, is);
+        if (responseBody != null) {
+            copy = 
exchange.getContext().getTypeConverter().convertTo(String.class, exchange, 
responseBody);
         }
 
         if (responseCode >= 300 && responseCode < 400) {
@@ -157,17 +167,17 @@ public class HttpProducer extends Defaul
             Header locationHeader = method.getResponseHeader("location");
             if (locationHeader != null) {
                 redirectLocation = locationHeader.getValue();
-                exception = new HttpOperationFailedException(uri, 
responseCode, statusText, redirectLocation, headers, copy);
+                answer = new HttpOperationFailedException(uri, responseCode, 
statusText, redirectLocation, headers, copy);
             } else {
                 // no redirect location
-                exception = new HttpOperationFailedException(uri, 
responseCode, statusText, null, headers, copy);
+                answer = new HttpOperationFailedException(uri, responseCode, 
statusText, null, headers, copy);
             }
         } else {
             // internal server error (error code 500)
-            exception = new HttpOperationFailedException(uri, responseCode, 
statusText, null, headers, copy);
+            answer = new HttpOperationFailedException(uri, responseCode, 
statusText, null, headers, copy);
         }
 
-        return exception;
+        return answer;
     }
 
     /**
@@ -204,10 +214,10 @@ public class HttpProducer extends Defaul
      * Extracts the response from the method as a InputStream.
      *
      * @param method  the method that was executed
-     * @return  the response as a stream
+     * @return  the response either as a stream, or as a deserialized java 
object
      * @throws IOException can be thrown
      */
-    protected static InputStream extractResponseBody(HttpMethod method, 
Exchange exchange) throws IOException {
+    protected static Object extractResponseBody(HttpMethod method, Exchange 
exchange) throws IOException, ClassNotFoundException {
         InputStream is = method.getResponseBodyAsStream();
         if (is == null) {
             return null;
@@ -221,16 +231,39 @@ public class HttpProducer extends Defaul
         }
         
         // Honor the character encoding
+        String contentType = null;
         header = method.getResponseHeader("content-type");
         if (header != null) {
-            String contentType = header.getValue();
+            contentType = header.getValue();
             // find the charset and set it to the Exchange
             HttpHelper.setCharsetFromContentType(contentType, exchange);
         }
-        return doExtractResponseBody(is, exchange);
+        InputStream response = doExtractResponseBodyAsStream(is, exchange);
+        if (contentType != null && 
contentType.equals(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT)) {
+            return doDeserializeJavaObjectFromResponse(response);
+        } else {
+            return response;
+        }
+    }
+
+    private static Object doDeserializeJavaObjectFromResponse(InputStream 
response) throws ClassNotFoundException, IOException {
+        if (response == null) {
+            LOG.debug("Cannot deserialize transferred exception due no 
response body.");
+            return null;
+        }
+
+        Object answer = null;
+        ObjectInputStream ois = new ObjectInputStream(response);
+        try {
+            answer = ois.readObject();
+        } finally {
+            IOHelper.close(ois);
+        }
+
+        return answer;
     }
 
-    private static InputStream doExtractResponseBody(InputStream is, Exchange 
exchange) throws IOException {
+    private static InputStream doExtractResponseBodyAsStream(InputStream is, 
Exchange exchange) throws IOException {
         // As httpclient is using a AutoCloseInputStream, it will be closed 
when the connection is closed
         // we need to cache the stream for it.
         try {

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java?rev=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.proxy;
+
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.ProxyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpClientProxyTest extends BaseJettyTest {
+
+    @Test
+    public void testHttpClientNoProxyOk() throws Exception {
+        String out = template.requestBody("direct:cool", "World", 
String.class);
+        assertEquals("Hello World", out);
+    }
+
+    @Test
+    public void testHttpClientNoProxyException() throws Exception {
+        try {
+            template.requestBody("direct:cool", "Kaboom", String.class);
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            HttpOperationFailedException cause = 
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+            assertEquals(500, cause.getStatusCode());
+            assertNotNull(cause.getResponseBody());
+            assertTrue(cause.getResponseBody().contains("MyAppException"));
+        }
+    }
+
+    @Test
+    public void testHttpClientProxyOk() throws Exception {
+        MyCoolService proxy = new 
ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
+        String out = proxy.hello("World");
+
+        assertEquals("Hello World", out);
+    }
+
+    @Test
+    public void testHttpClientProxyException() throws Exception {
+        MyCoolService proxy = new 
ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
+        try {
+            proxy.hello("Kaboom");
+            fail("Should have thrown exception");
+        } catch (UndeclaredThrowableException e) {
+            HttpOperationFailedException cause = 
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+            assertEquals(500, cause.getStatusCode());
+            assertNotNull(cause.getResponseBody());
+            assertTrue(cause.getResponseBody().contains("MyAppException"));
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:cool")
+                    .to("http://localhost:{{port}}/myapp/myservice";);
+
+                from("jetty:http://localhost:{{port}}/myapp/myservice";)
+                    .bean(MyCoolServiceBean.class);
+            }
+        };
+    }
+}

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java?rev=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.proxy;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.ProxyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpClientProxyTransferExceptionTest extends BaseJettyTest {
+
+    @Test
+    public void testHttpClientNoProxyOk() throws Exception {
+        String out = template.requestBody("direct:cool", "World", 
String.class);
+        assertEquals("Hello World", out);
+    }
+
+    @Test
+    public void testHttpClientNoProxyException() throws Exception {
+        try {
+            template.requestBody("direct:cool", "Kaboom");
+            fail("Should have thrown an exception");
+        } catch (CamelExecutionException e) {
+            MyAppException cause = assertIsInstanceOf(MyAppException.class, 
e.getCause());
+            assertNotNull(cause);
+            assertEquals("Kaboom", cause.getName());
+        }
+    }
+
+    @Test
+    public void testHttpClientProxyOk() throws Exception {
+        MyCoolService proxy = new 
ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
+        String out = proxy.hello("World");
+
+        assertEquals("Hello World", out);
+    }
+
+    @Test
+    public void testHttpClientProxyException() throws Exception {
+        MyCoolService proxy = new 
ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
+        try {
+            proxy.hello("Kaboom");
+            fail("Should have thrown exception");
+        } catch (MyAppException e) {
+            assertEquals("Kaboom", e.getName());
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:cool")
+                    
.to("http://localhost:{{port}}/myapp/myservice?transferException=true";);
+
+                
from("jetty:http://localhost:{{port}}/myapp/myservice?transferException=true";)
+                    .bean(MyCoolServiceBean.class);
+            }
+        };
+    }
+}

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java?rev=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.proxy;
+
+/**
+ * @version $Revision$
+ */
+public class MyAppException extends Exception {
+
+    private final String name;
+
+    public MyAppException(String msg, String name) {
+        super(msg);
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java?rev=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.proxy;
+
+/**
+ * @version $Revision$
+ */
+public interface MyCoolService {
+
+    String hello(String name) throws MyAppException;
+}

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java?rev=1053029&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java
 Mon Dec 27 09:34:44 2010
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.proxy;
+
+/**
+ * @version $Revision$
+ */
+public class MyCoolServiceBean implements MyCoolService {
+
+    public String hello(String name) throws MyAppException {
+        if ("Kaboom".equals(name)) {
+            throw new MyAppException("Invalid name", "Kaboom");
+        }
+
+        return "Hello " + name;
+    }
+}

Modified: camel/trunk/components/camel-jetty/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/log4j.properties?rev=1053029&r1=1053028&r2=1053029&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/log4j.properties 
(original)
+++ camel/trunk/components/camel-jetty/src/test/resources/log4j.properties Mon 
Dec 27 09:34:44 2010
@@ -21,7 +21,7 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output 
on the console.
 #
-log4j.rootLogger=WARN, file
+log4j.rootLogger=INFO, file
 
 # uncomment the following to enable camel debugging
 #log4j.logger.org.apache.camel.component.jetty=TRACE


Reply via email to