public UpnpServiceConfiguration getConfiguration() { return upnpService.getConfiguration(); }
public UpnpServiceConfiguration getConfiguration() { return getUpnpService().getConfiguration(); }
protected void onSubscriptionFailure() { log.fine("Subscription failed"); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { subscription.fail(null); } } ); } }
protected List<RemoteService> filterExclusiveServices(RemoteService[] services) { ServiceType[] exclusiveTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes(); if (exclusiveTypes == null || exclusiveTypes.length == 0) return Arrays.asList(services); List<RemoteService> exclusiveServices = new ArrayList<>(); for (RemoteService discoveredService : services) { for (ServiceType exclusiveType : exclusiveTypes) { if (discoveredService.getServiceType().implementsVersion(exclusiveType)) { log.fine("Including exclusive service: " + discoveredService); exclusiveServices.add(discoveredService); } else { log.fine("Excluding unwanted service: " + exclusiveType); } } } return exclusiveServices; }
public SendingUnsubscribe(UpnpService upnpService, RemoteGENASubscription subscription) { super( upnpService, new OutgoingUnsubscribeRequestMessage( subscription, upnpService.getConfiguration().getEventSubscriptionHeaders(subscription.getService()) ) ); this.subscription = subscription; }
protected void onRenewalFailure() { log.fine("Subscription renewal failed, removing subscription from registry"); getUpnpService().getRegistry().removeRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { subscription.end(CancelReason.RENEWAL_FAILED, null); } } ); } }
public SendingSubscribe(UpnpService upnpService, RemoteGENASubscription subscription, List<NetworkAddress> activeStreamServers) { super( upnpService, new OutgoingSubscribeRequestMessage( subscription, subscription.getEventCallbackURLs( activeStreamServers, upnpService.getConfiguration().getNamespace() ), upnpService.getConfiguration().getEventSubscriptionHeaders(subscription.getService()) ) ); this.subscription = subscription; }
public SendingRenewal(UpnpService upnpService, RemoteGENASubscription subscription) { super( upnpService, new OutgoingRenewalRequestMessage( subscription, upnpService.getConfiguration().getEventSubscriptionHeaders(subscription.getService()) ) ); this.subscription = subscription; }
protected void handleResponseFailure(IncomingActionResponseMessage responseMsg) throws ActionException { try { log.fine("Received response with Internal Server Error, reading SOAP failure message"); getUpnpService().getConfiguration().getSoapActionProcessor().readBody(responseMsg, actionInvocation); } catch (UnsupportedDataException ex) { log.fine("Error reading SOAP body: " + ex); log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex)); throw new ActionException( ErrorCode.ACTION_FAILED, "Error reading SOAP response failure message. " + ex.getMessage(), false ); } }
protected void handleResponse(IncomingActionResponseMessage responseMsg) throws ActionException { try { log.fine("Received response for outgoing call, reading SOAP response body: " + responseMsg); getUpnpService().getConfiguration().getSoapActionProcessor().readBody(responseMsg, actionInvocation); } catch (UnsupportedDataException ex) { log.fine("Error reading SOAP body: " + ex); log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex)); throw new ActionException( ErrorCode.ACTION_FAILED, "Error reading SOAP response message. " + ex.getMessage(), false ); } }
public void eventReceived() { // The only thing we are interested in, sending an event when the state changes getUpnpService().getConfiguration().getSyncProtocolExecutorService().execute( getUpnpService().getProtocolFactory().createSendingEvent(this) ); } };
protected Location getDescriptorLocation(NetworkAddress activeStreamServer, LocalDevice device) { return new Location( activeStreamServer, getUpnpService().getConfiguration().getNamespace().getDescriptorPathString(device) ); }
protected StreamResponseMessage sendRemoteRequest(OutgoingActionRequestMessage requestMessage) throws ActionException, RouterException { try { log.fine("Writing SOAP request body of: " + requestMessage); getUpnpService().getConfiguration().getSoapActionProcessor().writeBody(requestMessage, actionInvocation); log.fine("Sending SOAP body of message as stream to remote device"); return getUpnpService().getRouter().send(requestMessage); } catch (RouterException ex) { Throwable cause = Exceptions.unwrap(ex); if (cause instanceof InterruptedException) { if (log.isLoggable(Level.FINE)) { log.fine("Sending action request message was interrupted: " + cause); } throw new ActionCancelledException((InterruptedException)cause); } throw ex; } catch (UnsupportedDataException ex) { if (log.isLoggable(Level.FINE)) { log.fine("Error writing SOAP body: " + ex); log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex)); } throw new ActionException(ErrorCode.ACTION_FAILED, "Error writing request message. " + ex.getMessage()); } }
protected void onUnsubscribe(final StreamResponseMessage response) { // Always remove from the registry and end the subscription properly - even if it's failed getUpnpService().getRegistry().removeRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { if (response == null) { log.fine("Unsubscribe failed, no response received"); subscription.end(CancelReason.UNSUBSCRIBE_FAILED, null); } else if (response.getOperation().isFailed()) { log.fine("Unsubscribe failed, response was: " + response); subscription.end(CancelReason.UNSUBSCRIBE_FAILED, response.getOperation()); } else { log.fine("Unsubscribe successful, response was: " + response); subscription.end(null, response.getOperation()); } } } ); } }
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().getDescriptorPathString(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); } } }
protected boolean isSupportedServiceAdvertisement(IncomingDatagramMessage message) { ServiceType[] exclusiveServiceTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes(); if (exclusiveServiceTypes == null) return false; // Discovery is disabled if (exclusiveServiceTypes.length == 0) return true; // Any advertisement is fine String usnHeader = message.getHeaders().getFirstHeader(UpnpHeader.Type.USN.getHttpName()); if (usnHeader == null) return false; // Not a service advertisement, drop it try { NamedServiceType nst = NamedServiceType.valueOf(usnHeader); for (ServiceType exclusiveServiceType : exclusiveServiceTypes) { if (nst.getServiceType().implementsVersion(exclusiveServiceType)) return true; } } catch (InvalidValueException ex) { log.finest("Not a named service type header value: " + usnHeader); } log.fine("Service advertisement not supported, dropping it: " + usnHeader); return false; }
@Override public void responseSent(StreamResponseMessage responseMessage) { if (subscription == null) return; // Preconditions failed very early on if (responseMessage != null && !responseMessage.getOperation().isFailed() && subscription.getCurrentSequence().getValue() == 0) { // Note that renewals should not have 0 // This is a minor concurrency issue: If we now register on the service and henceforth send a new // event message whenever the state of the service changes, there is still a chance that the initial // event message arrives later than the first on-change event message. Shouldn't be a problem as the // subscriber is supposed to figure out what to do with out-of-sequence messages. I would be // surprised though if actual implementations won't crash! log.fine("Establishing subscription"); subscription.registerOnService(); subscription.establish(); log.fine("Response to subscription sent successfully, now sending initial event asynchronously"); getUpnpService().getConfiguration().getAsyncProtocolExecutor().execute( getUpnpService().getProtocolFactory().createSendingEvent(subscription) ); } else if (subscription.getCurrentSequence().getValue() == 0) { log.fine("Subscription request's response aborted, not sending initial event"); if (responseMessage == null) { log.fine("Reason: No response at all from subscriber"); } else { log.fine("Reason: " + responseMessage.getOperation()); } log.fine("Removing subscription from registry: " + subscription); getUpnpService().getRegistry().removeLocalSubscription(subscription); } }
public SendingEvent(UpnpService upnpService, LocalGENASubscription subscription) { super(upnpService, null); // Special case, we actually need to send several messages to each callback URL // TODO: Ugly design! It is critical (concurrency) that we prepare the event messages here, in the constructor thread! subscriptionId = subscription.getSubscriptionId(); requestMessages = new OutgoingEventRequestMessage[subscription.getCallbackURLs().size()]; int i = 0; for (URL url : subscription.getCallbackURLs()) { requestMessages[i] = new OutgoingEventRequestMessage(subscription, url); getUpnpService().getConfiguration().getGenaEventProcessor().writeBody(requestMessages[i]); i++; } currentSequence = subscription.getCurrentSequence(); // Always increment sequence now, as (its value) has already been set on the headers and the // next event will use the incremented value subscription.incrementSequence(); }
if(getUpnpService().getConfiguration().isReceivedSubscriptionTimeoutIgnored()) {
} 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);