public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice device, Exception ex) { System.out.println( "Discovery failed: " + device.getDisplayString() + " => " + ex ); }
if (currentDevice.hasServices()) { List<RemoteService> filteredServices = filterExclusiveServices(currentDevice.getServices()); for (RemoteService service : filteredServices) { RemoteService svc = describeService(service); if (currentDevice.hasEmbeddedDevices()) { for (RemoteDevice embeddedDevice : currentDevice.getEmbeddedDevices()) { Icon[] iconDupes = new Icon[currentDevice.getIcons().length]; for (int i = 0; i < currentDevice.getIcons().length; i++) { Icon icon = currentDevice.getIcons()[i]; iconDupes[i] = icon.deepCopy(); return currentDevice.newInstance( currentDevice.getIdentity().getUdn(), currentDevice.getVersion(), currentDevice.getType(), currentDevice.getDetails(), iconDupes, currentDevice.toServiceArray(describedServices), describedEmbeddedDevices );
new DeviceItem( device, device.getDetails().getFriendlyName(), device.getDisplayString(), "(REMOTE) " + device.getType().getDisplayString() ); new StreamRequestMessage(UpnpRequest.Method.GET, device.normalizeURI(usableIcon.getUri()));
@Override public RemoteDevice newInstance(UDN udn, UDAVersion version, DeviceType type, DeviceDetails details, Icon[] icons, RemoteService[] services, List<RemoteDevice> embeddedDevices) throws ValidationException { return new RemoteDevice( new RemoteDeviceIdentity(udn, getIdentity()), version, type, details, icons, services, embeddedDevices.size() > 0 ? embeddedDevices.toArray(new RemoteDevice[embeddedDevices.size()]) : null ); }
public URL normalizeURI(URI relativeOrAbsoluteURI) { // TODO: I have one device (Netgear 834DG DSL Router) that sends a <URLBase>, and even that is wrong (port)! // This can be fixed by "re-enabling" UPnP in the upnpService after a reboot, it will then use the right port... // return URIUtil.createAbsoluteURL(getDescriptorURL(), relativeOrAbsoluteURI); if (getDetails() != null && getDetails().getBaseURL() != null) { // If we have an <URLBase>, all URIs are relative to it return URIUtil.createAbsoluteURL(getDetails().getBaseURL(), relativeOrAbsoluteURI); } else { // Otherwise, they are relative to the descriptor location return URIUtil.createAbsoluteURL(getIdentity().getDescriptorURL(), relativeOrAbsoluteURI); } }
@Override public void logRouterInfo() throws RouterException { final RemoteDevice device = service.getDevice(); final UDAVersion version = device.getVersion(); final DeviceDetails deviceDetails = device.getDetails(); logger.info("Service id: {}", service.getServiceId()); logger.info("Reference: {}", service.getReference()); logger.info("Display name: {}", device.getDisplayString()); logger.info("Version: {}.{}", version.getMajor(), version.getMinor()); logger.info("Control uri: {}", service.getControlURI()); logger.info("Descriptor uri: {}", service.getDescriptorURI()); logger.info("Event subscription uri: {}", service.getEventSubscriptionURI()); logger.info("Device base url: {}", deviceDetails.getBaseURL()); logger.info("Device presentation uri: {}", deviceDetails.getPresentationURI()); }
public void resume() { log.fine("Updating remote device expiration timestamps on resume"); List<RemoteDeviceIdentity> toUpdate = new ArrayList<>(); for (RegistryItem<UDN, RemoteDevice> remoteItem : getDeviceItems()) { toUpdate.add(remoteItem.getItem().getIdentity()); } for (RemoteDeviceIdentity identity : toUpdate) { update(identity); } }
descriptorURL = service.getDevice().normalizeURI(service.getDescriptorURI()); } catch(IllegalArgumentException e) { log.warning("Could not normalize service descriptor URL: " + service.getDescriptorURI()); getUpnpService().getConfiguration().getDescriptorRetrievalHeaders(service.getDevice().getIdentity()); if (headers != null) serviceDescRetrievalMsg.getHeaders().putAll(headers);
if (registeredRemoteDevice != null) { if (!registeredRemoteDevice.isRoot()) { log.fine("Updating root device of embedded: " + registeredRemoteDevice); registeredRemoteDevice = registeredRemoteDevice.getRoot(); registeredRemoteDevice.getIdentity().getUdn(), registeredRemoteDevice, registry.getConfiguration().getRemoteDeviceMaxAgeSeconds() != null
synchronized public URL getEventSubscriptionURL() { return getService().getDevice().normalizeURI( getService().getEventSubscriptionURI() ); }
rd = new RemoteDevice(rdIdentity); } catch (ValidationException ex) { log.warning("Validation errors of device during discovery: " + rdIdentity);
private URI getUri() { if (service.getDevice().getDetails().getPresentationURI() != null) { return service.getDevice().getDetails().getPresentationURI(); } if (service.getControlURI() != null) { return service.getControlURI(); } if (service.getDescriptorURI() != null) { return service.getDescriptorURI(); } if (service.getEventSubscriptionURI() != null) { return service.getEventSubscriptionURI(); } return null; }
public void run() { URL deviceURL = rd.getIdentity().getDescriptorURL(); // Performance optimization, try to avoid concurrent GET requests for device descriptor, // if we retrieve it once, we have the hydrated device. There is no different outcome // processing this several times concurrently. if (activeRetrievals.contains(deviceURL)) { log.finer("Exiting early, active retrieval for URL already in progress: " + deviceURL); return; } // Exit if it has been discovered already, could be we have been waiting in the executor queue too long if (getUpnpService().getRegistry().getRemoteDevice(rd.getIdentity().getUdn(), true) != null) { log.finer("Exiting early, already discovered: " + deviceURL); return; } try { activeRetrievals.add(deviceURL); describe(); } catch (RouterException ex) { log.log(Level.WARNING, "Descriptor retrieval failed: " + deviceURL, ex ); } finally { activeRetrievals.remove(deviceURL); } }
addIfNotNull(deviceNode, "Descriptor URL: ", ((RemoteDevice) device).getIdentity().getDescriptorURL(), true); } else if (device instanceof LocalDevice) { addIfNotNull(deviceNode, "Descriptor URI: ", namespace.getDescriptorPath(device)); addIfNotNull(deviceNode, "Presentation URI: ", device.getDetails().getPresentationURI(), device); if (device instanceof RemoteDevice && ((RemoteDevice) device).getIdentity().getInterfaceMacAddress() != null) addIfNotNull(deviceNode, "MAC Ethernet Address: ", HexBin.bytesToString(((RemoteDevice) device).getIdentity().getInterfaceMacAddress(), ":")); } else if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; addIfNotNull(serviceNode, "Descriptor URL: ", rs.getDevice().normalizeURI(rs.getDescriptorURI()), true); addIfNotNull(serviceNode, "Control URL: ", rs.getDevice().normalizeURI(rs.getControlURI()), true); addIfNotNull(serviceNode, "Event Subscription URL: ", rs.getDevice().normalizeURI(rs.getEventSubscriptionURI()), true);
public URL normalizeURI(URI relativeOrAbsoluteURI) { // TODO: I have one device (Netgear 834DG DSL Router) that sends a <URLBase>, and even that is wrong (port)! // This can be fixed by "re-enabling" UPnP in the upnpService after a reboot, it will then use the right port... // return URIUtil.createAbsoluteURL(getDescriptorURL(), relativeOrAbsoluteURI); if (getDetails() != null && getDetails().getBaseURL() != null) { // If we have an <URLBase>, all URIs are relative to it return URIUtil.createAbsoluteURL(getDetails().getBaseURL(), relativeOrAbsoluteURI); } else { // Otherwise, they are relative to the descriptor location return URIUtil.createAbsoluteURL(getIdentity().getDescriptorURL(), relativeOrAbsoluteURI); } }
if (registeredRemoteDevice != null) { if (!registeredRemoteDevice.isRoot()) { log.fine("Updating root device of embedded: " + registeredRemoteDevice); registeredRemoteDevice = registeredRemoteDevice.getRoot(); registeredRemoteDevice.getIdentity().getUdn(), registeredRemoteDevice, registry.getConfiguration().getRemoteDeviceMaxAgeSeconds() != null
protected void addIfNotNull(DefaultMutableTreeNode parent, String info, URI uri, Device device) { if (device instanceof RemoteDevice) { try { addIfNotNull(parent, info, uri != null ? ((RemoteDevice) device).normalizeURI(uri) : null, true); } catch (IllegalArgumentException ex) { if (ex.getCause() != null && ex.getCause() instanceof MalformedURLException) { // If it's an unsupported URL (which in Java is pretty much anything but HTTP) show the plain text addIfNotNull(parent, info, uri, false); } else { throw ex; } } } else if (device instanceof LocalDevice) { addIfNotNull(parent, info, uri, false); } }
@Override public RemoteDevice newInstance(UDN udn, UDAVersion version, DeviceType type, DeviceDetails details, Icon[] icons, RemoteService[] services, List<RemoteDevice> embeddedDevices) throws ValidationException { return new RemoteDevice( new RemoteDeviceIdentity(udn, getIdentity()), version, type, details, icons, services, embeddedDevices.size() > 0 ? embeddedDevices.toArray(new RemoteDevice[embeddedDevices.size()]) : null ); }
rd = new RemoteDevice(rdIdentity); } catch (ValidationException ex) { log.warning("Validation errors of device during discovery: " + rdIdentity);
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeClass public final void setup() throws Exception { upnpClient = new UpnpClient("ContentDirectory", device -> "underTest".equals(device.getDetails().getSerialNumber())); Executors.newSingleThreadExecutor().submit(upnpClient); final Map<Key<?>, Object> properties = new HashMap<>(); final Path repositoryPath = Paths.get("target/test-classes/test-sets/model-iTunes-fg-20160504-2.n3"); properties.put(ROOT_PATH, TestSetLocator.getMusicTestSetsPath().resolve("iTunes-fg-20160504-2")); final PowerOnNotification powerOnNotification = new PowerOnNotification(properties); final DefaultMediaFileSystem fileSystem = context.getBean(DefaultMediaFileSystem.class); resourceServer = context.getBean(DefaultResourceServer.class); fileSystem.onPowerOnNotification(powerOnNotification); resourceServer.onPowerOnNotification(powerOnNotification); final Repository repository = context.getBean(Repository.class); loadRepository(repository, repositoryPath); cacheManager = context.getBean(DefaultCacheManager.class); }