From 50fc128ff7c5750f0348e0898ff815f084d609c0 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Wed, 5 May 2021 11:23:46 +0200 Subject: [PATCH] alternative way to set timeouts for the ISLookup client --- .../dhp/utils/ISLookupClientFactory.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 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 9552eb2b3..9af390f9c 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,11 +1,11 @@ package eu.dnetlib.dhp.utils; -import java.util.Map; - -import javax.xml.ws.BindingProvider; - +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,20 +31,23 @@ public class ISLookupClientFactory { final T service = (T) jaxWsProxyFactory.create(); - if (service instanceof BindingProvider) { + Client client = ClientProxy.getClient(service); + if (client != null) { + HTTPConduit conduit = (HTTPConduit) client.getConduit(); + HTTPClientPolicy policy = new HTTPClientPolicy(); + log .info( - "setting timeouts for {} to requestTimeout: {}, connectTimeout: {}", - BindingProvider.class.getName(), requestTimeout, connectTimeout); + String + .format( + "setting connectTimeout to %s, requestTimeout to %s for service %s", + connectTimeout, + requestTimeout, + clazz.getCanonicalName())); - 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); + policy.setConnectionTimeout(connectTimeout); + policy.setReceiveTimeout(requestTimeout); + conduit.setClient(policy); } return service;