WS-DISCOVERY使用

最近项目中要用到探测webservice服务端的信息,在网上查询后了解到apache cxf提供了这部分功能,支持包在附件中。

具体使用如下:

将支持包放到webservice服务项目lib目录下,提供udp探测功能。

客户端探测实现代码:

 

public class WsClientDiscovery {
    public static void main(String[] args) {
        Bus bus = null;
        try {
            bus = BusFactory.newInstance().createBus();

            WSDiscoveryClient client = new WSDiscoveryClient(bus);
            client.setAddress("soap.udp://192.168.0.143:3702");  //服务端地址和udp端口地址
            ProbeType pt = new ProbeType();
            ScopesType scopes = new ScopesType();
            pt.setScopes(scopes);
            ProbeMatchesType pmts = client.probe(pt);
            List<ResolveMatchType> rmts = new LinkedList<ResolveMatchType>();
            for (ProbeMatchType pmt : pmts.getProbeMatch()) {
                rmts.add(client.resolve(pmt.getEndpointReference()));
            }

            int i = 0;
            for (ResolveMatchType rmt : rmts) {
                i++;
                String address = rmt.getXAddrs().iterator().next();    //服务端提供服务
                QName qname = rmt.getTypes().iterator().next();
                if (qname.toString().contains("RemoteWSServer")) {
                    RemoteWSServer port = rmt.getEndpointReference().getPort(
                        RemoteWSServer.class);
                    ((BindingProvider) port).getRequestContext().put(
                        BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                        "http://192.168.0.143:8081/remote/services/remoteWSServerRemote");
                    List<String> l = port.list();
                    System.out.println(l);
                }
            }
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            bus.shutdown(true);
        }
    }

}

 

 另外,google中也有相同功能的开源项目:https://code.google.com/p/java-ws-discovery/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值