From 93052ae38453901f8190607d12c84c9d5affc053 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Thu, 25 Jun 2020 16:16:02 +0200 Subject: [PATCH] WIP: set the connect & request timeout for BindingProvider service implementation --- .../dhp/utils/ISLookupClientFactory.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java index 97fe4b9d8..9552eb2b3 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/ISLookupClientFactory.java @@ -1,15 +1,22 @@ package eu.dnetlib.dhp.utils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.util.Map; + +import javax.xml.ws.BindingProvider; + import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; public class ISLookupClientFactory { - private static final Log log = LogFactory.getLog(ISLookupClientFactory.class); + private static final Logger log = LoggerFactory.getLogger(ISLookupClientFactory.class); + + private static int requestTimeout = 60000 * 10; + private static int connectTimeout = 60000 * 10; public static ISLookUpService getLookUpService(final String isLookupUrl) { return getServiceStub(ISLookUpService.class, isLookupUrl); @@ -21,6 +28,25 @@ public class ISLookupClientFactory { final JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); jaxWsProxyFactory.setServiceClass(clazz); jaxWsProxyFactory.setAddress(endpoint); - return (T) jaxWsProxyFactory.create(); + + final T service = (T) jaxWsProxyFactory.create(); + + if (service instanceof BindingProvider) { + log + .info( + "setting timeouts for {} to requestTimeout: {}, connectTimeout: {}", + BindingProvider.class.getName(), requestTimeout, connectTimeout); + + Map requestContext = ((BindingProvider) service).getRequestContext(); + + requestContext.put("com.sun.xml.internal.ws.request.timeout", requestTimeout); + requestContext.put("com.sun.xml.internal.ws.connect.timeout", connectTimeout); + requestContext.put("com.sun.xml.ws.request.timeout", requestTimeout); + requestContext.put("com.sun.xml.ws.connect.timeout", connectTimeout); + requestContext.put("javax.xml.ws.client.receiveTimeout", requestTimeout); + requestContext.put("javax.xml.ws.client.connectionTimeout", connectTimeout); + } + + return service; } }