You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/05/31 08:17:22 UTC

svn commit: r410441 - in /incubator/tuscany/sandbox/jboynes/sca: core2/src/main/java/org/apache/tuscany/core/wire/ core2/src/test/java/org/apache/tuscany/core/wire/ spi/src/main/java/org/apache/tuscany/spi/wire/

Author: jmarino
Date: Tue May 30 23:17:21 2006
New Revision: 410441

URL: http://svn.apache.org/viewvc?rev=410441&view=rev
Log:
invocation handler bug fixing and testcases

Added:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java
      - copied, changed from r410423, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationandlerTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ServiceInvocationandlerTestCase.java
Removed:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
Modified:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationHandlerTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ReferenceInvocationHandler.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ServiceInvocationHandler.java

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java?rev=410441&r1=410440&r2=410441&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java Tue May 30 23:17:21 2006
@@ -28,7 +28,7 @@
 public class OutboundInvocationChainImpl extends InvocationChainImpl implements OutboundInvocationChain {
 
     /**
-     * Creates an new source wire configuration
+     * Creates an new outbound chain
      */
     public OutboundInvocationChainImpl(Method operation) {
         super(operation);
@@ -49,7 +49,6 @@
         if (requestHandlers != null || responseHandlers != null) {
             Interceptor channelInterceptor = new RequestResponseInterceptor(requestChannel, targetRequestChannel,
                     responseChannel, targetResponseChannel);
-
             if (interceptorChainHead != null) {
                 interceptorChainTail.setNext(channelInterceptor);
             } else {

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java?rev=410441&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java (added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java Tue May 30 23:17:21 2006
@@ -0,0 +1,104 @@
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.mock.wire.MockHandler;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.util.MethodHashMap;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.ServiceInvocationHandler;
+
+/**
+ * Tests handling of exceptions thrown during an inbound wire invocation
+ *
+ * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $
+ */
+public class InboundInvocationErrorTestCase extends TestCase {
+
+    private Method checkedMethod;
+    private Method runtimeMethod;
+
+    public InboundInvocationErrorTestCase() {
+        super();
+    }
+
+    public InboundInvocationErrorTestCase(String arg0) {
+        super(arg0);
+    }
+
+    public void setUp() throws Exception {
+        checkedMethod = InboundInvocationErrorTestCase.TestBean.class.getDeclaredMethod("checkedException", (Class[]) null);
+        runtimeMethod = InboundInvocationErrorTestCase.TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null);
+        assertNotNull(checkedMethod);
+        assertNotNull(runtimeMethod);
+    }
+
+    public void testCheckedException() throws Exception {
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        chains.put(checkedMethod, createChain(checkedMethod));
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        try {
+            InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+                    new Class[]{InboundInvocationErrorTestCase.TestBean.class}, handler);
+            proxy.checkedException();
+        } catch (InboundInvocationErrorTestCase.TestException e) {
+            return;
+        }
+        fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown");
+    }
+
+    public void testRuntimeException() throws Exception {
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        chains.put(runtimeMethod, createChain(runtimeMethod));
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        try {
+            InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+                    new Class[]{InboundInvocationErrorTestCase.TestBean.class}, handler);
+            proxy.runtimeException();
+        } catch (InboundInvocationErrorTestCase.TestRuntimeException e) {
+            return;
+        }
+        fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown");
+    }
+
+    private InboundInvocationChain createChain(Method m) {
+        MockStaticInvoker invoker = new MockStaticInvoker(m, new InboundInvocationErrorTestCase.TestBeanImpl());
+        InboundInvocationChain chain = new InboundInvocationChainImpl(m);
+        chain.addInterceptor(new MockSyncInterceptor());
+        chain.addRequestHandler(new MockHandler());
+        chain.setTargetInvoker(invoker);
+        chain.addInterceptor(new InvokerInterceptor());
+        chain.build();
+        return chain;
+    }
+
+    public interface TestBean {
+
+        public void checkedException() throws InboundInvocationErrorTestCase.TestException;
+
+        public void runtimeException() throws InboundInvocationErrorTestCase.TestRuntimeException;
+
+    }
+
+    public class TestBeanImpl implements InboundInvocationErrorTestCase.TestBean {
+
+        public void checkedException() throws InboundInvocationErrorTestCase.TestException {
+            throw new InboundInvocationErrorTestCase.TestException();
+        }
+
+        public void runtimeException() throws InboundInvocationErrorTestCase.TestRuntimeException {
+            throw new InboundInvocationErrorTestCase.TestRuntimeException();
+        }
+    }
+
+    public class TestException extends Exception {
+    }
+
+    public class TestRuntimeException extends RuntimeException {
+    }
+
+}

Copied: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java (from r410423, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java?p2=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java&r1=410423&r2=410441&rev=410441&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java Tue May 30 23:17:21 2006
@@ -29,20 +29,20 @@
 import org.apache.tuscany.spi.wire.ReferenceInvocationHandler;
 
 /**
- * Tests handling of exceptions thrown during an wire
+ * Tests handling of exceptions thrown during an outbound wire invocation
  *
  * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $
  */
-public class InvocationErrorTestCase extends TestCase {
+public class OutboundInvocationErrorTestCase extends TestCase {
 
     private Method checkedMethod;
     private Method runtimeMethod;
 
-    public InvocationErrorTestCase() {
+    public OutboundInvocationErrorTestCase() {
         super();
     }
 
-    public InvocationErrorTestCase(String arg0) {
+    public OutboundInvocationErrorTestCase(String arg0) {
         super(arg0);
     }
 
@@ -54,9 +54,9 @@
     }
 
     public void testCheckedException() throws Exception {
-        Map<Method, OutboundInvocationChain> config = new MethodHashMap<OutboundInvocationChain>();
-        config.put(checkedMethod, getConfiguration(checkedMethod));
-        ReferenceInvocationHandler handler = new ReferenceInvocationHandler(config);
+        Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
+        chains.put(checkedMethod, createChain(checkedMethod));
+        ReferenceInvocationHandler handler = new ReferenceInvocationHandler(chains);
         try {
             TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                     new Class[]{TestBean.class}, handler);
@@ -68,9 +68,9 @@
     }
 
     public void testRuntimeException() throws Exception {
-        Map<Method, OutboundInvocationChain> config = new MethodHashMap<OutboundInvocationChain>();
-        config.put(runtimeMethod, getConfiguration(runtimeMethod));
-        ReferenceInvocationHandler handler = new ReferenceInvocationHandler(config);
+        Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
+        chains.put(runtimeMethod, createChain(runtimeMethod));
+        ReferenceInvocationHandler handler = new ReferenceInvocationHandler(chains);
         try {
             TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                     new Class[]{TestBean.class}, handler);
@@ -81,15 +81,15 @@
         fail(TestException.class.getName() + " should have been thrown");
     }
 
-    private OutboundInvocationChain getConfiguration(Method m) {
+    private OutboundInvocationChain createChain(Method m) {
         MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl());
-        OutboundInvocationChain invocationConfiguration = new OutboundInvocationChainImpl(m);
-        invocationConfiguration.addInterceptor(new MockSyncInterceptor());
-        invocationConfiguration.addRequestHandler(new MockHandler());
-        invocationConfiguration.setTargetInvoker(invoker);
-        invocationConfiguration.setTargetInterceptor(new InvokerInterceptor());
-        invocationConfiguration.build();
-        return invocationConfiguration;
+        OutboundInvocationChain chain = new OutboundInvocationChainImpl(m);
+        chain.addInterceptor(new MockSyncInterceptor());
+        chain.addRequestHandler(new MockHandler());
+        chain.setTargetInvoker(invoker);
+        chain.setTargetInterceptor(new InvokerInterceptor());
+        chain.build();
+        return chain;
     }
 
     public interface TestBean {

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationHandlerTestCase.java?rev=410441&r1=410440&r2=410441&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationHandlerTestCase.java Tue May 30 23:17:21 2006
@@ -10,13 +10,9 @@
 import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
 import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
 import org.apache.tuscany.core.util.MethodHashMap;
-import org.apache.tuscany.core.wire.InvokerInterceptor;
-import org.apache.tuscany.core.wire.MessageChannelImpl;
-import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
 import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.ReferenceInvocationHandler;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
 
 public class ReferenceInvocationHandlerTestCase extends TestCase {
 
@@ -46,7 +42,7 @@
         configs.put(hello, createChain(hello));
         ReferenceInvocationHandler handler = new ReferenceInvocationHandler(configs);
         try {
-            assertEquals("foo", handler.invoke(null, hello, new Object[]{}));
+            handler.invoke(null, hello, new Object[]{});
             fail("Expected " + IllegalArgumentException.class.getName());
         } catch (IllegalArgumentException e) {
             // should throw

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationandlerTestCase.java?rev=410441&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationandlerTestCase.java (added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ReferenceInvocationandlerTestCase.java Tue May 30 23:17:21 2006
@@ -0,0 +1,49 @@
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockHandler;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.util.MethodHashMap;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.ReferenceInvocationHandler;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceInvocationandlerTestCase extends MockObjectTestCase {
+
+    private Method echo;
+
+    public void testHandlersInterceptorInvoke() throws Throwable {
+        Map<Method, OutboundInvocationChain> chains = new MethodHashMap<OutboundInvocationChain>();
+        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+        OutboundInvocationChain chain = new OutboundInvocationChainImpl(echo);
+        MockSyncInterceptor interceptor = new MockSyncInterceptor();
+        chain.addInterceptor(interceptor);
+        chain.setTargetInterceptor(new InvokerInterceptor());
+        MockHandler requestHandler = new MockHandler();
+        chain.addRequestHandler(requestHandler);
+        MockHandler responseHandler = new MockHandler();
+        chain.addResponseHandler(responseHandler);
+        chain.setTargetInvoker(invoker);
+        chain.build();
+        chains.put(echo, chain);
+        ReferenceInvocationHandler handler = new ReferenceInvocationHandler(chains);
+        assertEquals("foo",handler.invoke(null,echo,new String[]{"foo"}));
+        assertEquals(1,interceptor.getCount());
+        assertEquals(1,requestHandler.getCount());
+        assertEquals(1,responseHandler.getCount());
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        echo = SimpleTarget.class.getMethod("echo", String.class);
+    }
+
+}

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ServiceInvocationandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ServiceInvocationandlerTestCase.java?rev=410441&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ServiceInvocationandlerTestCase.java (added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/ServiceInvocationandlerTestCase.java Tue May 30 23:17:21 2006
@@ -0,0 +1,95 @@
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockHandler;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.util.MethodHashMap;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.ServiceInvocationHandler;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.ReferenceInvocationHandler;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class ServiceInvocationandlerTestCase extends MockObjectTestCase {
+
+    private Method echo;
+
+    public void testHandlersInterceptorInvoke() throws Throwable {
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+        InboundInvocationChain chain = new InboundInvocationChainImpl(echo);
+        MockSyncInterceptor interceptor = new MockSyncInterceptor();
+        chain.addInterceptor(interceptor);
+        chain.addInterceptor(new InvokerInterceptor());
+        MockHandler requestHandler = new MockHandler();
+        chain.addRequestHandler(requestHandler);
+        MockHandler responseHandler = new MockHandler();
+        chain.addResponseHandler(responseHandler);
+        chain.setTargetInvoker(invoker);
+        chain.build();
+        chains.put(echo, chain);
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
+        assertEquals(1, interceptor.getCount());
+        assertEquals(1, requestHandler.getCount());
+        assertEquals(1, responseHandler.getCount());
+    }
+
+    public void testInterceptorInvoke() throws Throwable {
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+        InboundInvocationChain chain = new InboundInvocationChainImpl(echo);
+        MockSyncInterceptor interceptor = new MockSyncInterceptor();
+        chain.addInterceptor(interceptor);
+        chain.addInterceptor(new InvokerInterceptor());
+        chain.setTargetInvoker(invoker);
+        chain.build();
+        chains.put(echo, chain);
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
+        assertEquals(1, interceptor.getCount());
+    }
+
+
+    public void testDirectErrorInvoke() throws Throwable {
+        InboundInvocationChain source = new InboundInvocationChainImpl(echo);
+        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+        source.setTargetInvoker(invoker);
+
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        chains.put(echo, source);
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        try {
+            assertEquals("foo", handler.invoke(null, echo, new Object[]{}));
+            fail("Expected " + IllegalArgumentException.class.getName());
+        } catch (IllegalArgumentException e) {
+            // should throw
+        }
+    }
+
+    public void testDirectInvoke() throws Throwable {
+        InboundInvocationChain source = new InboundInvocationChainImpl(echo);
+        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+        source.setTargetInvoker(invoker);
+
+        Map<Method, InboundInvocationChain> chains = new MethodHashMap<InboundInvocationChain>();
+        chains.put(echo, source);
+        ServiceInvocationHandler handler = new ServiceInvocationHandler(chains);
+        assertEquals("foo", handler.invoke(null, echo, new Object[]{"foo"}));
+    }
+
+
+    public void setUp() throws Exception {
+        super.setUp();
+        echo = SimpleTarget.class.getMethod("echo", String.class);
+    }
+
+}

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ReferenceInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ReferenceInvocationHandler.java?rev=410441&r1=410440&r2=410441&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ReferenceInvocationHandler.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ReferenceInvocationHandler.java Tue May 30 23:17:21 2006
@@ -25,14 +25,15 @@
 import org.apache.tuscany.spi.context.TargetException;
 
 /**
- * Receives a request from a proxy and dispatches it to a target invoker or source interceptor stack
+ * Receives a request from a proxy and performs an invocation on an {@link OutboundWire} via an {@link
+ * OutboundInvocationChain}
  *
  * @version $Rev: 406016 $ $Date: 2006-05-12 22:45:22 -0700 (Fri, 12 May 2006) $
  */
 public class ReferenceInvocationHandler implements WireInvocationHandler, InvocationHandler {
 
     /*
-     * an association of an operation to chain holder. The holder contains the master wire chain
+     * an association of an operation to chain holder. The holder contains an invocation chain
      * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
      * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
      * to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
@@ -47,9 +48,6 @@
         }
     }
 
-    /**
-     * Dispatches a client request made on a proxy
-     */
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
         Interceptor headInterceptor = null;
         ChainHolder holder = chains.get(method);
@@ -83,7 +81,8 @@
             assert chain != null;
             invoker = chain.getTargetInvoker();
         }
-        if (headInterceptor == null) {
+        if (chain.getTargetRequestChannel() == null && chain.getTargetResponseChannel() == null
+                && headInterceptor == null) {
             try {
                 // short-circuit the dispatch and invoke the target directly
                 if (chain.getTargetInvoker() == null) {
@@ -99,12 +98,29 @@
             msg.setTargetInvoker(invoker);
             msg.setBody(args);
             // dispatch the wire down the chain and get the response
-            Message resp = headInterceptor.invoke(msg);
-            Object body = resp.getBody();
-            if (body instanceof Throwable) {
-                throw (Throwable) body;
+            if (chain.getTargetRequestChannel() != null) {
+                chain.getTargetRequestChannel().send(msg);
+                Object body = msg.getRelatedCallbackMessage().getBody();
+                if (body instanceof Throwable) {
+                    throw (Throwable) body;
+                }
+                return body;
+
+            } else if (headInterceptor == null) {
+                throw new AssertionError("No target interceptor configured [" + method.getName() + "]");
+
+            } else {
+                Message resp = headInterceptor.invoke(msg);
+                if (chain.getTargetResponseChannel() != null) {
+                    chain.getTargetResponseChannel().send(resp);
+                    resp = resp.getRelatedCallbackMessage();
+                }
+                Object body = resp.getBody();
+                if (body instanceof Throwable) {
+                    throw (Throwable) body;
+                }
+                return body;
             }
-            return body;
         }
     }
 

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ServiceInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ServiceInvocationHandler.java?rev=410441&r1=410440&r2=410441&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ServiceInvocationHandler.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/ServiceInvocationHandler.java Tue May 30 23:17:21 2006
@@ -1,22 +1,23 @@
 package org.apache.tuscany.spi.wire;
 
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.InvocationHandler;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.tuscany.spi.context.TargetException;
 
 /**
- * Receives a request from a proxy and dispatches it to a target invoker or source interceptor stack
+ * Receives a request from a proxy and performs an invocation on an {@link InboundWire} via an {@link
+ * InboundInvocationChain}
  *
  * @version $Rev: 406016 $ $Date: 2006-05-12 22:45:22 -0700 (Fri, 12 May 2006) $
  */
 public class ServiceInvocationHandler implements WireInvocationHandler, InvocationHandler {
 
     /*
-     * an association of an operation to chain holder. The holder contains the master wire chain
+     * an association of an operation to chain holder. The holder contains the invocation chain
      * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
      * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
      * to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
@@ -35,7 +36,6 @@
      * Dispatches a client request made on a proxy
      */
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        Interceptor headInterceptor = null;
         ChainHolder holder = chains.get(method);
         if (holder == null) {
             TargetException e = new TargetException("Operation not configured");
@@ -43,12 +43,7 @@
             throw e;
         }
         InboundInvocationChain chain = holder.chain;
-        if (chain != null) {
-            headInterceptor = chain.getHeadInterceptor();
-        }
-
         TargetInvoker invoker;
-
         if (holder.cachedInvoker == null) {
             assert chain != null;
             if (chain.getTargetInvoker() == null) {
@@ -67,8 +62,10 @@
             assert chain != null;
             invoker = chain.getTargetInvoker();
         }
-        if (chain.getTargetRequestChannel() == null && chain.getTargetResponseChannel() == null
-                && headInterceptor == null) {
+        MessageChannel requestChannel = chain.getRequestChannel();
+        MessageChannel responseChannel = chain.getResponseChannel();
+        Interceptor headInterceptor = chain.getHeadInterceptor();
+        if (requestChannel == null && headInterceptor == null && responseChannel == null) {
             try {
                 // short-circuit the dispatch and invoke the target directly
                 if (chain.getTargetInvoker() == null) {
@@ -83,31 +80,34 @@
             Message msg = new MessageImpl();
             msg.setTargetInvoker(invoker);
             msg.setBody(args);
-            // dispatch the wire down the chain and get the response
-            if (chain.getTargetRequestChannel() != null) {
-                chain.getTargetRequestChannel().send(msg);
-                return msg.getRelatedCallbackMessage();
-
-            } else if (headInterceptor == null) {
-                throw new AssertionError("No target interceptor configured [" + method.getName() + "]");
-
+            Message resp;
+            if (requestChannel != null) {
+                requestChannel.send(msg);
+                resp = msg.getRelatedCallbackMessage();
+                if (responseChannel != null) {
+                    responseChannel.send(resp);
+                }
             } else {
-                Message resp = headInterceptor.invoke(msg);
-                if (chain.getTargetResponseChannel() != null) {
-                    chain.getTargetResponseChannel().send(resp);
-                    resp = resp.getRelatedCallbackMessage();
+                if (headInterceptor == null){
+                    throw new TargetException("Expected interceptor on target chain");
                 }
-                Object body = resp.getBody();
-                if (body instanceof Throwable) {
-                    throw (Throwable) body;
+                // dispatch the wire down the chain and get the response
+                resp = headInterceptor.invoke(msg);
+                if (responseChannel != null) {
+                    responseChannel.send(resp);
                 }
-                return body;
             }
+            Object body = resp.getBody();
+            if (body instanceof Throwable) {
+                throw (Throwable) body;
+            }
+            return body;
         }
     }
 
+
     public Object invoke(Method method, Object[] args) throws Throwable {
-        return invoke(null,method,args);
+        return invoke(null, method, args);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org