summaryrefslogtreecommitdiffstats
path: root/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync')
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java33
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java47
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java36
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java63
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java63
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java70
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java39
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java74
-rw-r--r--sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java45
9 files changed, 470 insertions, 0 deletions
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java
new file mode 100644
index 0000000000..0c29cea1dc
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java
@@ -0,0 +1,33 @@
+/*
+ * 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 sampleasync;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Sample service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+@Remotable
+public interface Upper {
+
+ String upper(String s);
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java
new file mode 100644
index 0000000000..ad2e62f85d
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java
@@ -0,0 +1,47 @@
+/*
+ * 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 sampleasync;
+
+import java.util.concurrent.Future;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.oasisopen.sca.annotation.AsyncInvocation;
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Sample service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+@Remotable
+@AsyncInvocation
+public interface UpperAsyncReference {
+
+ // Sync
+ String upper(String s);
+
+ // Aysnc Poll
+ public Response<String> upperAsync(String s);
+
+ // Async Callback
+ public Future<String> upperAsync(String s, AsyncHandler<String> handler);
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java
new file mode 100644
index 0000000000..cb4a1c0b42
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java
@@ -0,0 +1,36 @@
+/*
+ * 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 sampleasync;
+
+import org.oasisopen.sca.ResponseDispatch;
+import org.oasisopen.sca.annotation.AsyncInvocation;
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Sample service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+@Remotable
+@AsyncInvocation
+public interface UpperAsyncService {
+
+ void upperAsync(String s,ResponseDispatch<String> response);
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java
new file mode 100644
index 0000000000..36fdb76424
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.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 sampleasync.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 sampleasync.Upper;
+
+/**
+ * Test how to run an SCA contribution containing a test composite on a
+ * Tuscany runtime node.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SampleGenericAsyncTestCase {
+ static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ final NodeFactory nf = NodeFactory.newInstance();
+ String here = SampleGenericAsyncTestCase.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("SampleAsyncReferenceTestCase.testReference");
+ Upper upper = node.getService(Upper.class, "SampleAsyncReference");
+ final String r = upper.upper("async");
+ System.out.println(r);
+ assertEquals("ASYNC", r);
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java
new file mode 100644
index 0000000000..bc35a637d1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/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 sampleasync.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 sampleasync.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/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java
new file mode 100644
index 0000000000..9cf7ff9883
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java
@@ -0,0 +1,70 @@
+/*
+ * 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 sampleasync.impl;
+
+import static java.lang.System.out;
+
+import java.util.concurrent.ExecutionException;
+
+import javax.xml.ws.Response;
+
+import org.oasisopen.sca.annotation.Reference;
+
+import sampleasync.Upper;
+import sampleasync.UpperAsyncReference;
+
+/**
+ * Sample service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UpperJavaAsyncReferenceImpl implements Upper {
+
+ @Reference
+ UpperAsyncReference upper;
+
+ public String upper(String s) {
+ out.println("UpperAsyncReferenceImpl.upper(" + s + ")");
+
+ // async poll
+ Response<String> response = upper.upperAsync(s);
+
+ while (!response.isDone()){
+ System.out.println("Waiting for poll");
+ try {
+ Thread.sleep(500);
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+
+ String result = null;
+
+ try {
+ result = response.get();
+ System.out.println("Async client poll patern: result = " + result);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java
new file mode 100644
index 0000000000..fb9ad065ad
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java
@@ -0,0 +1,39 @@
+/*
+ * 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 sampleasync.impl;
+
+import static java.lang.System.out;
+
+import org.oasisopen.sca.ResponseDispatch;
+
+import sampleasync.UpperAsyncService;
+
+/**
+ * Sample component implementation that uses Java interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UpperJavaAsyncServiceImpl implements UpperAsyncService {
+
+ public void upperAsync(String s,ResponseDispatch<String> response) {
+ out.println("UpperJavaAsyncServiceImpl.upperAsync(" + s + ")");
+ response.sendResponse(s.toUpperCase());
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java
new file mode 100644
index 0000000000..101c6a4399
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java
@@ -0,0 +1,74 @@
+/*
+ * 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 sampleasync.impl;
+
+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;
+import sampleasync.Upper;
+
+/**
+ * Sample component implementation that uses Java interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+@Java(Upper.class)
+public class UpperSampleAsyncReferenceImpl {
+
+ @WSDL("http://sample/upper#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. If I pass in the wrapped
+ // version then the databinding won't unwrap on the reference
+ // side as it thinks the target Java interface is bare?
+ final Element ureq = xdom("http://sample/upper", "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/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java
new file mode 100644
index 0000000000..41a85e44a0
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/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 sampleasync.impl;
+
+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#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", "upperResponse", elem("result", text(output)));
+ }
+}