diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/core-databinding/src/main/java/org')
-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. |