本文介绍了使用Apache CXF进行WS-Discovery.如何指定设备类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用Apache CXF来支持与ONVIF兼容的IP摄像机服务.它使用WS-Discovery查找设备和服务,并且 cxf支持 -box:

I'm going to use Apache CXF for ONVIF-compatible ip camera service. It uses WS-Discovery to find devices and services and cxf supports it out-of-box:

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

How will cxf detect device type to send in ProbeMatches response? How can i specify that my device is ip camera (i need to set concrete device type in ProbeMatches response, NetworkVideoTransmitter for example)?

推荐答案

研究了CXF源代码(WSDiscoveryServiceImpl类)后,我找到了答案:

After looking into CXF source code (WSDiscoveryServiceImpl class) i've found the answer:

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实施并发布服务以对其进行修复.

In brief - it iterates published services and compares QNames. If searched qname is found in published it's added into ProbeMatch. So i should implement and publish service with needed QName to fix it.

这篇关于使用Apache CXF进行WS-Discovery.如何指定设备类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:28