Failed to set modified URLStreamHandlerFactory

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Failed to set modified URLStreamHandlerFactory

xamarin
This post was updated on .
Hello,
Congratulations  for this nice framework;
I need to implement my existing code(java project) into an OSGI java project,
when I try to run it , I have this error:
<b>Grave: 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.</b>
I implemented cling-distribution-2.0-alpha3 instead of cling-distribution-1.0.5.zip but the problem persists,
This is my thread class :
import java.util.ArrayList;
import java.util.List;

import org.fourthline.cling.UpnpService;
import org.fourthline.cling.UpnpServiceImpl;
import org.fourthline.cling.model.message.header.STAllHeader;
import org.fourthline.cling.model.meta.Device;
import org.fourthline.cling.model.meta.LocalDevice;
import org.fourthline.cling.model.meta.RemoteDevice;
import org.fourthline.cling.registry.Registry;
import org.fourthline.cling.registry.RegistryListener;

public class DeviceAddingThread extends Thread {

	private List<Device> devices = new ArrayList<Device>();
	private RegistryListener listener;
	private UpnpService upnpService;

	public List<Device> getDevices() {
		return devices;
	}

	public DeviceAddingThread() {
		listener = new RegistryListener() {
			public void remoteDeviceDiscoveryStarted(Registry registry,
					RemoteDevice device) {
				System.out.println("Discovery started: "
						+ device.getDisplayString());

			}

			public void remoteDeviceDiscoveryFailed(Registry registry,
					RemoteDevice device, Exception ex) {
				System.out.println("Discovery failed: "
						+ device.getDisplayString() + " => " + ex);
			}

			public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
				System.out.println("Remote device available: "
						+ device.getDisplayString());

				devices.add(device);				
			}

			public void remoteDeviceUpdated(Registry registry,
					RemoteDevice device) {
				System.out.println("Remote device updated: "
						+ device.getDisplayString());
			}

			public void remoteDeviceRemoved(Registry registry,
					RemoteDevice device) {
				System.out.println("Remote device removed: "
						+ device.getDisplayString());
			}

			public void localDeviceAdded(Registry registry, LocalDevice device) {
				System.out.println("Local device added: "
						+ device.getDisplayString());
			}

			public void localDeviceRemoved(Registry registry, LocalDevice device) {
				System.out.println("Local device removed: "
						+ device.getDisplayString());
			}

			public void beforeShutdown(Registry registry) {
				System.out
						.println("Before shutdown, the registry has devices: "
								+ registry.getDevices().size());
			}

			public void afterShutdown() {
				System.out.println("Shutdown of registry complete!");
			}
		};
	}

	@Override
	public void run() {
	
		// This will create necessary network resources for UPnP right away

		upnpService = new UpnpServiceImpl(listener);

		// Send a search message to all devices and services, they should
		// respond soon
		upnpService.getControlPoint().search(new STAllHeader());

		// Let's wait 10 seconds for them to respond
		System.out.println("Waiting 10 seconds before shutting down...");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		 //Release all resources and advertise BYEBYE to other UPnP devices
		 System.out.println("Stopping Cling...");
		 upnpService.shutdown();
	}

}

and I call it from an activator

import org.fourthline.cling.model.meta.Device;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

	@Override
	public void start(BundleContext arg0) throws Exception {
		System.out.println("starting...");

		DeviceAddingThread deviceAddingThread=new DeviceAddingThread();
		
		deviceAddingThread.setDaemon(false);
		deviceAddingThread.start();
		try {
			deviceAddingThread.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (Device d: deviceAddingThread.getDevices()){
			if (d!=null)
			new DeviceControlPanel(d);
	}

	public void stop(BundleContext arg0) throws Exception {
		System.out.println("terminating");
		
	}

}

when i try to run the bundle this error occurs, any ideas , or suggestions ?
Reply | Threaded
Open this post in threaded view
|

Re: Failed to set modified URLStreamHandlerFactory

Christian Bauer
Administrator
Can't use bundled default client based on HTTPURLConnection, see manual.

Or FAQ.
Reply | Threaded
Open this post in threaded view
|

Re: Failed to set modified URLStreamHandlerFactory

xamarin
This post was updated on .
Thank you Christian for the quick answer,
you mean that we cannot use Cling for osgi  ???
Reply | Threaded
Open this post in threaded view
|

Re: Failed to set modified URLStreamHandlerFactory

Christian Bauer
Administrator
Your computer will explode if you try. Or you could read the manual.