`
cesymm
  • 浏览: 29273 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

cxf 根据ip 探测服务

    博客分类:
  • cxf
 
阅读更多
使用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("---");
            }
        }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics