我正在尝试配置CXF总线,并为所有客户端设置通用超时。为此,我正在使用HttpConduitFeature并将其在初始配置期间添加到总线中,如下所示:
@Configuration
public class CxfContext {
@Autowired
private SoapConfigurations soapConfigurations;
@Bean
public Bus bus() {
SpringBus b = new SpringBus();
List<Feature> features = ImmutableList.<Feature> builder() //
.add(loggingFeature()) //
.add(conduitFeature()) //
.build();
b.setFeatures(features);
return b;
}
private LoggingFeature loggingFeature() {
LoggingFeature f = new LoggingFeature();
f.setPrettyLogging(true);
f.setVerbose(true);
f.setLimit(-1);
return f;
}
private HttpConduitFeature conduitFeature() {
HttpConduitFeature feature = new HttpConduitFeature();
HttpConduitConfig conduitConfig = new HttpConduitConfig();
HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
clientPolicy.setConnectionTimeout(10000);
clientPolicy.setReceiveTimeout(10000);
conduitConfig.setClientPolicy(clientPolicy);
feature.setConduitConfig(conduitConfig);
return feature;
}
}
之后,在生成Soap客户端时,我正在使用JaxWsProxyFactoryBean并将总线设置为它:
@Configuration
public class SoapClientContext {
@Autowired
private Bus bus;
@Bean
public IService myService(SoapConfigurations soapConfigurations) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(soapConfigurations.getUrl());
factory.setBus(bus);
return factory.create(IService.class);
}
}
客户端正确使用了总线中配置的日志记录功能,但是未考虑HttpConduitFeature。因此,超时默认为1分钟,而不是配置的10秒。
我现在看到的唯一解决方案是直接在工厂设置HttpConduitFeature:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(soapConfigurations.getUrl());
factory.setBus(bus);
factory.getFeatures().add(conduitFeature());
我是否需要一些其他配置,以便生成的客户端直接使用总线中定义的HttpConduitFeature?