public class SubscriptionRequestextends HTTPRequest
Represents a UPnP event subscription request.

This class extends HTTPRequest to handle GENA (General Event Notification Architecture) subscription requests for UPnP event notifications. It manages the subscription process including SUBSCRIBE and UNSUBSCRIBE operations for UPnP services.

Key features:

  • SUBSCRIBE and UNSUBSCRIBE request handling
  • Service URL resolution and management
  • Subscription ID (SID) management
  • Callback URL handling
  • Timeout and renewal management

This class is used by UPnP control points to subscribe to event notifications from UPnP services, allowing them to receive updates when service state variables change.

  • Field Details

    • CALLBACK_START_WITH

      private static final String CALLBACK_START_WITH
      /////////////////////////////////////////////
      See Also:
    • CALLBACK_END_WITH

      private static final String CALLBACK_END_WITH
      Character a callback URL ends with.
      See Also:
  • Constructor Details

    • SubscriptionRequest

      public SubscriptionRequest()
      Create an empty subscription request with no content body.
    • SubscriptionRequest

      public SubscriptionRequest(HTTPRequest httpReq)
      Copy the method, URI and headers of an existing HTTP request.
      Parameters:
      httpReq - the request to copy this one's request line and headers from
  • Method Details

    • setService

      private void setService(Service service)
      Sets the service the subscription targets.
      Parameters:
      service - the service being subscribed to
    • setSubscribeRequest

      public void setSubscribeRequest(Service service, String callback, long timeout)
      Turn this request into an initial SUBSCRIBE for the given service.
      Parameters:
      service - the service to subscribe to, supplying the event URL and host
      callback - the event callback URL in angle brackets, where NOTIFYs go
      timeout - the subscription duration in seconds
    • setRenewRequest

      public void setRenewRequest(Service service, String uuid, long timeout)
      Turn this request into a renewal of an existing subscription.
      Parameters:
      service - the service holding the subscription, supplying the event URL
      uuid - the subscription ID of the subscription being renewed
      timeout - the requested subscription duration in seconds
    • setUnsubscribeRequest

      public void setUnsubscribeRequest(Service service)
      Turn this request into an UNSUBSCRIBE, using the service's current subscription ID.
      Parameters:
      service - the service to cancel for, supplying the event URL and SID
    • setNT

      public void setNT(String value)
      Set the NT (notification type) header.
      Parameters:
      value - the notification type, e.g. upnp:event for a subscription
    • getNT

      public String getNT()
      Get the NT (notification type) header value.
      Returns:
      the notification type, or null if the header is not set
    • hasNT

      public boolean hasNT()
      Test whether an NT header is present and non-empty.
      Returns:
      true if a notification type has been set
    • setCallback

      public void setCallback(String value)
      Set the CALLBACK header, enclosing the value in angle brackets.
      Parameters:
      value - the event callback URL where NOTIFY requests are delivered
    • getCallback

      public String getCallback()
      Get the CALLBACK header value with the angle brackets stripped.
      Returns:
      the event callback URL, or null if the header is not set
    • hasCallback

      public boolean hasCallback()
      Test whether a CALLBACK header is present and non-empty.
      Returns:
      true if an event callback URL has been set
    • setSID

      public void setSID(String id)
      Set the SID header from a bare subscription ID.
      Parameters:
      id - the subscription ID to record in the header
    • getSID

      public String getSID()
      Get the subscription ID from the SID header, dropping the uuid: prefix.
      Returns:
      the bare subscription ID, or an empty string if the header is unset or carries no SID
    • hasSID

      public boolean hasSID()
      Test whether a SID header is present and non-empty.
      Returns:
      true if a subscription ID has been set
    • setTimeout

      public final void setTimeout(long value)
      Set the TIMEOUT header naming the subscription duration.
      Parameters:
      value - the subscription duration in seconds
    • getTimeout

      public long getTimeout()
      Get the subscription duration from the TIMEOUT header.
      Returns:
      the subscription duration in seconds, or 0 if the header is unset
    • post

      public void post(SubscriptionResponse subRes)
      Send this request and read the reply as a subscription response.
      Parameters:
      subRes - the response object to populate from the reply
    • post

      public SubscriptionResponse post()
      Send this request to its host and port and wrap the reply.
      Returns:
      the reply wrapped as a subscription response, never null