From 7b5cdae8f98a1980084eed2222516c5d4580ec27 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 24 Jun 2008 16:31:03 +0000 Subject: Fix for TUSCANY-2046 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@671234 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sca/binding/rmi/RMIService.java | 12 ++++- .../src/test/java/helloworld/HelloException.java | 60 ++++++++++++++++++++++ .../src/test/java/helloworld/HelloWorldImpl.java | 5 +- .../test/java/helloworld/HelloWorldRmiImpl.java | 2 +- .../test/java/helloworld/HelloWorldRmiService.java | 2 +- .../test/java/helloworld/HelloWorldService.java | 2 +- .../tuscany/sca/binding/rmi/BindingTestCase.java | 47 +++++++++-------- 7 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java (limited to 'java/sca/modules') diff --git a/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java b/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java index 479ee7c8b2..4d5278b49c 100644 --- a/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java b/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloException.java new file mode 100644 index 0000000000..cbc860ecc6 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java b/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java index eee4259df8..0a1f4283db 100644 --- a/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java b/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java index 001c520c0f..5b20d17c83 100644 --- a/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java b/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java index 6c2ae95e55..461c176e1e 100644 --- a/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java b/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java index 13a16c523f..3b705d2c97 100644 --- a/java/sca/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java +++ b/java/sca/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/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java b/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java index afc3ef98cf..c8a13573d1 100644 --- a/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java +++ b/java/sca/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(); -- cgit v1.2.3