我有一个cxf JAX-WS客户端。我添加了故障转移策略。问题是客户端如何从备份解决方案中恢复并再次使用主URL?因为现在客户端将切换到辅助URL后,即使再次可用,也不会使用主URL。
客户端部分的代码是:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(GatewayPort.class);
factory.setAddress(this.configFile.getPrimaryURL());
FailoverFeature feature = new FailoverFeature();
SequentialStrategy strategy = new SequentialStrategy();
List<String> addList = new ArrayList<String>();
addList.add(this.configFile.getSecondaryURL());
strategy.setAlternateAddresses(addList);
feature.setStrategy(strategy);
List<AbstractFeature> features = new ArrayList<AbstractFeature>();
features.add(feature);
factory.setFeatures(features);
this.serviceSoap = (GatewayPort)factory.create();
Client client = ClientProxy.getClient(this.serviceSoap);
if (client != null)
{
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(this.configFile.getTimeout());
policy.setReceiveTimeout(this.configFile.getTimeout());
conduit.setClient(policy);
}
答案 0 :(得分:4)
您可以将主URL添加到备用地址列表,而不是将其设置为JaxWsProxyFactoryBean。这样,由于您使用的是SequentialStrategy,因此每次服务调用都会首先检查主URL,如果失败,则会尝试使用secodary URL。
答案 1 :(得分:0)
您还可以尝试使用故障恢复的替代CXF故障转移功能。