2015-10-13 148 views
2

有沒有辦法強制Apache CXF使用特定的網絡適配器?使用所需的網絡適配器撥打網絡服務

我已經使用Jax-WS生成了soap web服務代理類,並使用下面的代碼調用服務。我只想通過使用無線網絡適配器調用服務而不禁用有線以太網連接。在系統

FooService oServ = new FooWSService();    
FooWS oWs = oServ.getFooWSPort();    
String endpointURL = "https://fooservice/serviceWSPort";    
BindingProvider bindingProvider = (BindingProvider) oWs; 

Map<String, Object> requestContext = bindingProvider.getRequestContext(); 
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);    

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(oWs); 
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint(); 

String result = oWS.TestMethod(); 

Avaible網絡適配器使用

Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); 

結果:

Display name: Realtek PCIe GBE Family Controller 
Name: eth4 
InetAddress: /fe80:0:0:0:914b:ee4a:58b7:e5b3%12 
InetAddress: /10.10.10.227 

Display name: 1x1 11b/g/n Wireless LAN PCI Express Half Mini Card Adapter 
Name: net4 
InetAddress: /fe80:0:0:0:513:7a5a:d3ab:9278%13 
InetAddress: /10.10.11.35 

回答

1

不能確定,羯羊它可以配置Web服務客戶端綁定請求到特定的接口,但我認爲你可以輕鬆地使用主機操作系統IP路由配置。對於windows,你可以不喜歡它:

route ADD 1.1.1.1 MASK 255.255.255.255 10.10.11.35 

哪裏1.1.1.1是IP地址,如果FooService接口和10.10.11.35是網絡接口的地址,至極將被用作網關。如果您需要-p標誌,您可以使此路線永久。對於Linux,可以用類似的方法完成。