使用所需的网络适配器调用Web Service

时间:2015-10-13 08:49:39

标签: java web-services soap cxf

有没有办法强制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 个答案:

答案 0 :(得分:1)

不太确定,是否可以将Web服务客户端配置为将请求绑定到特定接口,但我认为您可以轻松地使用Host OS ip路由配置。对于Windows,您可以这样做:

route ADD 1.1.1.1 MASK 255.255.255.255 10.10.11.35

如果fooservice和10.10.11.35是网络接口的地址,则1.1.1.1是IP地址,其中将用作网关。如果您需要-p标志,可以将此路线设为永久路线。对于Linux,它可以以类似的方式完成。

相关问题