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/09 12:58:52 UTC

svn commit: r1043914 - in /tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample: ./ src/main/java/sample/api/ src/main/java/sample/impl/ src/test/java/sample/ src/test/java/sample/impl/ src/test/resources/

Author: slaws
Date: Thu Dec  9 11:58:51 2010
New Revision: 1043914

URL: http://svn.apache.org/viewvc?rev=1043914&view=rev
Log:
TUSCANY-3801 - Start adding an async dimension to the implementation extension sample

Added:
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite
Modified:
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
    tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java

Modified: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml Thu Dec  9 11:58:51 2010
@@ -32,7 +32,8 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-base-runtime</artifactId>
+            <artifactId>tuscany-base-runtime-pom</artifactId>
+            <type>pom</type>
             <version>2.0-SNAPSHOT</version>
         </dependency>  
         

Modified: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java Thu Dec  9 11:58:51 2010
@@ -24,5 +24,6 @@ import org.w3c.dom.Element;
 public interface WSDLReference {
 
     Element call(String op, Element e);
-
+    void callAsync(String op, Element e);
+    
 }

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java Thu Dec  9 11:58:51 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package sample.impl;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.invocation.Constants;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvokerAsyncResponse;
+import org.apache.tuscany.sca.invocation.Message;
+import org.w3c.dom.Element;
+
+/**
+ * Invoker for Sample components that implement a WSDL interface using a generic
+ * call method.
+ * 
+ * @version $Rev$ $Date$
+ */
+class SampleAsyncResponseInvoker implements InvokerAsyncResponse {
+    final String name;
+    final Object instance;
+    final Operation op;
+    Map<String, Object> asyncMessageMap;
+
+    SampleAsyncResponseInvoker(Map<String, Object> asyncMessageMap, final Operation op, final Class<?> clazz, final Object instance) {
+        this.asyncMessageMap = asyncMessageMap;  
+        this.name = op.getName();
+        this.instance = instance;
+        this.op = op;
+    }
+
+    public void invokeAsyncResponse(final Message msg) {
+        try {
+            String messageID = (String) msg.getHeaders().get(Constants.MESSAGE_ID);
+            String forwardOpName = (String)asyncMessageMap.get(messageID);
+            
+            // process the async response
+            //Object response = ((Object[])msg.getBody())[0];
+            Object response = msg.getBody();
+            
+            Method method = instance.getClass().getMethod(forwardOpName + "Callback", Element.class);
+            method.invoke(instance, response);
+        } catch(Exception e) {
+            e.printStackTrace();
+            // TODO - need to throw this to somewhere?
+        }
+    }
+}

Modified: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java Thu Dec  9 11:58:51 2010
@@ -20,8 +20,11 @@
 package sample.impl;
 
 import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -29,7 +32,9 @@ import org.apache.tuscany.sca.interfaced
 import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation;
 import org.apache.tuscany.sca.invocation.Invoker;
-import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.invocation.InvokerAsyncRequest;
+import org.apache.tuscany.sca.invocation.InvokerAsyncResponse;
+import org.apache.tuscany.sca.provider.ImplementationAsyncProvider;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
 
@@ -38,16 +43,19 @@ import org.apache.tuscany.sca.runtime.Ru
  * 
  * @version $Rev$ $Date$
  */
-class SampleProvider implements ImplementationProvider {
+class SampleProvider implements ImplementationAsyncProvider {
     final RuntimeComponent comp;
     final SampleImplementation impl;
     final ProxyFactory pxf;
+    final ExtensionPointRegistry ep;
     Object instance;
+    Map<String, Object> asyncMessageMap = new HashMap<String, Object>();
 
-    SampleProvider(final RuntimeComponent comp, final SampleImplementation impl, ProxyFactory pf) {
+    SampleProvider(final RuntimeComponent comp, final SampleImplementation impl, ProxyFactory pf, ExtensionPointRegistry ep) {
         this.comp = comp;
         this.impl = impl;
         this.pxf = pf;
+        this.ep = ep;
     }
 
     public void start() {
@@ -63,7 +71,7 @@ class SampleProvider implements Implemen
                 if(i instanceof JavaInterface)
                     f.set(instance, pxf.createProxy(comp.getComponentContext().getServiceReference(f.getType(), r.getName())));
                 else
-                    f.set(instance, new SampleWSDLProxy(r.getEndpointReferences().get(0), i));
+                    f.set(instance, new SampleWSDLProxy(asyncMessageMap, r.getEndpointReferences().get(0), i, ep));
             }
         } catch(Exception e) {
             throw new RuntimeException(e);
@@ -88,4 +96,17 @@ class SampleProvider implements Implemen
             throw new RuntimeException(e);
         }
     }
+    
+    public InvokerAsyncRequest createAsyncInvoker(RuntimeComponentService service, Operation operation) {
+        // Only providing Async support through WSDL interfaces in this test
+        try {
+            return new SampleWSDLInvoker((WSDLOperation)operation, impl.clazz, instance);
+        } catch(Exception e) {
+            throw new RuntimeException(e);
+        }            
+    }
+    
+    public InvokerAsyncResponse createAsyncResponseInvoker(Operation operation) {
+        return new SampleAsyncResponseInvoker(asyncMessageMap, operation, impl.clazz, instance);
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java Thu Dec  9 11:58:51 2010
@@ -33,13 +33,15 @@ import org.apache.tuscany.sca.runtime.Ru
  */
 public class SampleProviderFactory implements ImplementationProviderFactory<SampleImplementation> {
     final ProxyFactory pxf;
+    final ExtensionPointRegistry ep;
 
     public SampleProviderFactory(final ExtensionPointRegistry ep) {
+        this.ep = ep;
         pxf = ExtensibleProxyFactory.getInstance(ep);
     }
 
     public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final SampleImplementation impl) {
-        return new SampleProvider(comp, impl, pxf);
+        return new SampleProvider(comp, impl, pxf, ep);
     }
 
     public Class<SampleImplementation> getModelType() {

Modified: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java Thu Dec  9 11:58:51 2010
@@ -21,9 +21,11 @@ package sample.impl;
 
 import java.lang.reflect.Method;
 
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
 import org.w3c.dom.Element;
 
 /**
@@ -32,7 +34,7 @@ import org.w3c.dom.Element;
  * 
  * @version $Rev$ $Date$
  */
-class SampleWSDLInvoker implements Invoker {
+class SampleWSDLInvoker extends InterceptorAsyncImpl {
     final String name;
     final Object instance;
     final Method method;
@@ -43,14 +45,43 @@ class SampleWSDLInvoker implements Invok
         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. 
+        
+        // At this point we could serialize the ??? and pick it up again 
+        // later to send the async response
+        
+        ((RuntimeEndpoint)msg.getTo()).invokeAsyncResponse(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/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java?rev=1043914&r1=1043913&r2=1043914&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java Thu Dec  9 11:58:51 2010
@@ -24,8 +24,12 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.Constants;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
 import org.w3c.dom.Element;
 
@@ -37,8 +41,14 @@ import sample.api.WSDLReference;
 class SampleWSDLProxy implements WSDLReference {
     final RuntimeEndpointReference repr;
     final Map<String, Operation> ops;
+    final ExtensionPointRegistry ep;
+    final MessageFactory mf;
+    Map<String, Object> asyncMessageMap;
 
-    SampleWSDLProxy(EndpointReference epr, Interface wi) {
+    SampleWSDLProxy(Map<String, Object> asyncMessageMap, EndpointReference epr, Interface wi, ExtensionPointRegistry ep) {
+        this.asyncMessageMap = asyncMessageMap; 
+        this.ep = ep;
+        mf = ep.getExtensionPoint(MessageFactory.class);
         repr = (RuntimeEndpointReference)epr;
         ops = new HashMap<String, Operation>();
         for(Operation o: wi.getOperations())
@@ -54,4 +64,33 @@ class SampleWSDLProxy implements WSDLRef
             throw new RuntimeException(ex);
         }
     }
+    
+    @Override
+    public void callAsync(String op, Element e) {
+        // Asynchronously invoke the named operation on the endpoint reference
+        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();
+        }
+        
+        // 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);
+    }    
 }

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java Thu Dec  9 11:58:51 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package sample;
+
+import static java.lang.System.out;
+import static sample.Xutil.elem;
+import static sample.Xutil.text;
+import static sample.Xutil.xdom;
+
+import org.w3c.dom.Element;
+
+import sample.api.Java;
+import sample.api.WSDL;
+import sample.api.WSDLReference;
+
+/**
+ * Sample component implementation that uses Java interfaces.
+ * 
+ * @version $Rev$ $Date$
+ */
+@Java(Upper.class)
+public class UpperSampleAsyncReferenceImpl {
+    
+    @WSDL("http://sample/upper-async#Upper")
+    WSDLReference upper;
+    
+    Element response;
+    
+    public String upper(String s) {
+        out.println("UpperSampleAsyncReferenceImpl.upper(" + s + ")");
+        
+        // TODO - I'm passing in the non-wrapped version of the parameter
+        //        here which doesn't seem right. Need to test that databinding
+        //        wraps it correctly
+        final Element ureq = xdom("http://sample/upper-async", "s", text(s));
+        upper.callAsync("upper", ureq);
+        
+        try {
+            Thread.sleep(500);
+        } catch (Exception ex) {
+            // do nothing
+        }
+        
+        return response.getTextContent();
+    }
+    
+    /**
+     *  In this implementation the convention is that the 
+     *  async callback arrives at an operation named
+     *  operationName + Callback
+     */
+    public void upperCallback(Element response) {
+        out.println("UpperSampleAsyncReferenceImpl.upperCallback(" + response.getTextContent() + ")");
+        this.response = response;
+    }
+}

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java Thu Dec  9 11:58:51 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package sample;
+
+import static java.lang.System.out;
+import static sample.Xutil.elem;
+import static sample.Xutil.text;
+import static sample.Xutil.xdom;
+
+import org.w3c.dom.Element;
+
+import sample.api.WSDL;
+
+/**
+ * Sample component implementation that uses Java interfaces.
+ * 
+ * @version $Rev$ $Date$
+ */
+@WSDL("http://sample/upper-async#Upper")
+public class UpperSampleAsyncServiceImpl {
+
+    public Element call(String op, Element e) {
+        String input = e.getTextContent();
+        out.println("UpperSampleAsyncServiceImpl.upper(" + input + ")");
+        String output = input.toUpperCase();
+        return xdom("http://sample/upper-async", "upperResponse", elem("result", text(output)));
+    }
+}

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java Thu Dec  9 11:58:51 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package sample.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import sample.Upper;
+
+/**
+ * Test how to run an SCA contribution containing a test composite on a
+ * Tuscany runtime node.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SampleNativeAsyncTestCase {
+    static Node node;
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        final NodeFactory nf = NodeFactory.newInstance();
+        String here = SampleNativeAsyncTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString();
+        node = nf.createNode(new Contribution("test", here));
+        node.start();
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        node.stop();
+    }
+
+    @Test
+    public void testReference() {
+        System.out.println("SampleNaiveAsyncTestCase.testReference");
+        Upper upper = node.getService(Upper.class, "SampleNativeAsyncReference");
+        final String r = upper.upper("async"); 
+        System.out.println(r);
+        assertEquals("ASYNC", r);
+    }
+}

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl Thu Dec  9 11:58:51 2010
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * Licensed to the Apache Software Foundation (ASF) under one
+    * or more contributor license agreements.  See the NOTICE file
+    * distributed with this work for additional information
+    * regarding copyright ownership.  The ASF licenses this file
+    * to you under the Apache License, Version 2.0 (the
+    * "License"); you may not use this file except in compliance
+    * with the License.  You may obtain a copy of the License at
+    * 
+    *   http://www.apache.org/licenses/LICENSE-2.0
+    * 
+    * Unless required by applicable law or agreed to in writing,
+    * software distributed under the License is distributed on an
+    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    * KIND, either express or implied.  See the License for the
+    * specific language governing permissions and limitations
+    * under the License.    
+-->
+<wsdl:definitions targetNamespace="http://sample/upper-async" 
+                  xmlns:tns="http://sample/upper-async"
+                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                  xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+	              name="Upper">
+
+    <wsdl:types>
+        <schema elementFormDefault="qualified" 
+                targetNamespace="http://sample/upper-async"
+                xmlns="http://www.w3.org/2001/XMLSchema">
+            <element name="upper">
+                <complexType>
+                    <sequence>
+                        <element name="s" type="xsd:string" />
+                    </sequence>
+                </complexType>
+            </element>
+
+            <element name="upperResponse">
+                <complexType>
+                    <sequence>
+                        <element name="result" type="xsd:string" />
+                    </sequence>
+                </complexType>
+            </element>
+
+        </schema>
+    </wsdl:types>
+
+    <wsdl:message name="upperRequest">
+        <wsdl:part element="tns:upper" name="parameters" />
+    </wsdl:message>
+
+    <wsdl:message name="upperResponse">
+        <wsdl:part element="tns:upperResponse" name="parameters" />
+    </wsdl:message>
+
+    <wsdl:portType name="Upper" sca:requires="sca:asyncInvocation">
+        <wsdl:operation name="upper">
+            <wsdl:input message="tns:upperRequest" name="upperRequest" />
+            <wsdl:output message="tns:upperResponse" name="upperResponse" />
+        </wsdl:operation>
+    </wsdl:portType>
+
+</wsdl:definitions>

Added: tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite?rev=1043914&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite (added)
+++ tuscany/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite Thu Dec  9 11:58:51 2010
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+  xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+  targetNamespace="http://test"
+  name="testnativeasync">
+      
+    <component name="SampleNativeAsyncReference">
+        <t:implementation.sample class="sample.UpperSampleAsyncReferenceImpl"/>
+        <reference name="upper" target="SampleNativeAsyncService"/>
+    </component>  
+    
+    <component name="SampleNativeAsyncService">
+        <t:implementation.sample class="sample.UpperSampleAsyncServiceImpl"/>
+    </component>
+ 
+</composite>