- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过一些Java代码来发现ONVIF设备。具体来说,我正在尝试获取他们的设备服务地址(我相信这只是他们的IP地址?),如ONVIF Core Spec指出的(在第4.3节中):“成功的发现将提供设备服务地址。设备服务地址,它可以通过设备服务接收详细的设备信息...”。我的目标是最终获得网络上ONVIF设备的详细信息。总的来说,我也在寻找有关使用ONVIF规范的指南。
我仍然对Web服务世界(以及一般而言的网络)还是陌生的,所以请原谅我。但是,我本人为此付出了很多努力:我读了很多ONVIF Core Spec,ONVIF Application Programmer's Guide和WS-Discovery Specification。如果可以的话,我将总结一下我所知道的,以便您可以告诉我我是否走在正确的轨道上:
“ Web服务”是使用平台和语言无关的Web服务标准(例如,通过IP网络的XML,SOAP和WSDL)的标准技术的名称。基本思想是我们希望能够从任何编程语言中调用有效的方法/函数(服务)。
Web服务通常托管在服务器上。但是在ONVIF用例中,Web服务提供商是ONVIF设备(例如IP摄像机)。因此,为了以任何语言与设备进行交互,我们可以使用Web服务操作/调用,因为Web服务调用可以以任何语言实现。
XML是数据描述语法(之所以使用,是因为它与语言无关;任何语言都可以解析它)。 SOAP是用于来回获取注入SOAP的XML文档的通信协议(基本上是进行我们的方法调用)。 WSDL用于描述服务(它是Web服务接口的基于XML的描述)。我已经下载了用于设备管理的WSDL here,并通过WSDL编译器wsimport
(由JDK提供)从WSDL中生成了Java类,以便在我的代码中使用。但我知道调用这些方法将在设备发现之后进行,对吗?
根据WS-Discovery规范发现了ONVIF设备。您发送Probe
消息,并且符合探针约束的设备会发回ProbeMatch
消息,如第13和14页in ONVIF Application Programmers Guide所述。
这是我开始感到困惑的地方。我如何用Java发送此消息? 《 ONVIF应用程序程序员指南》在第15页上提供了一些伪代码,但我不知道如何实现它。该指南明确指出了该指南中的4.3.1节。我知道“作用域”和“类型”只是您可以嵌入探针中的约束,但不是必需的(根据WS discovery spec的第5页)。因为我想发现所有设备,所以我认为启动不需要任何限制,对吗?
因此,该指南还在第110页上提供了用于发现的示例SOAP消息。从中删除类型声明(因为我不想使用该约束),我知道要发送的SOAP消息将是(我相信吗?):
<?xml version="1.0" encoding="UTF-8"?>
<e:Envelope xmlns:e="http://www.w3.org/2003/05/soap-envelope"
xmlns:w="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"
xmlns:dn="http://www.onvif.org/ver10/network/wsdl">
<e:Header>
<w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID>
<w:To e:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To>
<w:Action
a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/Pr
obe</w:Action>
</e:Header>
<e:Body>
<d:Probe>
</d:Probe>
</e:Body>
</e:Envelope>
XAddrs
,但不确定) 。我是否需要以某种方式将该SOAP消息的UDP广播发送到该地址?
最佳答案
经过反复试验,我找到了另一个解决方案。在大多数情况下,mpromonet可能是可行的方式,我只是想避免使用像Apache这样的大型依赖项。我还认为,仅使用一些简单的UDP消息传递就应该可行。
该解决方案还基于SO用户Thomas的有用代码here。我基本上只是通过删除线程来简化他的代码,并添加了一些注释。同样,他的解决方案可能比我的解决方案(表现更好)更好。但是,我的初学者(例如我)可能更容易理解。
这是代码:
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.*;
import javax.xml.namespace.QName;
import javax.xml.soap.*;
import java.util.*;
public class ONVIFDeviceDiscoveryFIN {
// Following constants are related to Discovery process
public static final int WS_DISCOVERY_TIMEOUT = 4000; // 4 seconds. Time to wait to receive a packet
public static final int WS_DISCOVERY_PORT = 3702;
public static final String WS_DISCOVERY_ADDRESS_IPv4 = "239.255.255.250";
// note that the probe below MUST be given a unique urn:uuid. Devices will NOT reply if the urn:uuid is not unique!
public static final String WS_DISCOVERY_PROBE_MESSAGE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tds=\"http://www.onvif.org/ver10/device/wsdl\" xmlns:tns=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">\r\n" +
" <soap:Header>\r\n" +
" <wsa:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</wsa:Action>\r\n" +
" <wsa:MessageID>urn:uuid:5e1cec36-03b9-4d8b-9624-0c5283982a00</wsa:MessageID>\r\n" +
" <wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\r\n" +
" </soap:Header>\r\n" +
" <soap:Body>\r\n" +
" <tns:Probe>\r\n" +
" <tns:Types>tds:Device</tns:Types>\r\n" + // Constraint to find just ONVIF devices hopefully? Recall we are sending a probe on the 192.168.0.50 network; if we have no constraints, it would find everything there! WS-Discovery generally is for much more than ONVIF, like printers and stuff
" </tns:Probe>\r\n" +
" </soap:Body>\r\n" +
"</soap:Envelope>";
private static ArrayList<String> getResponsesToProbe(String uuid) throws IOException{
// TODO: add in ability to send scope and type constraints
// NOTE: We do need to know the address of the network interface to discover devices on...
// Function composes and sends a Probe to discover devices on the network. uuid is the urn:uuid to put in the probe. Functions returns all the SOAP-Infused XML responses (all the ProbeMatches).
// give the probe a unique urn:uuid (we must do this for each probe!). This is generated outside function
final String probe = WS_DISCOVERY_PROBE_MESSAGE.replaceAll("<wsa:MessageID>urn:uuid:.*</wsa:MessageID>", "<wsa:MessageID>urn:uuid:" + uuid + "</wsa:MessageID>");
// set up the "sender and receiver"; this is the socket that we send our probe from, and where we receive back the ProbeMatch responses.
// NOTE: that we do need to know the address of the network interface to discover devices on... (port could be anything)
final int port = 55000;
DatagramSocket senderAndReceiver = new DatagramSocket(port, InetAddress.getByName("192.168.0.50")); // so you do need to know the address of your network interface to discover devices on...
senderAndReceiver.setSoTimeout(WS_DISCOVERY_TIMEOUT);
// send the probe
DatagramPacket probeMsg = new DatagramPacket(probe.getBytes(), probe.length(), InetAddress.getByName(WS_DISCOVERY_ADDRESS_IPv4), WS_DISCOVERY_PORT);
senderAndReceiver.send(probeMsg);
// read in the responses
ArrayList<String> responses = new ArrayList(); // this is the collection of all SOAP-infused XML ProbeMatch responses
byte[] receiverBuffer = new byte[8192];
DatagramPacket receiverPacket = new DatagramPacket(receiverBuffer, receiverBuffer.length); // this is the packet that receive the response in. Get's updated with the next response on each call to .receive()
while (true) {
try {
senderAndReceiver.receive(receiverPacket);
responses.add(new String(receiverPacket.getData()));
} catch (SocketTimeoutException e) {
// System.out.println("Socket read timeout; taken to mean that there is no more responses -- i.e., no more Probe Matches");
break;
}
}
// close the socket
senderAndReceiver.close();
return responses;
}
public static void main(String[] args) throws IOException, SOAPException {
final String uuid = UUID.randomUUID().toString(); // generate the uuid to add to the Probe message
ArrayList<String> responses = getResponsesToProbe(uuid); // responses is a collection of all the SOAP-infused XML ProbeMatches . It's all of our responses to the probe; it's basically the devices we've discovered!
}
}
arp -a
命令(不确定在Mac或Linux上如何执行此操作),然后找到相机的IP。它所属的接口是您要用作“ 192.168.0.50”的接口。以我的有限理解,这些接口基本上可以分割您的网络,因此您需要选择合适的接口来查找设备。我认为(?)Thomas的代码通过找到所有这些网络接口避免了这个问题,这是在
his code中的第81-100行中完成的。
WS_DISCOVERY_PROBE_MESSAGE
中)中使用了硬编码的UUID进行了测试。这将一次发现设备;但是之后,如果您发送具有相同UUID的探测,则设备似乎根本不会回复。您也不会收到任何错误响应,因此为什么我很难找出答案。就像设备保留了所有收到的所有探针的UUID的内部日志一样。如果您发送带有旧UUID的探测,它只会拒绝它。至少,对于我正在测试的符合ONVIF的相机(AXIS M3045-V),情况就是如此。我不确定ONVIF规范是否需要此行为,但是至少在AXIS M3045-V中是明显的。
关于java - 如何使用WS-Discovery规范在Java中发现网络上的ONVIF设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56379926/
我刚刚去了 Bluemix,看到有一个名为 Discovery 的新实验服务。显然,它可以提取 PDF、Word 文档和 HTML 页面以及其他文件类型。 该服务与文档转换 (DC) 有何区别?以前,
我刚刚去了 Bluemix,看到有一个名为 Discovery 的新实验服务。显然,它可以提取 PDF、Word 文档和 HTML 页面以及其他文件类型。 该服务与文档转换 (DC) 有何区别?以前,
Closed. This question is off-topic。它当前不接受答案。 想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。 已关闭8
我试图让 usart 在我的 stm32f0-discovery 上工作,但现在我发现关于这个的文档有点“缺乏”,所以有没有人有任何 usart 为 stm32f050 工作的例子? 谢谢。 巴特特尼
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
如果我能在我的项目中实现长按和短按按钮,它会派上用场。我正在使用 STM32F4 探索套件并在 C 中对其进行编程。我准备了一个引脚作为外部输入,我修改了中断处理程序。 架构: 我暂时将其设置为在下降
我让 Prometheus 在 AWS 上的 K8 中运行,并使用服务发现来获取有关我的基础设施的信息。 我已经能够使用服务发现来检索指标和节点的目标标签,但是我显示的是 0/17 个事件目标 pod
我让 Prometheus 在 AWS 上的 K8 中运行,并使用服务发现来获取有关我的基础设施的信息。 我已经能够使用服务发现来检索指标和节点的目标标签,但是我显示的是 0/17 个事件目标 pod
在 CloudFoundry 中,您可以通过在发现服务中注册其他微服务并按其名称查询它们来访问它们。但是您也可以设置一个路由(“子域”),您可以从中调用该服务,这似乎更容易处理。在这两种情况下都可以使
我是 Stack Exchange 社区的新手。我正在尝试在两个线程之间共享字符串的值。部分代码如下所示。 waveplayer.c 和 main.c 的内容均声明为线程。并且字符串buffer1需要
我是 Android 编程的新手。我想制作一个包含蓝牙发现功能的库(一个 JAR 文件)。 既然是库,里面的方法应该是顺序方法(启动蓝牙发现,等待一段时间,返回结果)。 我在下面做了一个代码,但它不起
我将 elastichsearch 部署到我的 AWS EKS 以进行日志记录,使用 stable/elasticsearch 图表,使用以下命令: helm install stable/elast
我最近购买了一个 STM32 Value line 探索套件,用于与 STM32 设备配合使用。我现在正在做一个需要看门狗的项目。在STM32中称为IWDG。但我的问题是当触发看门狗时我需要一个 IS
在下面的代码中,我可以看到定时器工作正常,因为 LED 一直在闪烁。但是 count 变量的值在第二个 while 内永远不会改变。 我不知道可能会出现什么问题? // count variable
在 IAR 编译器上开发 STM32L151xx。 我正在尝试获取 EXTI 中断但无处可去,这是我的代码,它基本上直接来自示例代码但无法正常工作, EXTI_InitTypeDef EXTI_I
我刚刚在 Apple 的网站上发现了 Widget Builder [ https://widgets.itunes.apple.com/builder/]我正在尝试在我雇主的网站上实现它。它基本上是
前言 在之前的 Laravel 版本中,安装包通常需要几个步骤,例如添加服务提供器到 app 配置文件并注册相关的 facades。现在,从 Laravel 5.5 开始,Laravel 可以自动
这个服务现在用到是非常少的,小编建议大家改为手动使用,这样当我们需要使用它的时候也能使用它,如果你电脑发现这个服务对应的svchost.exe进程使用的CPU非常,可以关闭它,但是不建议直接永久禁用
本文整理了Java中com.netflix.discovery.converters.XmlXStream类的一些代码示例,展示了XmlXStream类的具体用法。这些代码示例主要来源于Github/
本文整理了Java中org.openid4java.discovery.yadis.YadisResolver类的一些代码示例,展示了YadisResolver类的具体用法。这些代码示例主要来源于Gi
我是一名优秀的程序员,十分优秀!