summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
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 /sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
parent14cb4931bd021046d95cd70455473c3b4ef5f470 (diff)
Add implementation for DOMInvoker
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1373548 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java100
1 files changed, 100 insertions, 0 deletions
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;
+ }
}