summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache')
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java89
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java46
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java46
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java38
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncClient.java33
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java50
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java180
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl2.java31
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1ClientImpl.java99
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServer.java46
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServerImpl.java29
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java39
-rw-r--r--sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java44
13 files changed, 770 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java
new file mode 100644
index 0000000000..2fb9c069ad
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.annotation.Service;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Property;
+import org.apache.tuscany.sca.itest.Service1;
+import org.apache.tuscany.sca.itest.TestException;
+import org.apache.tuscany.sca.itest.TestInvocation;
+
+
+/**
+ * Test initiation class with a single reference of multiplicity 1..1
+ * @author MikeEdwards
+ *
+ */
+@Service(TestInvocation.class)
+public class ASM_0002_Client implements org.apache.tuscany.sca.itest.TestInvocation {
+
+ @Property
+ public String testName = "ASM_xxxx";
+
+ // required=false implies a multiplicity of 0..1 so that this component need not be wired
+ @Reference(required=false)
+ public Service1 reference1;
+
+ /**
+ * This method is offered as a service and is
+ * invoked by the test client to run the test
+ */
+ public String invokeTest( String input ) throws TestException {
+ String response = null;
+
+ try {
+ response = runTest( input );
+ } catch( Exception e ) {
+ System.out.println("TestInvocation: Test service got an exception during execution:" + e.getClass().getName()+ " " + e.getMessage() );
+ e.printStackTrace();
+ throw new TestException("Test service got an exception during execution: " + e.getClass().getName()+ " " + e.getMessage() );
+ } // end try
+ return response;
+ } // end method invokeTest
+
+ /**
+ * This method actually runs the test - and is subclassed by classes that run other tests.
+ * @param input - an input string
+ * @return - a response string = "ASM_0001 inputString xxxxx" where xxxxx depends on the invoked service
+ *
+ */
+ public String runTest( String input ){
+ String response = null;
+ // Deals with cases where this component reference is not wired
+ if( reference1 != null ) {
+ String response1 = reference1.operation1(input);
+
+ response = testName + " " + input + " " + response1;
+ } else {
+ response = testName + " " + input + " no invocation";
+ } // end if
+
+ return response;
+ } // end method runTest
+
+ /**
+ * Sets the name of the test
+ * @param name - the test name
+ */
+ protected void setTestName( String name ) {
+ testName = name;
+ }
+
+} //
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java
new file mode 100644
index 0000000000..01446c88e5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java
@@ -0,0 +1,46 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+/**
+ * A business exception
+ *
+ */
+public class BusinessFault1 extends Exception {
+
+ // Serialization UID
+ private static final long serialVersionUID = 44240525335368929L;
+
+ public BusinessFault1() {
+ super();
+ }
+
+ public BusinessFault1(String arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault1(Throwable arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault1(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+} // end class BusinessFault1
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java
new file mode 100644
index 0000000000..7f9d965820
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java
@@ -0,0 +1,46 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+/**
+ * A business exception
+ *
+ */
+public class BusinessFault2 extends Exception {
+
+ // Serialization UID
+ private static final long serialVersionUID = 44240525335368929L;
+
+ public BusinessFault2() {
+ super();
+ }
+
+ public BusinessFault2(String arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault2(Throwable arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault2(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+} // end class BusinessFault1
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java
new file mode 100644
index 0000000000..84ba75e0e2
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * A test service interface
+ * @author MikeEdwards
+ *
+ */
+@Remotable
+public interface Service1 {
+
+ /**
+ * Method for invoking testcase service
+ * @param input - input parameter(s) as a String
+ * @return - output data as a String
+ */
+ public String operation1( String input );
+
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncClient.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncClient.java
new file mode 100644
index 0000000000..5b76af2e8f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncClient.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 org.apache.tuscany.sca.itest;
+
+import java.util.concurrent.Future;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface Service1AsyncClient extends Service1 {
+ Response<String> operation1Async(String input);
+ Future<?> operation1Async(String input, AsyncHandler<String> handler);
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java
new file mode 100644
index 0000000000..1500cbdb07
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.ResponseDispatch;
+import org.oasisopen.sca.annotation.AsyncFault;
+import org.oasisopen.sca.annotation.AsyncInvocation;
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Service1 service interface
+ * - Asynchronous server version
+ */
+@AsyncInvocation
+@Remotable
+public interface Service1AsyncServer {
+
+ /**
+ * Synchronous method for invoking testcase service
+ * @param input - input parameter as a String
+ * @return - output data as a String
+ * Listed here for documentation purposes - this is the operation that the async server operation maps to
+ */
+ // public String operation1( String input );
+
+ /**
+ * Async server version of the synchronous operation1 method
+ * @param input - input parameter as a String
+ * @param handler - the ResponseDispatch<String> handler used to send the response message (a String in this case)
+ */
+ @AsyncFault( {BusinessFault1.class, BusinessFault2.class} )
+ public void operation1Async( String input, ResponseDispatch<String> handler );
+
+} // end interface Service1AsyncServer
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java
new file mode 100644
index 0000000000..e4e17ca860
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java
@@ -0,0 +1,180 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.oasisopen.sca.ResponseDispatch;
+import org.oasisopen.sca.ServiceUnavailableException;
+import org.oasisopen.sca.annotation.*;
+
+
+/**
+ * Java component implementation
+ * 1 service with interface Service1AsyncServer
+ * 0 references
+ *
+ * Async server implementation of the Service1 service
+ *
+ */
+@Service(Service1AsyncServer.class)
+public class Service1AsyncServerImpl implements Service1AsyncServer {
+
+ private volatile ResponseDispatch<String> responseHandler = null;
+
+ private volatile String tmpFilePath = null;
+
+ @Property(required=true)
+ public volatile String serviceName = "service1";
+
+ /*
+ public String operation1(String input) {
+ return serviceName + " operation1 invoked";
+ }
+ */
+
+ public void operation1Async(String input, ResponseDispatch<String> handler) {
+ // Store the ResponseDispatch object
+ responseHandler = handler;
+
+ serializeResponseHandler(responseHandler);
+
+ // Now kick off processing on a separate thread that will dispatch the response some time after this
+ // initial method returns...
+ runResponseThread( input );
+
+ // return
+ return;
+ } // end method operation1Async
+
+ /**
+ * Serialize the response handler to a file
+ * @param responseHandler2
+ */
+ private void serializeResponseHandler(
+ ResponseDispatch<String> responseHandler2) {
+ if( responseHandler2 instanceof Serializable ) {
+ Serializable obj = (Serializable)responseHandler2;
+ FileOutputStream fos;
+ try {
+ File tmpFile = File.createTempFile("Async_Server", null);
+ tmpFilePath = tmpFile.getCanonicalPath();
+ fos = new FileOutputStream(tmpFile);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+
+ oos.writeObject(obj);
+
+ oos.close();
+ } catch (FileNotFoundException e) {
+ } catch (IOException e) {
+ e.printStackTrace();
+ } // end try
+
+ } // end if
+ } // end method serializeResponseHandler
+
+ @SuppressWarnings("unchecked")
+ public ResponseDispatch<String> deserializeResponseHandler() {
+ try {
+ if( tmpFilePath == null ) return null;
+ FileInputStream fis = new FileInputStream( tmpFilePath );
+ ObjectInputStream ois = new ObjectInputStream(fis);
+
+ ResponseDispatch<String> responseDispatch = (ResponseDispatch<String>) ois.readObject();
+
+ ois.close();
+ return responseDispatch;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } // end try
+
+ return null;
+ } // end method deserializeResponseHandler
+
+ /**
+ * Method used to run a separate thread, to invoke the ResponseDispatch
+ */
+ private void runResponseThread( String input ) {
+
+ int invocationCount = 2; // # of threads to use
+ long maxWaitTime = 5000; // Max wait time for completion = 5sec
+
+ // Run the tests using a ThreadPoolExecutor
+ ThreadPoolExecutor theExecutor = new ThreadPoolExecutor( invocationCount, invocationCount,
+ maxWaitTime, TimeUnit.MILLISECONDS,
+ new ArrayBlockingQueue<Runnable>( invocationCount ) );
+
+
+
+ // Perform the invocations on separate thread...
+ theExecutor.execute( new separateThreadInvoker( input ) );
+
+ } // end method runResponseThread
+
+ /**
+ * An inner class which acts as a runnable task for invoking APIs on threads that are not processing
+ * either a service operation or a callback operation
+ */
+ private class separateThreadInvoker implements Runnable {
+
+ private long pauseTime = 1000; // Pause interval to allow initiating thread to complete
+ private String input; // Input parameter
+
+ public separateThreadInvoker( String input ) {
+ super();
+ this.input = input;
+ } // end constructor
+
+ public void run() {
+
+ // Wait for a short time to ensure that the invoking thread has time to return
+ try {
+ Thread.sleep(pauseTime);
+ } catch (InterruptedException e) {
+ // Nothing to do here...
+ } // end try
+
+ ResponseDispatch<String> responseHandler2 = deserializeResponseHandler();
+ if( responseHandler2 != null ) {
+ responseHandler = responseHandler2;
+ } // end if
+
+ if( "exception".equals(input) ) {
+ // Invoke the response dispatch object to return a an exception
+ responseHandler.sendFault( new BusinessFault1(serviceName + " operation1 invoked asynchronously"));
+
+ } else {
+ // Invoke the response dispatch object to return a response
+ responseHandler.sendResponse( serviceName + " operation1 invoked asynchronously");
+ } // end if
+ } // end method run
+
+ } // end class separateThreadInvoker
+
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl2.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl2.java
new file mode 100644
index 0000000000..1f653ed8a8
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl2.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.ResponseDispatch;
+
+public class Service1AsyncServerImpl2 implements Service1AsyncServer {
+
+ @Override
+ public void operation1Async(String input, ResponseDispatch<String> handler) {
+ handler.sendResponse("Service1AsyncServerImpl2.operation1Async " + input);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1ClientImpl.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1ClientImpl.java
new file mode 100644
index 0000000000..d45acdcde9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1ClientImpl.java
@@ -0,0 +1,99 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.oasisopen.sca.annotation.Reference;
+
+public class Service1ClientImpl implements Service1 {
+
+ @Reference
+ Service1AsyncClient service1;
+
+ Object threeMutex = new Object();
+ String threeResp;
+ Throwable threeEx;
+
+ @Override
+ public String operation1(String input) {
+
+ String resp = "";
+ resp += service1.operation1(input);
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ resp += invokeAsyncType1(input);
+ resp += invokeAsyncType2(input);
+ return resp;
+ }
+
+ private String invokeAsyncType1(String input) {
+ // two
+ Response<String> h = service1.operation1Async(input+"TypeOne");
+ try {
+ return h.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String invokeAsyncType2(String input) {
+ // three
+ System.out.println("invokeAsyncType2 entry");
+ AsyncHandler<String> ah = new AsyncHandler<String>() {
+ @Override
+ public void handleResponse(Response<String> res) {
+ try {
+ System.out.println("invokeAsyncType2 callback handler invoked");
+ threeResp = res.get();
+ } catch (Throwable e) {
+ threeEx = e;
+ }
+ synchronized (threeMutex) {
+ threeMutex.notifyAll();
+ }
+ }
+ };
+ service1.operation1Async(input+"TypeTwo",ah);
+ if (threeResp == null && threeEx == null) {
+ synchronized (threeMutex) {
+ if (threeResp == null && threeEx == null) {
+ try {
+ threeMutex.wait(15000);
+ System.out.println("invokeAsyncType2 mutex notified or wait expired");
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ if (threeResp == null && threeEx == null) {
+ throw new RuntimeException("no response recieved");
+ }
+ if (threeEx != null) {
+ throw new RuntimeException("got exception", threeEx);
+ }
+ return threeResp;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServer.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServer.java
new file mode 100644
index 0000000000..daafd10ec6
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServer.java
@@ -0,0 +1,46 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Service1 service interface
+ * - Non-Asynchronous server version
+ */
+@Remotable
+public interface Service1NonAsyncServer {
+
+ /**
+ * Synchronous method for invoking testcase service
+ * @param input - input parameter as a String
+ * @return - output data as a String
+ */
+ public String operation1( String input );
+
+ /**
+ * Async server version of the synchronous operation1 method
+ * @param input - input parameter as a String
+ * @param handler - the ResponseDispatch<String> handler used to send the response message (a String in this case)
+ * Listed here for documentation purposes - this is the operation that the async server operation maps to
+ */
+// @AsyncFault( {BusinessFault1.class, BusinessFault2.class} )
+// public void operation1Async( String input, ResponseDispatch<String> handler );
+
+} // end interface Service1AsyncServer
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServerImpl.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServerImpl.java
new file mode 100644
index 0000000000..05d01dda78
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1NonAsyncServerImpl.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+public class Service1NonAsyncServerImpl implements Service1NonAsyncServer {
+
+ @Override
+ public String operation1(String input) {
+ return "Service1NonAsyncServerImpl.operation1 " + input;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java
new file mode 100644
index 0000000000..1de688dfcd
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.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 org.apache.tuscany.sca.itest;
+
+/*
+ * Exception thrown by SCA Test services
+ */
+public class TestException extends Exception {
+
+ /**
+ * Required serialVersionUID field
+ */
+ private static final long serialVersionUID = -6978058912756564824L;
+
+ public TestException() { super(); };
+
+ public TestException( String msg ) { super( msg ); };
+
+ public TestException( String msg, Throwable cause ) { super( msg, cause); };
+
+ public TestException( Throwable cause ) { super( cause ); };
+
+}
diff --git a/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java
new file mode 100644
index 0000000000..5b624d4712
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.tuscany.sca.itest;
+
+import javax.jws.WebMethod;
+import org.oasisopen.sca.annotation.Remotable;
+import org.apache.tuscany.sca.itest.TestException;
+
+
+/**
+ * Basic interface to invoke testcases
+ * 1 operation
+ * - "invokeTest", string input, string output
+ *
+ */
+@Remotable
+public interface TestInvocation {
+
+ /**
+ * Method for invoking testcase
+ * @param input - input parameter(s) as a String
+ * @return - output data as a String
+ * @throws - a TestException is thrown in cases where the test service fails internally
+ */
+ @WebMethod
+ public String invokeTest( String input ) throws TestException ;
+
+}