1

我打算将 Apache CXF 用于兼容 ONVIF 的网络摄像机服务。它使用 WS-Discovery 来查找设备和服务,并且cxf开箱即用地支持它:

cxf-services-ws-discovery-service jar 将注册一个 ServerLifecyleListener,它将自动发布“Hello”消息。它还将响应与其发布的服务匹配的任何探测请求。

cxf 如何检测设备类型以发送ProbeMatches响应?如何指定我的设备是 ip camera(例如,我需要在 ProbeMatches 响应中设置具体的设备类型NetworkVideoTransmitter)?

4

1 回答 1

0

在查看 CXF 源代码(WSDiscoveryServiceImpl类)后,我找到了答案:

public ProbeMatchesType handleProbe(ProbeType pt) {
        List<HelloType> consider = new LinkedList<HelloType>(registered);
        //step one, consider the "types"
        //ALL types in the probe must be in the registered type
        if (pt.getTypes() != null && !pt.getTypes().isEmpty()) {
            ListIterator<HelloType> cit = consider.listIterator();
            while (cit.hasNext()) {
                HelloType ht = cit.next();
                boolean matches = true;
                for (QName qn : pt.getTypes()) {
                    if (!ht.getTypes().contains(qn)) {
                        matches = false;
                    }
                }
                if (!matches) {
                    cit.remove();
                }
            }
        }
        //next, consider the scopes
        matchScopes(pt, consider);

        if (consider.isEmpty()) {
            return null;
        }
        ProbeMatchesType pmt = new ProbeMatchesType();
        for (HelloType ht : consider) {
            ProbeMatchType m = new ProbeMatchType();
            m.setEndpointReference(ht.getEndpointReference());
            m.setScopes(ht.getScopes());
            m.setMetadataVersion(ht.getMetadataVersion());
            m.getTypes().addAll(ht.getTypes());
            m.getXAddrs().addAll(ht.getXAddrs());
            pmt.getProbeMatch().add(m);
        }
        return pmt;
    }

简而言之 - 它迭代已发布的服务并比较 QName。如果在发布中找到搜索的 qname,则将其添加到ProbeMatch. 所以我应该用需要的 QName 实现和发布服务来修复它。

于 2014-12-03T10:52:53.963 回答