6

I am trying to create a service to autodiscover upnp devices in my local network, implementing it in a webapplication running on tomcat 7 and using 4thline Cling library. I got this error

org.fourthline.cling.transport.RouterImpl handleStartFailure SEVERE: Unable to initialize network router: org.fourthline.cling.transport.spi.InitializationException: Failed to set modified URLStreamHandlerFactory in this environment. Can't use bundled default client based on HTTPURLConnection, see manual.

In the cling's manual they say that Cling couldn't use the Java JDK's HTTPURLConnection for HTTP client operations. They suggest to configure network transport.

I didn't understand well how to do. Anyone had a similar problem? Can you suggest me an example?

Thanks.

The code I am using 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();
        }


    }
}
Antonio Mele
  • 377
  • 1
  • 5
  • 12

0 Answers0