diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-25 15:52:32 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-25 15:52:32 +0000 |
commit | 22749e7c989f20f56cb9efef762d801a05b9a1d3 (patch) | |
tree | ad0140eeef1d8517b9c90c6203e834ae889b4ab4 /branches | |
parent | 9da64f4dfbb8b71be6f8d943a05570f532e9a3a1 (diff) |
Merge the fix for TUSCANY-2406 from trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@671590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches')
7 files changed, 105 insertions, 25 deletions
diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java b/branches/sca-java-1.3/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java index 479ee7c8b2..4d5278b49c 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java @@ -97,7 +97,17 @@ public class RMIService implements ComponentLifecycle { 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); diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloException.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloException.java new file mode 100644 index 0000000000..cbc860ecc6 --- /dev/null +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloException.java @@ -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); + } + +} diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java index eee4259df8..0a1f4283db 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java @@ -33,7 +33,10 @@ public class HelloWorldImpl implements HelloWorldService { 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; } } diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java index 001c520c0f..5b20d17c83 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java @@ -43,7 +43,7 @@ public class HelloWorldRmiImpl implements HelloWorldRmiService { 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"; } diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java index 6c2ae95e55..461c176e1e 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java @@ -26,6 +26,6 @@ package helloworld; public interface HelloWorldRmiService { String sayRmiHello(String name); - String sayRmiHi(String name, String greeter); + String sayRmiHi(String name, String greeter) throws HelloException; } diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java index 13a16c523f..3b705d2c97 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java @@ -26,6 +26,6 @@ package helloworld; public interface HelloWorldService { String sayHello(String name); - String sayHi(String name, String greeter); + String sayHi(String name, String greeter) throws HelloException; } diff --git a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java index afc3ef98cf..c8a13573d1 100644 --- a/branches/sca-java-1.3/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java +++ b/branches/sca-java-1.3/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java @@ -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 @@ import org.junit.Test; 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(); |