eXtreme Development

Java - definir timeout no Apache CXF client

package org.ow2.petals.kernel.ws.client;

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.ow2.petals.kernel.ws.api.RuntimeService;

public class Main {

	private void createService() {
		// set time to wait for response in milliseconds. zero means unlimited
		long timeout = 10000L;
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(RuntimeService.class);
		factory.setAddress("http://localhost:9999/service/Runtime");
		RuntimeService runtimeService = (RuntimeService) factory.create();

		Client client = ClientProxy.getClient(runtimeService);
		if (client != null) {
			HTTPConduit conduit = (HTTPConduit) client.getConduit();
			HTTPClientPolicy policy = new HTTPClientPolicy();
			policy.setConnectionTimeout(timeout);
			policy.setReceiveTimeout(timeout);
			conduit.setClient(policy);
		}
	}
}

Referencias

https://chamerling.wordpress.com/2009/09/23/setting-timeout-on-generated-jaxws-cxf-clients/ http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html http://webapplicationdeveloper.blogspot.com.br/2013/10/setting-timeout-on-apache-cxf.html



SourceForge BootStrap