From a4c7fdc0ab7957cc305839fc47e5fe5f15122c61 Mon Sep 17 00:00:00 2001 From: Guillaume Turri Date: Sat, 14 Dec 2024 22:23:15 +0100 Subject: [PATCH 1/2] Separate connectTimeout and readTimeout this fixes part of #147 --- .../java/de/timroes/axmlrpc/XMLRPCClient.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java index efcf0f4..12b1921 100644 --- a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java +++ b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java @@ -196,7 +196,8 @@ public class XMLRPCClient { private Proxy proxy; - private int timeout; + private int connectTimeout; + private int readTimeout; private final SerializerHandler serializerHandler; /** @@ -296,7 +297,7 @@ public URL getURL() { } /** - * Sets the time in seconds after which a call should timeout. + * Set both the connect timeout and the read timeout. * If {@code timeout} will be zero or less the connection will never timeout. * In case the connection times out an {@link XMLRPCTimeoutException} will * be thrown for calls made by {@link #call(java.lang.String, java.lang.Object[])}. @@ -307,7 +308,16 @@ public URL getURL() { * @param timeout The timeout for connections in seconds. */ public void setTimeout(int timeout) { - this.timeout = timeout; + this.connectTimeout = timeout; + this.readTimeout = timeout; + } + + public void setConnectTimeout(int timeout) { + this.connectTimeout = timeout; + } + + public void setReadTimeout(int timeout) { + this.readTimeout = timeout; } /** @@ -647,9 +657,11 @@ public Object call(String methodName, Object[] params) throws XMLRPCException { http.setDoInput(true); // Set timeout - if(timeout > 0) { - http.setConnectTimeout(timeout * 1000); - http.setReadTimeout(timeout * 1000); + if(connectTimeout > 0) { + http.setConnectTimeout(connectTimeout * 1000); + } + if (readTimeout > 0) { + http.setReadTimeout(readTimeout * 1000); } // Set the request parameters From a04fb5afee44a5c60c4b2b4fe5d502e4ec730d39 Mon Sep 17 00:00:00 2001 From: Guillaume Turri Date: Sat, 14 Dec 2024 22:27:12 +0100 Subject: [PATCH 2/2] Can override timeout per query This fixes #147 --- src/main/java/de/timroes/axmlrpc/XMLRPCClient.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java index 12b1921..f3e39a7 100644 --- a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java +++ b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java @@ -638,7 +638,10 @@ public void cancel() { * @throws XMLRPCException Will be thrown if an error occurred during the call. */ public Object call(String methodName, Object[] params) throws XMLRPCException { + return callWithOverridenTimeout(methodName, connectTimeout, readTimeout, params); + } + public Object callWithOverridenTimeout(String methodName, int connectTimeout, int readTimeout, Object[] params) throws XMLRPCException { try { Call c = createCall(methodName, params);