You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/03/19 20:07:12 UTC
[3/5] git commit: Add ability to set the synch timeout via a
contextual property
Add ability to set the synch timeout via a contextual property
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/560d32e2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/560d32e2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/560d32e2
Branch: refs/heads/2.7.x-fixes
Commit: 560d32e278505d179dac73445379de946d37a56a
Parents: ca3bb54
Author: Daniel Kulp <dk...@apache.org>
Authored: Wed Mar 19 13:58:18 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Wed Mar 19 14:52:54 2014 -0400
----------------------------------------------------------------------
.../org/apache/cxf/endpoint/ClientImpl.java | 52 ++++++++++++--------
1 file changed, 31 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/560d32e2/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java b/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
index 77522fb..70b324e 100644
--- a/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
+++ b/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
@@ -47,6 +47,7 @@ import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
import org.apache.cxf.common.i18n.UncheckedException;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
import org.apache.cxf.interceptor.ClientOutFaultObserver;
@@ -81,7 +82,11 @@ public class ClientImpl
implements Client, Retryable, MessageObserver {
public static final String THREAD_LOCAL_REQUEST_CONTEXT = "thread.local.request.context";
-
+ /**
+ * When a synchronous request/response invoke is done using an asynchronous transport mechanism,
+ * this is the timeout used for waiting for the response. Default is 60 seconds.
+ */
+ public static final String SYNC_TIMEOUT = "cxf.synchronous.timeout";
public static final String FINISHED = "exchange.finished";
@@ -651,9 +656,7 @@ public class ClientImpl
// Wait for a response if we need to
if (oi != null && !oi.getOperationInfo().isOneWay()) {
- synchronized (exchange) {
- waitResponse(exchange);
- }
+ waitResponse(exchange);
}
// leave the input stream open for the caller
@@ -709,24 +712,31 @@ public class ClientImpl
}
protected void waitResponse(Exchange exchange) throws IOException {
- int remaining = synchronousTimeout;
- while (!Boolean.TRUE.equals(exchange.get(FINISHED)) && remaining > 0) {
- long start = System.currentTimeMillis();
- try {
- exchange.wait(remaining);
- } catch (InterruptedException ex) {
- // ignore
+ synchronized (exchange) {
+ long remaining = synchronousTimeout;
+ Long o = PropertyUtils.getLong(exchange.getOutMessage(), SYNC_TIMEOUT);
+ if (o != null) {
+ remaining = o;
+ }
+ while (!Boolean.TRUE.equals(exchange.get(FINISHED)) && remaining > 0) {
+ long start = System.currentTimeMillis();
+ try {
+ exchange.wait(remaining);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ long end = System.currentTimeMillis();
+ remaining -= (int)(end - start);
+ }
+ if (!Boolean.TRUE.equals(exchange.get(FINISHED))) {
+ LogUtils.log(LOG, Level.WARNING, "RESPONSE_TIMEOUT",
+ exchange.get(OperationInfo.class).getName().toString());
+ String msg = new org.apache.cxf.common.i18n.Message("RESPONSE_TIMEOUT", LOG,
+ exchange.get(OperationInfo.class)
+ .getName().toString())
+ .toString();
+ throw new IOException(msg);
}
- long end = System.currentTimeMillis();
- remaining -= (int)(end - start);
- }
- if (!Boolean.TRUE.equals(exchange.get(FINISHED))) {
- LogUtils.log(LOG, Level.WARNING, "RESPONSE_TIMEOUT",
- exchange.get(OperationInfo.class).getName().toString());
- String msg = new org.apache.cxf.common.i18n.Message("RESPONSE_TIMEOUT", LOG,
- exchange.get(OperationInfo.class).getName().toString())
- .toString();
- throw new IOException(msg);
}
}