summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-08-15 18:23:04 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-08-15 18:23:04 +0000
commit8842dab9f815f98c1a59af5943340c6967b8801f (patch)
tree461a62021d8471859047a064eb267742350b669f
parent14cb4931bd021046d95cd70455473c3b4ef5f470 (diff)
Add implementation for DOMInvoker
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1373548 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java9
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java29
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java24
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java100
4 files changed, 158 insertions, 4 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
index cfc997b261..caf4fd5d86 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
@@ -71,7 +71,6 @@ import org.apache.tuscany.sca.invocation.InvokerAsyncResponse;
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.PolicyProvider;
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 RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen
builder.build(component, reference, binding, builderContext, true);
}
}
-
+
+ public void setreferenceInterfaceContract(InterfaceContract ic) {
+ this.referenceInterfaceContract = ic;
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
index 6fa53dcea2..de33a5b140 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
@@ -52,15 +52,21 @@ import org.apache.tuscany.sca.core.context.ServiceReferenceExt;
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> implements ServiceReferenceExt<B> {
protected XMLOutputFactory xmlOutputFactory;
protected BuilderExtensionPoint builders;
+ private MessageFactory messageFactory;
+
/*
* Public constructor for Externalizable serialization/deserialization
*/
@@ -127,6 +135,8 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> {
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> implements ServiceReferenceExt<B> {
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);
+ }
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java
new file mode 100644
index 0000000000..1bda350a7a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/DOMInvokerImpl.java
@@ -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);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
index 827008dc73..a48e6e2c28 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
@@ -263,6 +263,28 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable {
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 implements InvocationHandler, Serializable {
}
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;
+ }
}