Author: rfeng
Date: Tue Jun 24 09:31:03 2008
New Revision: 671234

URL: http://svn.apache.org/viewvc?rev=671234&view=rev
Log:
Fix for TUSCANY-2046

Added:
    
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
   (with props)
Modified:
    
tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java
    
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java
    
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java
    
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java
    
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java
    
tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java

Modified: 
tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java
 Tue Jun 24 09:31:03 2008
@@ -97,7 +97,17 @@
         enhancer.setSuperclass(UnicastRemoteObject.class);
         enhancer.setCallback(new MethodInterceptor() {
             public Object intercept(Object arg0, Method method, Object[] args, 
MethodProxy arg3) throws Throwable {
-                return invokeTarget(JavaInterfaceUtil.findOperation(method, 
serviceInterface.getOperations()), args);
+                try {
+                    return 
invokeTarget(JavaInterfaceUtil.findOperation(method, 
serviceInterface.getOperations()), args);
+                } catch (InvocationTargetException e) {
+                    Throwable cause = e.getCause();
+                    for (Class<?> declaredType : method.getExceptionTypes()) {
+                        if (declaredType.isInstance(cause)) {
+                            throw e;
+                        }
+                    }
+                    throw cause;
+                }
             }
         });
         Class targetJavaInterface = getTargetJavaClass(serviceInterface);

Added: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java?rev=671234&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
 (added)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
 Tue Jun 24 09:31:03 2008
@@ -0,0 +1,60 @@
+/*
+ * 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 helloworld;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HelloException extends Exception {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 2570611055132507470L;
+
+    /**
+     * 
+     */
+    public HelloException() {
+    }
+
+    /**
+     * @param message
+     */
+    public HelloException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param cause
+     */
+    public HelloException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public HelloException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Propchange: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java
 Tue Jun 24 09:31:03 2008
@@ -33,7 +33,10 @@
         return "Hello from the RMI Service to - " + name;
     }
     
-    public String sayHi(String name, String greeter) {
+    public String sayHi(String name, String greeter) throws HelloException {
+        if (name == null || greeter == null) {
+            throw new HelloException("Invalid name or greeter: name=" + name + 
" greeter=" + greeter);
+        }
         return "Hi from " + greeter + " in RMI Service to - " + name;
     }
 }

Modified: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java
 Tue Jun 24 09:31:03 2008
@@ -43,7 +43,7 @@
         return extService.sayHello(name) + " thro the RMI Reference";
     }
     
-    public String sayRmiHi(String name, String greeter) {
+    public String sayRmiHi(String name, String greeter) throws HelloException {
         return extService.sayHi(name, greeter) + " thro the RMI Reference";
     }
 

Modified: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java
 Tue Jun 24 09:31:03 2008
@@ -26,6 +26,6 @@
 public interface HelloWorldRmiService {
 
     String sayRmiHello(String name);
-    String sayRmiHi(String name, String greeter);
+    String sayRmiHi(String name, String greeter) throws HelloException;
 
 }

Modified: 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java
 Tue Jun 24 09:31:03 2008
@@ -26,6 +26,6 @@
 public interface HelloWorldService {
 
     String sayHello(String name);
-    String sayHi(String name, String greeter);
+    String sayHi(String name, String greeter) throws HelloException;
 
 }

Modified: 
tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java?rev=671234&r1=671233&r2=671234&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
 (original)
+++ 
tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
 Tue Jun 24 09:31:03 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.sca.binding.rmi;
 
+import helloworld.HelloException;
 import helloworld.HelloWorldRmiService;
 import junit.framework.Assert;
 
@@ -34,32 +35,38 @@
 public class BindingTestCase {
     private static HelloWorldRmiService helloWorldRmiService;
     private static SCADomain domain;
- 
+
     @Test
     public void testRmiService() {
-        System.out.println(helloWorldRmiService.sayRmiHello("Tuscany World!"));
-        Assert.assertEquals("Hello from the RMI Service to - Tuscany World! 
thro the RMI Reference",
-                helloWorldRmiService.sayRmiHello("Tuscany World!"));
-        
-        System.out.println(helloWorldRmiService.sayRmiHi("Tuscany World!", 
"Apache World"));
-        
-        Assert.assertEquals("Hi from Apache World in RMI Service to - Tuscany 
World! thro the RMI Reference",
-                            helloWorldRmiService.sayRmiHi("Tuscany World!", 
"Apache World"));
-    }
+        String msg = helloWorldRmiService.sayRmiHello("Tuscany World!");
+        System.out.println(msg);
+        Assert.assertEquals("Hello from the RMI Service to - Tuscany World! 
thro the RMI Reference", msg);
+
+        try {
+            msg = helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache 
World");
+            System.out.println(msg);
+            Assert.assertEquals("Hi from Apache World in RMI Service to - 
Tuscany World! thro the RMI Reference", msg);
+        } catch (HelloException e) {
+            Assert.fail(e.getMessage());
+        }
+        try {
+            msg = helloWorldRmiService.sayRmiHi(null, "Apache World");
+            Assert.fail("HelloException should have been thrown");
+        } catch (HelloException e) {
 
+        }
+    }
 
-    
     @BeforeClass
     public static void init() throws Exception {
-try {
-        domain = SCADomain.newInstance("RMIBindingTest.composite");
-        helloWorldRmiService = 
-            domain.getService(HelloWorldRmiService.class, 
"HelloWorldRmiServiceComponent");
-} catch (Exception e) {
-    e.printStackTrace();
-}
-  }
-    
+        try {
+            domain = SCADomain.newInstance("RMIBindingTest.composite");
+            helloWorldRmiService = 
domain.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     @AfterClass
     public static void destroy() throws Exception {
         domain.close();


Reply via email to