cxf 根据ip 探测服务

使用cxf自带的API获取多播获取服务时,获取不到。
换成google的可以通过多播发现服务

// Uncomment the following to override the IP this server will announce itself at
// if proxy mode is enabled. This IP is only used if server.enableProxyMode() is called.
// WsDiscoveryConstants.proxyAddress = InetAddress.getByName("10.0.1.3");
// Uncomment the following to bind multicasts to a specific interface
// WsDiscoveryConstants.multicastInterface = NetworkInterface.getByInetAddress(InetAddress.getByName("10.0.1.4"));

// Create a new server instance
WsDiscoveryServer server = WsDiscoveryBuilder.createServer();

// Start background threads
server.start();

System.out.println("Sending probe...");

// Send Probe-message.
server.probe();

// All listening WS-Discovery instances should respond to a blank probe.
// The background server will receive the replies and store the
// discovered services in a service directory.

System.out.println("Waiting for replies. (2 sec)");
Thread.sleep(2000);

// Check if any of the discovered services are missing XAddrs (invocation address).
// If they are, try to resolve it.
{
// Get a copy of the remote service directory
IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();
boolean resolve_sent = false;

for (WsDiscoveryService service : result)
// Is XAddrs empty?
if (service.getXAddrs().size() == 0) {
// Send Resolve-message
System.out.println("Trying to resolve XAddr for service " +service.getEndpointReference());
server.resolve(service);
resolve_sent = true;
}

if (resolve_sent) {
System.out.println("Waiting for ResolveMatches. (2 sec)");
Thread.sleep(2000);
}
}

// Get a copy of the remote service directory and display the results.
{
System.out.println("** Discovered services: **");

IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();

for (WsDiscoveryService service : result) {
// Print service info
System.out.println(ToStringBuilder.reflectionToString(service,ToStringStyle.MULTI_LINE_STYLE));

System.out.println("---");
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值