You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/12/03 13:23:20 UTC

svn commit: r1041784 - in /tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src: main/java/sampleasync/impl/ test/java/sampleasync/impl/

Author: slaws
Date: Fri Dec  3 12:23:19 2010
New Revision: 1041784

URL: http://svn.apache.org/viewvc?rev=1041784&view=rev
Log:
TUSCANY-3801 - update to match infrastructure changes to support native async bindings (not committed yet)

Modified:
    tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java
    tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java
    tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java
    tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java
    tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java

Modified: tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java?rev=1041784&r1=1041783&r2=1041784&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java Fri Dec  3 12:23:19 2010
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.interfacedef.Interface;
@@ -85,17 +86,23 @@ class SampleAsyncProvider implements Imp
     }
 
     public Invoker createInvoker(final RuntimeComponentService s, final Operation op) {
+        // TODO - we're passing EP into the WSDL invoker so this isn't going to work
+        //        properly for sync calls
+        return createAsyncInvoker(null, s, op); 
+    }
+    
+    public Invoker createAsyncInvoker(Endpoint endpoint, final RuntimeComponentService s, final Operation op) {
         try {
             // Creating an invoker for a Java or WSDL-typed implementation
             if(op instanceof JavaOperation)
                 return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance);
-            return new SampleWSDLInvoker((WSDLOperation)op, impl.clazz, instance);
+            return new SampleWSDLInvoker(endpoint, (WSDLOperation)op, impl.clazz, instance);
         } catch(Exception e) {
             throw new RuntimeException(e);
         }
     }
     
-    public Invoker createAsyncResponseInvoker(RuntimeComponentService service, Operation operation) {
+    public Invoker createAsyncResponseInvoker(Operation operation) {
         return new SampleAsyncResponseInvoker(asyncMessageMap, operation, impl.clazz, instance);
     }
 }

Modified: tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java?rev=1041784&r1=1041783&r2=1041784&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java Fri Dec  3 12:23:19 2010
@@ -54,10 +54,10 @@ class SampleAsyncResponseInvoker impleme
             String forwardOpName = (String)asyncMessageMap.get(messageID);
             
             // process the async response
-            Object reponse = ((Object[])msg.getBody())[0];
+            //Object reponse = ((Object[])msg.getBody())[0];
+            Object reponse = msg.getBody();
             
-            //Method method = instance.getClass().getMethod(forwardOpName + "Callback", Element.class);
-            Method method = instance.getClass().getMethod(forwardOpName + "Callback", String.class);
+            Method method = instance.getClass().getMethod(forwardOpName + "Callback", Element.class);
             method.invoke(instance, reponse);
         } catch(Exception e) {
             e.printStackTrace();

Modified: tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java?rev=1041784&r1=1041783&r2=1041784&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java Fri Dec  3 12:23:19 2010
@@ -21,9 +21,14 @@ package sampleasync.impl;
 
 import java.lang.reflect.Method;
 
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.invocation.impl.InterceptorAsyncImpl;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation;
+import org.apache.tuscany.sca.invocation.InterceptorAsync;
 import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.InvokerAsync;
 import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
 import org.w3c.dom.Element;
 
 /**
@@ -32,26 +37,53 @@ import org.w3c.dom.Element;
  * 
  * @version $Rev$ $Date$
  */
-class SampleWSDLInvoker implements Invoker {
+class SampleWSDLInvoker extends InterceptorAsyncImpl {
+    final Endpoint endpoint;
     final String name;
     final Object instance;
     final Method method;
 
-    SampleWSDLInvoker(final WSDLOperation op, final Class<?> clazz, final Object instance) throws SecurityException, NoSuchMethodException {
+    SampleWSDLInvoker(Endpoint endpoint, final WSDLOperation op, final Class<?> clazz, final Object instance) throws SecurityException, NoSuchMethodException {
+        this.endpoint = endpoint;
         this.name = op.getName();
         this.instance = instance;
         this.method = clazz.getMethod("call", String.class, Element.class);
     }
+    
+    public Invoker getNext() {
+        // Can't get next for an implementation invoker
+        return null;
+    }
 
     public Message invoke(final Message msg) {
+        return processRequest(msg);
+    }
+    
+    public void invokeAsyncRequest(Message msg) {
+        Message responseMsg = processRequest(msg);
+        
+        // in this sample programming model we make the async
+        // response from the implementation provider. The 
+        // component implementation itself doesn't get a chance to 
+        // do async responses. 
+        
+        ((RuntimeEndpoint)endpoint).invokeAsyncResponse(this, responseMsg);
+    }
+    
+    public Message processRequest(Message msg) {
         try {
             //AsyncHeader asyncHeader = (String) message.getHeaders().get("ASYNC-HEADER");
             // Invoke the generic call method
-            msg.setBody(method.invoke(instance, name, ((Object[])msg.getBody())[0]));
+            Object response = method.invoke(instance, name, ((Object[])msg.getBody())[0]);
+            msg.setBody(response);
         } catch(Exception e) {
             e.printStackTrace();
             msg.setFaultBody(e.getCause());
         }
         return msg;
     }
+    
+    public Message processResponse(Message msg) {
+        return msg;
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java?rev=1041784&r1=1041783&r2=1041784&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java (original)
+++ tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java Fri Dec  3 12:23:19 2010
@@ -72,16 +72,27 @@ class SampleWSDLProxy implements WSDLRef
         Message message = mf.createMessage();
         message.setBody(new Object[]{e});
         
+        // We could MESSAGE_ID here if required. If not the infrastructure
+        // will generate a UUID
+        String messageID = "myuniqueid";
+        message.getHeaders().put(Constants.MESSAGE_ID, messageID);
+        
+        // save the message id ready for when we process the response        
+        asyncMessageMap.put(messageID, op);
+        
         // We could add implementation specific headers here if required
+        //message.getHeaders().put(Constants.???, ???);
+        
         try {
             repr.invokeAsync(ops.get(op), message);
         } catch (Throwable ex) {
             ex.printStackTrace();
         }
         
-        // save the message id ready for when we process the response
-        String messageID = (String) message.getHeaders().get(Constants.MESSAGE_ID);
-        
-        asyncMessageMap.put(messageID, op);
+        // if we don't provide a message id we can get the one the 
+        // infrastructure generates
+        //String messageID = (String) message.getHeaders().get(Constants.MESSAGE_ID);
+        //asyncMessageMap.put(messageID, op);
+
     }
 }

Modified: tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java?rev=1041784&r1=1041783&r2=1041784&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java Fri Dec  3 12:23:19 2010
@@ -41,7 +41,7 @@ public class UpperSampleAsyncReferenceIm
     
     @WSDL("http://sample/upper#Upper")
     WSDLReference upper;
-    String response;
+    Element response;
     
     public String upper(String s) {
         out.println("UpperSampleAsyncReferenceImpl.upper(" + s + ")");
@@ -59,7 +59,7 @@ public class UpperSampleAsyncReferenceIm
             // do nothing
         }
         
-        return response;
+        return response.getTextContent();
     }
     
     /**
@@ -67,11 +67,8 @@ public class UpperSampleAsyncReferenceIm
      *  async callback arrives at an operation named
      *  operationName + Callback
      */
-    // TODO - I think this should take and Element parameter but the response 
-    //        handler interface is a Java interface at the moment and so no
-    //        transformation takes place automatically.
-    public void upperCallback(String response) {
-        out.println("UpperSampleAsyncReferenceImpl.upperCallback(" + response + ")");
+    public void upperCallback(Element response) {
+        out.println("UpperSampleAsyncReferenceImpl.upperCallback(" + response.getTextContent() + ")");
         this.response = response;
     }
 }