@Override protected Namespace createNamespace() { // For the Jetty server, this is the servlet context path return new Namespace("/upnp"); }
discovered.add(new DeviceDescriptorResource(namespace.getDescriptorPath(this), this)); new ServiceDescriptorResource(namespace.getDescriptorPath(service), service) ); new ServiceControlResource(namespace.getControlPath(service), service) ); new ServiceEventSubscriptionResource(namespace.getEventSubscriptionPath(service), service) ); discovered.add(new IconResource(namespace.prefixIfRelative(this, icon.getUri()), icon));
@Override public Resource[] discoverResources(Namespace namespace) { List<Resource> discovered = new ArrayList<>(); // Services for (RemoteService service : getServices()) { if(service == null) continue; discovered.add(new ServiceEventCallbackResource(namespace.getEventCallbackPath(service), service)); } // Embedded devices if (hasEmbeddedDevices()) { for (Device embeddedDevice : getEmbeddedDevices()) { if(embeddedDevice == null) continue; discovered.addAll(Arrays.asList(embeddedDevice.discoverResources(namespace))); } } return discovered.toArray(new Resource[discovered.size()]); }
addIfNotNull(deviceNode, "Descriptor URL: ", ((RemoteDevice) device).getIdentity().getDescriptorURL(), true); } else if (device instanceof LocalDevice) { addIfNotNull(deviceNode, "Descriptor URI: ", namespace.getDescriptorPath(device)); addIfNotNull(serviceNode, "Descriptor URI: ", namespace.getDescriptorPath(ls)); addIfNotNull(serviceNode, "Control URI: ", namespace.getControlPath(ls)); addIfNotNull(serviceNode, "Event Subscription URI: ", namespace.getEventSubscriptionPath(ls)); addIfNotNull(serviceNode, "Local Event Callback URI: ", namespace.getEventCallbackPath(ls)); } else if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service;
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasServices()) return; Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList); for (Service service : deviceModel.getServices()) { Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId()); if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI()); } else if (service instanceof LocalService) { LocalService ls = (LocalService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls)); } } }
} else if (getUpnpService().getConfiguration().getNamespace().isControlPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventSubscriptionPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri())) { )) ); if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri()) && message.getOperation().getMethod().equals(UpnpRequest.Method.NOTIFY)) return createReceivingEvent(message);
protected Location getDescriptorLocation(NetworkAddress activeStreamServer, LocalDevice device) { return new Location( activeStreamServer, getUpnpService().getConfiguration().getNamespace().getDescriptorPath(device) ); }
public URI getEventCallbackPath(Service service) { return URI.create(getEventSubscriptionPath(service).toString() + CALLBACK_FILE); }
synchronized public void init(InetAddress bindAddress, final Router router) throws InitializationException { try { if (log.isLoggable(Level.FINE)) log.fine("Setting executor service on servlet container adapter"); getConfiguration().getServletContainerAdapter().setExecutorService( router.getConfiguration().getStreamServerExecutorService() ); if (log.isLoggable(Level.FINE)) log.fine("Adding connector: " + bindAddress + ":" + getConfiguration().getListenPort()); hostAddress = bindAddress.getHostAddress(); localPort = getConfiguration().getServletContainerAdapter().addConnector( hostAddress, getConfiguration().getListenPort() ); String contextPath = router.getConfiguration().getNamespace().getBasePath().getPath(); getConfiguration().getServletContainerAdapter().registerServlet(contextPath, createServlet(router)); } catch (Exception ex) { throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex.toString(), ex); } }
Resource[] getResources(Device device) throws RegistrationException { try { return registry.getConfiguration().getNamespace().getResources(device); } catch (ValidationException ex) { throw new RegistrationException("Resource discover error: " + ex.toString(), ex); } } }
protected void generateIconList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasIcons()) return; Element iconListElement = appendNewElement(descriptor, deviceElement, ELEMENT.iconList); for (Icon icon : deviceModel.getIcons()) { Element iconElement = appendNewElement(descriptor, iconListElement, ELEMENT.icon); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.mimetype, icon.getMimeType()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.width, icon.getWidth()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.height, icon.getHeight()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.depth, icon.getDepth()); if (deviceModel instanceof RemoteDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, icon.getUri()); } else if (deviceModel instanceof LocalDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, namespace.getIconPath(icon)); } } }
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasServices()) return; Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList); for (Service service : deviceModel.getServices()) { Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId()); if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI()); } else if (service instanceof LocalService) { LocalService ls = (LocalService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls)); } } }
} else if (getUpnpService().getConfiguration().getNamespace().isControlPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventSubscriptionPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri())) { )) ); if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri()) && message.getOperation().getMethod().equals(UpnpRequest.Method.NOTIFY)) return createReceivingEvent(message);
protected void execute() throws RouterException { List<NetworkAddress> activeStreamServers = getUpnpService().getRouter().getActiveStreamServers(null); if (activeStreamServers.size() == 0) { log.fine("Aborting notifications, no active stream servers found (network disabled?)"); return; } // Prepare it once, it's the same for each repetition List<Location> descriptorLocations = new ArrayList(); for (NetworkAddress activeStreamServer : activeStreamServers) { descriptorLocations.add( new Location( activeStreamServer, getUpnpService().getConfiguration().getNamespace().getDescriptorPath(getDevice()) ) ); } for (int i = 0; i < getBulkRepeat(); i++) { try { for (Location descriptorLocation : descriptorLocations) { sendMessages(descriptorLocation); } // UDA 1.0 is silent about this but UDA 1.1 recomments "a few hundred milliseconds" log.finer("Sleeping " + getBulkIntervalMilliseconds() + " milliseconds"); Thread.sleep(getBulkIntervalMilliseconds()); } catch (InterruptedException ex) { log.warning("Advertisement thread was interrupted: " + ex); } } }
return URI.create(getBasePath().toString() + s.toString());
Resource[] getResources(Device device) throws RegistrationException { try { return registry.getConfiguration().getNamespace().getResources(device); } catch (ValidationException ex) { throw new RegistrationException("Resource discover error: " + ex.toString(), ex); } } }
protected void generateIconList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasIcons()) return; Element iconListElement = appendNewElement(descriptor, deviceElement, ELEMENT.iconList); for (Icon icon : deviceModel.getIcons()) { Element iconElement = appendNewElement(descriptor, iconListElement, ELEMENT.icon); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.mimetype, icon.getMimeType()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.width, icon.getWidth()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.height, icon.getHeight()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.depth, icon.getDepth()); if (deviceModel instanceof RemoteDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, icon.getUri()); } else if (deviceModel instanceof LocalDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, namespace.getIconPath(icon)); } } }
discovered.add(new DeviceDescriptorResource(namespace.getDescriptorPath(this), this)); new ServiceDescriptorResource(namespace.getDescriptorPath(service), service) ); new ServiceControlResource(namespace.getControlPath(service), service) ); new ServiceEventSubscriptionResource(namespace.getEventSubscriptionPath(service), service) ); discovered.add(new IconResource(namespace.prefixIfRelative(this, icon.getUri()), icon));
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasServices()) return; Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList); for (Service service : deviceModel.getServices()) { Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId()); if (service instanceof RemoteService) { RemoteService rs = (RemoteService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI()); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI()); } else if (service instanceof LocalService) { LocalService ls = (LocalService) service; appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls)); appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls)); } } }
} else if (getUpnpService().getConfiguration().getNamespace().isControlPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventSubscriptionPath(message.getUri())) { } else if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri())) { )) ); if (getUpnpService().getConfiguration().getNamespace().isEventCallbackPath(message.getUri()) && message.getOperation().getMethod().equals(UpnpRequest.Method.NOTIFY)) return createReceivingEvent(message);