summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-09-28 08:11:20 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-09-28 08:11:20 +0000
commitc7429b610632c552ccb18fe74b2ba7e6f5043225 (patch)
tree48fdb2d49e4aa53f5c5eaba51018a3711bb00439 /sca-java-2.x/trunk/modules
parentde91701577fc25ac7ec7b87b7a46d4011fb2b676 (diff)
TUSCANY-3954: Apply patch from Greg Dritschler to Change AsyncJDKInvocationHandler to not use AsyncFaultWrapper
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1176776 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java24
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java35
2 files changed, 27 insertions, 32 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
index f8f393d040..2d54965947 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
@@ -58,7 +58,7 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
private String uniqueID = UUID.randomUUID().toString();
- private ClassLoader classLoader = null;
+ private Class businessInterface = null;
private AsyncHandler callback;
protected AsyncInvocationFutureImpl() {
@@ -73,9 +73,9 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
* @param classLoader - the classloader used for the business interface to which this Future applies
* @return - an instance of AsyncInvocationFutureImpl<V>
*/
- public static <V> AsyncInvocationFutureImpl<V> newInstance( Class<V> type, ClassLoader classLoader ) {
+ public static <V> AsyncInvocationFutureImpl<V> newInstance( Class<V> type, Class businessInterface ) {
AsyncInvocationFutureImpl<V> future = new AsyncInvocationFutureImpl<V>();
- future.setClassLoader( classLoader );
+ future.setBusinessInterface( businessInterface );
return future;
}
@@ -179,7 +179,7 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
Throwable e;
try {
// Set the TCCL to the classloader of the business interface
- Thread.currentThread().setContextClassLoader(this.getClassLoader());
+ Thread.currentThread().setContextClassLoader(this.getBusinessInterface().getClassLoader());
e = w.retrieveFault();
} finally {
Thread.currentThread().setContextClassLoader(tccl);
@@ -237,24 +237,24 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
}
/**
- * Gets the classloader associated with the business interface to which this Future relates
- * @return the ClassLoader of the business interface
+ * Gets the business interface to which this Future relates
+ * @return the business interface
*/
- public ClassLoader getClassLoader() {
- return classLoader;
+ public Class getBusinessInterface() {
+ return businessInterface;
}
/**
- * Sets the classloader associated with the business interface to which this Future relates
+ * Sets the business interface to which this Future relates
* @param classLoader - the classloader of the business interface
*/
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
+ public void setBusinessInterface(Class businessInterface) {
+ this.businessInterface = businessInterface;
}
/**
* Sets the callback handler, when the client uses the async callback method
- * @param classLoader - the classloader of the business interface
+ * @param callback - the client's callback object
*/
public void setCallback(AsyncHandler callback) {
this.callback = callback;
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
index e37fa7754a..89388fa9af 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
@@ -194,19 +194,20 @@ public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
Method method = getNonAsyncMethod(asyncMethod);
Class<?> returnType = method.getReturnType();
// Allocate the Future<?> / Response<?> object - note: Response<?> is a subclass of Future<?>
- AsyncInvocationFutureImpl future = AsyncInvocationFutureImpl.newInstance(returnType, getInterfaceClassloader());
+ AsyncInvocationFutureImpl future = AsyncInvocationFutureImpl.newInstance(returnType, businessInterface);
if (callback != null)
future.setCallback(callback);
try {
invokeAsync(proxy, method, args, future, asyncMethod);
- } catch (Exception e) {
- future.setWrappedFault(new AsyncFaultWrapper(e));
} catch (Throwable t) {
- Exception e =
- new ServiceRuntimeException("Received Throwable: " + t.getClass().getName()
- + " when invoking: "
- + asyncMethod.getName(), t);
- future.setWrappedFault(new AsyncFaultWrapper(e));
+ // invokeAsync schedules a separate Runnable to run the request. Any exception caught here
+ // is a runtime exception, not an application exception.
+ if (!(t instanceof ServiceRuntimeException)) {
+ t = new ServiceRuntimeException("Received Throwable: " + t.getClass().getName()
+ + " when invoking: "
+ + asyncMethod.getName(), t);
+ }
+ future.setFault(t);
} // end try
return future;
} // end method doInvokeAsyncPoll
@@ -220,7 +221,7 @@ public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
// Target service is asynchronous
Class<?> returnType = method.getReturnType();
AsyncInvocationFutureImpl future =
- AsyncInvocationFutureImpl.newInstance(returnType, getInterfaceClassloader());
+ AsyncInvocationFutureImpl.newInstance(returnType, businessInterface);
invokeAsync(proxy, method, args, future, method);
// Wait for some maximum time for the result - 120 seconds here
// Really, if the service is async, the client should use async client methods to invoke the service
@@ -403,11 +404,11 @@ public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
if ("AsyncResponse".equals(e.getMessage())) {
// Do nothing...
} else {
- future.setWrappedFault(new AsyncFaultWrapper(s));
+ future.setFault(s);
} // end if
} // end if
else {
- future.setWrappedFault(new AsyncFaultWrapper(s));
+ future.setFault(s);
}
} catch (AsyncResponseException ar) {
// This exception is received in the case where the Binding does not support async invocation
@@ -415,7 +416,9 @@ public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
// indicate that the service received the request but will send the response separately - do nothing
} catch (Throwable t) {
//System.out.println("Async invoke got exception: " + t.toString());
- future.setWrappedFault(new AsyncFaultWrapper(t));
+ // If we invoked a sync service, this might be an application exception.
+ // The databinding ensured the exception is type-compatible with the application.
+ future.setFault(t);
} // end try
} // end method run
@@ -734,12 +737,4 @@ public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
}
throw new IllegalStateException("No synchronous method matching async method " + asyncMethod.getName());
} // end method getNonAsyncMethod
-
- /**
- * Gets the classloader of the business interface
- * @return
- */
- private ClassLoader getInterfaceClassloader() {
- return businessInterface.getClassLoader();
- }
}