Author: ningjiang
Date: Mon Dec 27 08:57:05 2010
New Revision: 1053024
URL: http://svn.apache.org/viewvc?rev=1053024&view=rev
Log:
CAMEL-3353 Fix the issue of CxfRsInvoker silently swallows exceptions
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsInvoker.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsInvoker.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsInvoker.java?rev=1053024&r1=1053023&r2=1053024&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsInvoker.java
(original)
+++
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsInvoker.java
Mon Dec 27 08:57:05 2010
@@ -144,12 +144,24 @@ public class CxfRsInvoker extends JAXRSI
Throwable exception = camelExchange.getException();
Object result = null;
if (exception instanceof RuntimeCamelException) {
- exception = exception.getCause();
+ // Unwrap the RuntimeCamelException
+ if (exception.getCause() != null) {
+ exception = exception.getCause();
+ }
}
if (exception instanceof WebApplicationException) {
result = ((WebApplicationException)exception).getResponse();
+ if (result != null) {
+ return result;
+ } else {
+ throw (WebApplicationException)exception;
+ }
+ } else {
+ // Send the exception message back
+ WebApplicationException webApplicationException = new
WebApplicationException(exception,
Response.serverError().entity(exception.toString()).build());
+ throw webApplicationException;
}
- return result;
+
}
return
endpoint.getBinding().populateCxfRsResponseFromExchange(camelExchange,
cxfExchange);
}
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java?rev=1053024&r1=1053023&r2=1053024&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
Mon Dec 27 08:57:05 2010
@@ -17,6 +17,7 @@
package org.apache.camel.component.cxf.jaxrs;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -26,6 +27,7 @@ import javax.ws.rs.core.Response;
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.NoErrorHandlerBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.CxfConstants;
@@ -69,8 +71,12 @@ public class CxfRsConsumerTest extends C
// We just put the response Object into the
out message body
exchange.getOut().setBody(customer);
} else {
- Response r =
Response.status(404).entity("Can't found the customer with uri " +
path).build();
- throw new WebApplicationException(r);
+ if
("/customerservice/customers/456".equals(path)) {
+ Response r =
Response.status(404).entity("Can't found the customer with uri " +
path).build();
+ throw new WebApplicationException(r);
+ } else {
+ throw new RuntimeCamelException("Can't
found the customer with uri " + path);
+ }
}
}
if ("updateCustomer".equals(operationName)) {
@@ -110,6 +116,13 @@ public class CxfRsConsumerTest extends C
} catch (FileNotFoundException exception) {
// do nothing here
}
+ url = new
URL("http://localhost:9000/rest/customerservice/customers/256");
+ try {
+ url.openStream();
+ fail("Expect to get exception here");
+ } catch (IOException exception) {
+ // expect the Internal error exception
+ }
}