alternative way to set timeouts for the ISLookup client

This commit is contained in:
Claudio Atzori 2021-05-05 11:23:46 +02:00
parent 1adfc41d23
commit 50fc128ff7
1 changed files with 18 additions and 15 deletions

View File

@ -1,11 +1,11 @@
package eu.dnetlib.dhp.utils; package eu.dnetlib.dhp.utils;
import java.util.Map; import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,20 +31,23 @@ public class ISLookupClientFactory {
final T service = (T) jaxWsProxyFactory.create(); 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 log
.info( .info(
"setting timeouts for {} to requestTimeout: {}, connectTimeout: {}", String
BindingProvider.class.getName(), requestTimeout, connectTimeout); .format(
"setting connectTimeout to %s, requestTimeout to %s for service %s",
connectTimeout,
requestTimeout,
clazz.getCanonicalName()));
Map<String, Object> requestContext = ((BindingProvider) service).getRequestContext(); policy.setConnectionTimeout(connectTimeout);
policy.setReceiveTimeout(requestTimeout);
requestContext.put("com.sun.xml.internal.ws.request.timeout", requestTimeout); conduit.setClient(policy);
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; return service;