summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-12-09 11:58:51 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-12-09 11:58:51 +0000
commit7e15f24294c313940b281faed8df35c94c07e42d (patch)
tree986e35273e45b3d59ae9838a8fdb20f138cfdc4d
parent21c4fe09a85c35932b3240f3a4141849e80496da (diff)
TUSCANY-3801 - Start adding an async dimension to the implementation extension sample
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1043914 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml3
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java3
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java66
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java29
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java4
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java35
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java41
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java73
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java45
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java63
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl65
-rw-r--r--sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite34
12 files changed, 451 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml
index 7ec143e4ed..7435c8dba0 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/pom.xml
@@ -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>
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
index cad8478a2a..bc0d5cc5d8 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
@@ -24,5 +24,6 @@ import org.w3c.dom.Element;
public interface WSDLReference {
Element call(String op, Element e);
-
+ void callAsync(String op, Element e);
+
}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java
new file mode 100644
index 0000000000..2366deeb33
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java
@@ -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?
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java
index 5d946b037b..a7e68cfee6 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java
@@ -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.interfacedef.java.JavaInterface;
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.RuntimeComponentService;
*
* @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 ImplementationProvider {
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 ImplementationProvider {
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);
+ }
}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java
index 4ad24d33ff..86ddd50ea6 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProviderFactory.java
@@ -33,13 +33,15 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent;
*/
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() {
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
index 6c5317274f..4d33a956a8 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
@@ -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 Invoker {
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;
+ }
}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
index a6882a0103..0fc8403cf1 100644
--- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
@@ -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 WSDLReference {
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);
+ }
}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java
new file mode 100644
index 0000000000..b6f59515cc
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncReferenceImpl.java
@@ -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;
+ }
+}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java
new file mode 100644
index 0000000000..69d6cb9ecf
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/UpperSampleAsyncServiceImpl.java
@@ -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)));
+ }
+}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java
new file mode 100644
index 0000000000..eeadb48b24
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java
@@ -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);
+ }
+}
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl
new file mode 100644
index 0000000000..d8d9065ca8
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/Upper-async.wsdl
@@ -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>
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite
new file mode 100644
index 0000000000..6610b66815
--- /dev/null
+++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/test/resources/testnativeasync.composite
@@ -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>