Clinging with a lump

I am trying to create a service for automatically detecting upnp devices on a local network, implementing it in a web application running on tomcat 7 and using the 4th Cling library. I got this error

org.fourthline.cling.transport.RouterImpl handleStartFailure SEVERE: cannot initialize the network router: org.fourthline.cling.transport.spi.InitializationException: Failed to set the modified URLStreamHandlerFactory in this environment. You cannot use the connected client by default based on HTTPURLConnection, see the Guide.

In the cling manual, they say that Cling was not able to use the Java JDK HTTPURLConnection for operations with the HTTP client. They suggest setting up network transport .

I poorly understood how to do this. Has anyone had a similar problem? Can you offer me an example?

Thanks.

The code I use is:

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(); } } } 
+5
source share

Source: https://habr.com/ru/post/1247673/


All Articles