diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-13 11:16:51 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-13 11:16:51 +0000 |
commit | 4174b0fa7cbd6cffa801897b3a9f48ee6280c571 (patch) | |
tree | 2737edb41292e8a6eb389a5149c8bb6e6865bd6c /sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany | |
parent | 957ed8ebbe1080c22428cc1e97d40f8b2b96ca9c (diff) |
TUSCANY-3801, update the databinding transformer so that it can be used with native async
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1045067 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany')
-rw-r--r-- | sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java index 3b4891af9d..8b15d616ac 100644 --- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java +++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java @@ -26,12 +26,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.java.JavaOperation; -import org.apache.tuscany.sca.invocation.Interceptor; -import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.Invocable; @@ -40,8 +39,7 @@ import org.apache.tuscany.sca.runtime.Invocable; * * @version $Rev$ $Date$ */ -public class DataTransformationInterceptor implements Interceptor { - private Invoker next; +public class DataTransformationInterceptor extends InterceptorAsyncImpl { private Operation sourceOperation; @@ -64,11 +62,49 @@ public class DataTransformationInterceptor implements Interceptor { this.mediator = mediator; this.invocable = invocable; } - - public Invoker getNext() { - return next; + + public Message processRequest(Message msg) { + Map<String, Object> metadata = new HashMap<String, Object>(); + metadata.put(Invocable.class.getName(), invocable); + Object input = mediator.mediateInput(msg.getBody(), sourceOperation, targetOperation, metadata); + msg.setBody(input); + return msg; } + public Message processResponse(Message msg) { + Message resultMsg = msg; + Map<String, Object> metadata = new HashMap<String, Object>(); + metadata.put(Invocable.class.getName(), invocable); + + if (sourceOperation.isNonBlocking()) { + // Not to reset the message body + return resultMsg; + } + + Object result = resultMsg.getBody(); + + if (resultMsg.isFault()) { + Object transformedFault = null; + if ((result instanceof Exception) && !(result instanceof RuntimeException)) { + transformedFault = mediator.mediateFault(result, sourceOperation, targetOperation, metadata); + if (transformedFault != result) { + resultMsg.setFaultBody(transformedFault); + } + } + // + // Leave it to another layer to actually throw the Exception which constitutes + // the message body. We don't throw it here. + // + } else { + assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; + Object newResult = mediator.mediateOutput(result, sourceOperation, targetOperation, metadata); + resultMsg.setBody(newResult); + } + + return resultMsg; + } + +/* public Message invoke(Message msg) { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(Invocable.class.getName(), invocable); @@ -103,10 +139,8 @@ public class DataTransformationInterceptor implements Interceptor { return resultMsg; } +*/ - public void setNext(Invoker next) { - this.next = next; - } /** * Returns return type for first Holder in input list. |