You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2012/08/15 20:23:07 UTC

svn commit: r1373548 - in /tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core: assembly/impl/ context/impl/ invocation/impl/

Author: antelder
Date: Wed Aug 15 18:23:04 2012
New Revision: 1373548

URL: http://svn.apache.org/viewvc?rev=1373548&view=rev
Log:
Add implementation for DOMInvoker

Added:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java
Modified:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java?rev=1373548&r1=1373547&r2=1373548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java Wed Aug 15 18:23:04 2012
@@ -71,7 +71,6 @@ import org.apache.tuscany.sca.invocation
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.invocation.Phase;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
 import org.apache.tuscany.sca.provider.BindingProviderFactory;
 import org.apache.tuscany.sca.provider.EndpointReferenceProvider;
 import org.apache.tuscany.sca.provider.ImplementationAsyncProvider;
@@ -80,9 +79,9 @@ import org.apache.tuscany.sca.provider.P
 import org.apache.tuscany.sca.provider.PolicyProviderFactory;
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.DomainRegistry;
 import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
 import org.apache.tuscany.sca.runtime.EndpointReferenceBinder;
-import org.apache.tuscany.sca.runtime.DomainRegistry;
 import org.apache.tuscany.sca.runtime.EndpointSerializer;
 import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -836,5 +835,9 @@ public class RuntimeEndpointReferenceImp
             builder.build(component, reference, binding, builderContext, true);
         }
     }
-
+    
+    public void setreferenceInterfaceContract(InterfaceContract ic) {
+        this.referenceInterfaceContract = ic;
+    }
+    
 }

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java?rev=1373548&r1=1373547&r2=1373548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java Wed Aug 15 18:23:04 2012
@@ -52,15 +52,21 @@ import org.apache.tuscany.sca.core.conte
 import org.apache.tuscany.sca.core.factory.ObjectCreationException;
 import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.impl.AsyncJDKInvocationHandler;
+import org.apache.tuscany.sca.core.invocation.impl.DOMInvokerImpl;
 import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.DOMInvoker;
 import org.apache.tuscany.sca.runtime.Invocable;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
 import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
 import org.oasisopen.sca.ServiceRuntimeException;
+import org.w3c.dom.Node;
 
 /**
  * Default implementation of a ServiceReference.
@@ -93,6 +99,8 @@ public class ServiceReferenceImpl<B> imp
     protected XMLOutputFactory xmlOutputFactory;
     protected BuilderExtensionPoint builders;
 
+    private MessageFactory messageFactory;
+
     /*
      * Public constructor for Externalizable serialization/deserialization
      */
@@ -127,6 +135,8 @@ public class ServiceReferenceImpl<B> imp
         this.staxProcessor = staxProcessors.getProcessor(EndpointReference.class);
         this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class);
         this.proxyFactory = ExtensibleProxyFactory.getInstance(registry);
+        FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+        this.messageFactory = modelFactories.getFactory(MessageFactory.class);
     }
 
     public RuntimeEndpointReference getEndpointReference() {
@@ -426,5 +436,22 @@ public class ServiceReferenceImpl<B> imp
     public void setBindingURI(String uri) {
         ((RuntimeEndpointReferenceImpl)endpointReference).setBindingURI(uri);
     }
-    
+
+    public DOMInvoker getDOMInvoker() {
+        
+        RuntimeEndpointReference epr = getEndpointReference();
+        InterfaceContract ic;
+        try {
+           ic = (InterfaceContract)epr.getGeneratedWSDLContract(epr.getBindingInterfaceContract()).clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException(e);
+        }
+        ic.getInterface().resetDataBinding(Node.class.getName());
+        
+        ((RuntimeEndpointReferenceImpl)epr).setreferenceInterfaceContract(ic);
+        epr.rebuild();
+        
+      AsyncJDKInvocationHandler handler = new AsyncJDKInvocationHandler(registry, messageFactory, this);
+      return new DOMInvokerImpl(handler);
+    }
 }

Added: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java?rev=1373548&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java Wed Aug 15 18:23:04 2012
@@ -0,0 +1,24 @@
+package org.apache.tuscany.sca.core.invocation.impl;
+
+import org.apache.tuscany.sca.runtime.DOMInvoker;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.w3c.dom.Node;
+
+public class DOMInvokerImpl implements DOMInvoker {
+
+    AsyncJDKInvocationHandler handler;
+    
+    public DOMInvokerImpl(AsyncJDKInvocationHandler handler) {
+        this.handler = handler;
+    }
+
+    @Override
+    public Node invoke(String opName, Node arg) {
+        try {
+            return (Node)handler.invoke(opName, new Object[]{arg}, handler.source, null);
+        } catch (Throwable e) {
+            throw new ServiceRuntimeException(e);
+        }
+    }
+
+}

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java?rev=1373548&r1=1373547&r2=1373548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java Wed Aug 15 18:23:04 2012
@@ -263,6 +263,28 @@ public class JDKInvocationHandler implem
         return found;
     }
 
+    protected synchronized InvocationChain getInvocationChain(String opName, Invocable source) {
+        if (source instanceof RuntimeEndpoint) {
+            // [rfeng] Start with the binding invocation chain
+            return source.getBindingInvocationChain();
+        }
+
+        InvocationChain found = null;
+        for (InvocationChain chain : source.getInvocationChains()) {
+            Operation operation = chain.getSourceOperation();
+            if (operation.isDynamic()) {
+                operation.setName(opName);
+                found = chain;
+                break;
+            } else if (operation.getName().equals(opName)) {
+                found = chain;
+                break;
+            }
+        }
+
+        return found;
+    }
+
     protected void setEndpoint(Endpoint endpoint) {
         this.target = endpoint;
     }
@@ -432,5 +454,83 @@ public class JDKInvocationHandler implem
     	}
     	return false;        
     }
+    
+    protected Object invoke(String opName, Object args, Invocable source, String msgID) throws Throwable {
+        
+        if (source instanceof RuntimeEndpointReference) {
+            RuntimeEndpointReference epr = (RuntimeEndpointReference)source;
+            if (epr.isOutOfDate()) {
+                epr.rebuild();
+                chains.clear();
+            }
+        }
+        
+        InvocationChain chain = getInvocationChain(opName, source);
+        
+        if (chain == null) {
+            throw new IllegalArgumentException("No matching operation is found: " + opName);
+        }        
+
+        Message msg = messageFactory.createMessage();
+        if (source instanceof RuntimeEndpointReference) {
+            msg.setFrom((RuntimeEndpointReference)source);
+        }
+        if (target != null) {
+            msg.setTo(target);
+        } else {
+            if (source instanceof RuntimeEndpointReference) {
+                msg.setTo(((RuntimeEndpointReference)source).getTargetEndpoint());
+            }
+        }
+        Invoker headInvoker = chain.getHeadInvoker();
+        Operation operation = null;
+        if (source instanceof RuntimeEndpoint) {
+            // [rfeng] We cannot use the targetOperation from the binding
+            // invocation chain.
+            // For each method, we need to find the matching operation so that
+            // we can set the operation on to the message
+            for (InvocationChain c : source.getInvocationChains()) {
+                Operation op = c.getTargetOperation();
+                if (opName.equals(op.getName())) {
+                    operation = op;
+                    break;
+                }
+            }
+        } else {
+            operation = chain.getTargetOperation();
+        }
+        msg.setOperation(operation);
+        msg.setBody(args);
+
+        Message msgContext = ThreadMessageContext.getMessageContext();
+
+        // Deal with header information that needs to be copied from the message
+        // context to the new message...
+        transferMessageHeaders(msg, msgContext);
+
+        ThreadMessageContext.setMessageContext(msg);
+
+        // If there is a supplied message ID, place its value into the Message
+        // Header under "MESSAGE_ID"
+        if (msgID != null) {
+            msg.getHeaders().put("MESSAGE_ID", msgID);
+        } // end if
+
+        try {
+            // dispatch the source down the chain and get the response
+            Message resp = headInvoker.invoke(msg);
+            Object body = resp.getBody();
+            if (resp.isFault()) {
+                throw (Throwable)body;
+            }
+            return body;
+        } finally {
+            ThreadMessageContext.setMessageContext(msgContext);
+        }
+    }    
+    
+    public Invocable getSource() {
+        return source;
+    }
         
 }