Cxf Client URL and Timeout via Java Configuration
soap_19127_md.gif

This example below shows how to configure a cxf clients time-out and endpoint url via java :

private static final String MY_CLIENT_SERVICE_URL = "http://clientUrl";
 
public final static QName SERVICE = new QName("http://www.mycompany.com",
            "MY_CLIENTService");
 
    private static final long TIME_OUT = 60000;
 
    private MyClient getService() {
        try {
            URL wsdlURL = null;
            try {
                ClassPathResource wsdlResource = ........
                wsdlURL = wsdlResource.getURL();
            } catch (IOException ex) {
                F16Logger.Error().append(ex).sendQuietly();
                throw ex;
            }
 
            ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
 
            factory.setServiceClass(MY_CLIENTService.class);
            factory.setServiceName(SERVICE);
            factory.setAddress(MY_CLIENT_SERVICE_URL);
            factory.setWsdlLocation(wsdlURL.toString());
            MY_CLIENTService client = (MY_CLIENTService) factory.create();
            final Client cl = ClientProxy.getClient(client);
 
            final HTTPConduit http = (HTTPConduit) cl.getConduit();
            cl.getInInterceptors().add(new LoggingInInterceptor());
            cl.getOutInterceptors().add(new LoggingOutInterceptor());
 
            final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
 
            httpClientPolicy.setReceiveTimeout(TIME_OUT);
            httpClientPolicy.setAllowChunking(false);
            httpClientPolicy.setConnectionTimeout(TIME_OUT);
 
            http.setClient(httpClientPolicy);
 
            return client;
        } catch (Exception e) {
            e.printStackTrace();          
            return null;
        }
    }
 
 }
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License