2012-10-04 158 views
3

我有一个cxf JAX-WS客户端。我添加了故障转移策略。问题是客户端如何从备份解决方案中恢复并再次使用主URL?因为现在在客户端切换到辅助URL之后,即使再次可用,也不会使用主URL。cxf故障转移恢复

为客户端部分中的代码是:

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); 
} 

回答

4

可在主URL添加到备用地址列表,而不是设置,要JaxWsProxyFactoryBean的。这样,由于您正在使用SequentialStrategy,因此每次服务调用都会首先检查主URL,如果失败,则会尝试使用secodary URL。

+0

在年底选择其他的办法:自定义机制将数据发送到辅助URL。例如:尝试2次发送到第一个URL,如果发送到第二个URL失败。 (由于来自URL提供者的新信息的业务模型更改,添加了此方法) – adimoldovan