我正在尝试创建一个服务来自动发现我本地网络中的upnp设备,在tomcat 7上运行的web应用程序中实现它并使用4thline Cling库。 我收到了这个错误
org.fourthline.cling.transport.RouterImpl handleStartFailure 严重:无法初始化网络路由器:org.fourthline.cling.transport.spi.InitializationException:无法在此环境中设置已修改的URLStreamHandlerFactory。无法使用基于HTTPURLConnection的捆绑默认客户端,请参阅手册。
在cling's manual中,他们说Cling无法使用Java JDK的HTTPURLConnection进行HTTP客户端操作。他们建议configure network transport。
我不太了解该怎么做。有人有类似的问题吗? 你能给我一个例子吗?
感谢。
我使用的代码是:
public class Example {
public static void startDiscovery() {
RegistryListener listener = new RegistryListener() {
public void remoteDeviceDiscoveryStarted(Registry registry,RemoteDevice device) {
String name = device.getDisplayString();
String url = device.getDetails().getBaseURL().toString();
String friendlyName = device.getDetails().getFriendlyName();
}
public void remoteDeviceDiscoveryFailed(Registry registry,RemoteDevice device, Exception ex) {
}
public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
}
public void remoteDeviceUpdated(Registry registry,RemoteDevice device) {
}
public void remoteDeviceRemoved(Registry registry,RemoteDevice device) {
}
public void localDeviceAdded(Registry registry, LocalDevice device) {
}
public void localDeviceRemoved(Registry registry, LocalDevice device) {
}
public void beforeShutdown(Registry registry) {
}
public void afterShutdown() {
}
};
try{
UpnpService upnpService = new UpnpServiceImpl(listener);
upnpService.getControlPoint().search(new STAllHeader());
// wait 5 seconds for them to respond
Thread.sleep(5000);
upnpService.shutdown();
}catch(Exception e){
e.printStackTrace();
}
}
}