Author: davsclaus
Date: Mon Jun 11 07:42:12 2012
New Revision: 1348733

URL: http://svn.apache.org/viewvc?rev=1348733&view=rev
Log:
CAMEL-5122: rmi consumer now rethrows exception tdefined from the method 
signature. And unmatched exception is rethrown as javax.rmi.RemoteException.

Added:
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/DamnException.java
      - copied unchanged from r1348732, 
camel/trunk/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/DamnException.java
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiDamnExceptionTest.java
      - copied unchanged from r1348732, 
camel/trunk/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiDamnExceptionTest.java
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiIllegalArgumentExceptionTest.java
      - copied unchanged from r1348732, 
camel/trunk/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiIllegalArgumentExceptionTest.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    
camel/branches/camel-2.9.x/components/camel-rmi/src/main/java/org/apache/camel/component/rmi/RmiConsumer.java
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/EchoService.java
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/IEcho.java
    
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiConcurrencyTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1348732

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
camel/branches/camel-2.9.x/components/camel-rmi/src/main/java/org/apache/camel/component/rmi/RmiConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-rmi/src/main/java/org/apache/camel/component/rmi/RmiConsumer.java?rev=1348733&r1=1348732&r2=1348733&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-rmi/src/main/java/org/apache/camel/component/rmi/RmiConsumer.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-rmi/src/main/java/org/apache/camel/component/rmi/RmiConsumer.java
 Mon Jun 11 07:42:12 2012
@@ -17,10 +17,10 @@
 package org.apache.camel.component.rmi;
 
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.rmi.Remote;
+import java.rmi.RemoteException;
 import java.rmi.registry.Registry;
 import java.rmi.server.UnicastRemoteObject;
 
@@ -89,10 +89,31 @@ public class RmiConsumer extends Default
         BeanInvocation invocation = new BeanInvocation(method, args);
         Exchange exchange = getEndpoint().createExchange();
         exchange.getIn().setBody(invocation);
-        getProcessor().process(exchange);
+        try {
+            log.debug("Invoking {} with args {}", method, args);
+            getProcessor().process(exchange);
+        } catch (Exception e) {
+            exchange.setException(e);
+        }
+
+        // is there a matching exception from the signature, then throw that
+        // or fallback and ensure the exception is thrown as a RemoteException
         Throwable fault = exchange.getException();
         if (fault != null) {
-            throw new InvocationTargetException(fault);
+            Object match = null;
+            for (Class<?> type : method.getExceptionTypes()) {
+                Object found = exchange.getException(type);
+                if (found != null) {
+                    match = found;
+                    break;
+                }
+            }
+            if (match != null && match instanceof Throwable) {
+                // we have a match
+                throw (Throwable) match;
+            } else {
+                throw new RemoteException("Error invoking " + method, fault);
+            }
         }
         return exchange.getOut().getBody();
     }

Modified: 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/EchoService.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/EchoService.java?rev=1348733&r1=1348732&r2=1348733&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/EchoService.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/EchoService.java
 Mon Jun 11 07:42:12 2012
@@ -26,4 +26,12 @@ public class EchoService implements IEch
     public String echo(String s) throws RemoteException {
         return "Echo " + s;
     }
+
+    public String damn(String s) throws DamnException, RemoteException {
+        throw new DamnException("Damn this did not work");
+    }
+
+    public String foo(String s) throws RemoteException {
+        throw new IllegalArgumentException("Illegal");
+    }
 }

Modified: 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/IEcho.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/IEcho.java?rev=1348733&r1=1348732&r2=1348733&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/IEcho.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/IEcho.java
 Mon Jun 11 07:42:12 2012
@@ -23,4 +23,8 @@ public interface IEcho extends Remote {
 
     String echo(String s) throws RemoteException;
 
+    String damn(String s) throws RemoteException, DamnException;
+
+    String foo(String s) throws RemoteException;
+
 }
\ No newline at end of file

Modified: 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiConcurrencyTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiConcurrencyTest.java?rev=1348733&r1=1348732&r2=1348733&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiConcurrencyTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiConcurrencyTest.java
 Mon Jun 11 07:42:12 2012
@@ -100,7 +100,7 @@ public class RmiConcurrencyTest extends 
                 from(echo).to("bean:echo");
 
                 // and our route where we call the server
-                
from("direct:echo").to("rmi://localhost:37543/echo").to("mock:result");
+                
from("direct:echo").to("rmi://localhost:37543/echo?method=echo").to("mock:result");
             }
         };
     }


Reply via email to