java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPRequest
org.cybergarage.upnp.event.SubscriptionRequest
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 Summary
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty subscription request with no content body.SubscriptionRequest(HTTPRequest httpReq) Copy the method, URI and headers of an existing HTTP request.Method Summary
Modifier and TypeMethodDescriptionGet the CALLBACK header value with the angle brackets stripped.getNT()Get the NT (notification type) header value.getSID()Get the subscription ID from the SID header, dropping the uuid: prefix.longGet the subscription duration from the TIMEOUT header.booleanTest whether a CALLBACK header is present and non-empty.booleanhasNT()Test whether an NT header is present and non-empty.booleanhasSID()Test whether a SID header is present and non-empty.post()Send this request to its host and port and wrap the reply.voidpost(SubscriptionResponse subRes) Send this request and read the reply as a subscription response.voidsetCallback(String value) Set the CALLBACK header, enclosing the value in angle brackets.voidSet the NT (notification type) header.voidsetRenewRequest(Service service, String uuid, long timeout) Turn this request into a renewal of an existing subscription.private voidsetService(Service service) Sets the service the subscription targets.voidSet the SID header from a bare subscription ID.voidsetSubscribeRequest(Service service, String callback, long timeout) Turn this request into an initial SUBSCRIBE for the given service.final voidsetTimeout(long value) Set the TIMEOUT header naming the subscription duration.voidsetUnsubscribeRequest(Service service) Turn this request into an UNSUBSCRIBE, using the service's current subscription ID.Methods inherited from class HTTPRequest
getFirstLineString, getHeader, getHTTPVersion, getLocalAddress, getLocalPort, getMethod, getParameterList, getParameterValue, getRequestHost, getRequestPort, getSocket, getURI, isGetRequest, isHeadRequest, isKeepAlive, isMethod, isNotifyRequest, isPostRequest, isSOAPAction, isSubscribeRequest, isUnsubscribeRequest, parseRequestLine, post, post, post, print, read, returnBadRequest, returnOK, returnResponse, set, setBindHost, setMethod, setRequestHost, setRequestPort, setSocket, setURI, setURI, toStringModifier and TypeMethodDescriptionReturns the first line of the HTTP request (method, URI, and version).Returns the complete HTTP header as a string.Returns the HTTP version string for this request.Returns the local address of the underlying socket.intReturns the local port of the underlying socket.Returns the HTTP method.Parses the URI query string and returns the parameters as a ParameterList.getParameterValue(String name) Returns the value of the specified URI query parameter.Returns the request host.intReturns the request port.Returns the HTTPSocket for this request.getURI()Returns the request URI.booleanDetermines if this is a GET request.booleanDetermines if this is a HEAD request.booleanDetermines if this connection should be kept alive.booleanChecks if the HTTP method matches the given string.booleanDetermines if this is a NOTIFY request.booleanDetermines if this is a POST request.booleanChecks if this request has a SOAPAction header.booleanDetermines if this is a SUBSCRIBE request.booleanDetermines if this is an UNSUBSCRIBE request.booleanparseRequestLine(String lineStr) Parses an HTTP request line and extracts method, URI, and version.Posts this HTTP request to the specified host and port with no keep-alive.Posts this HTTP request to the specified host and port.booleanpost(HTTPResponse httpRes) Posts an HTTP response back to the client.voidprint()Prints the HTTP request to the debug message stream.booleanread()Reads the HTTP request from the underlying socket.booleanSends an HTTP 400 Bad Request response with no content.booleanreturnOK()Sends an HTTP 200 OK response with no content.booleanreturnResponse(int statusCode) Sends an HTTP response with the specified status code and no content.voidset(HTTPRequest httpReq) Copies the contents of the given HTTP request into this request.voidsetBindHost(String host) I2P - bind HTTP socket to specified local host addressvoidSets the HTTP method (e.g., GET, POST).voidsetRequestHost(String host) Sets the host for this request.voidsetRequestPort(int host) Sets the port for this request.voidsetSocket(HTTPSocket value) Sets the HTTPSocket for this request.voidSets the URI for this HTTP request without relative URL conversion.voidSets the URI for this HTTP request.toString()/////////////////////////////////////////////Methods inherited from class HTTPPacket
addHeader, addHeader, clearHeaders, getCacheControl, getCharSet, getConnection, getContent, getContentInputStream, getContentLanguage, getContentLength, getContentRange, getContentRangeFirstPosition, getContentRangeInstanceLength, getContentRangeLastPosition, getContentString, getContentType, getDate, getFirstLine, getFirstLineToken, getHeader, getHeader, getHeaderString, getHeaderValue, getHost, getIntegerHeaderValue, getLongHeaderValue, getNHeaders, getServer, getStringHeaderValue, getStringHeaderValue, getTransferEncoding, getVersion, hasConnection, hasContent, hasContentInputStream, hasContentRange, hasFirstLine, hasHeader, hasTransferEncoding, init, isChunked, isCloseConnection, isKeepAliveConnection, read, set, set, set, set, setCacheControl, setCacheControl, setCacheControl, setConnection, setContent, setContent, setContent, setContent, setContentInputStream, setContentLanguage, setContentLength, setContentRange, setContentType, setDate, setHeader, setHeader, setHeader, setHeader, setHost, setIntegerHeader, setLongHeader, setServer, setStringHeader, setStringHeader, setTransferEncoding, setVersionModifier and TypeMethodDescriptionvoidAdds a header with the specified name and value.voidaddHeader(HTTPHeader header) Adds a header to this HTTP packet.voidClears all headers from this HTTP packet.Get the Cache-Control header value.Gets the character set from the Content-Type header.Gets the Connection header value.byte[]Gets the content of this HTTP packet.Gets the content input stream.Gets the Content-Language header value.longGets the content length from the Content-Length header.long[]Gets the content range values as an array.longGet the first position from the content range.longGet the instance length from the content range.longGet the last position from the content range.Gets the content of this HTTP packet as a string.Gets the Content-Type header value.getDate()Get the Date header value.protected StringGets the first line of the HTTP packet.protected StringgetFirstLineToken(int num) Gets a specific token from the first line using HTTP request line delimiters.getHeader(int n) Gets the header at the specified index.Gets the header with the specified name, ignoring case.Gets all headers as a formatted string.getHeaderValue(String name) Gets the value of a header by name.getHost()Get the Host header value.intgetIntegerHeaderValue(String name) Gets an integer header value by name.longgetLongHeaderValue(String name) Gets a long header value by name.intGets the number of headers in this HTTP packet.Get the Server header value.getStringHeaderValue(String name) Gets a string header value, stripping double quotes if present.getStringHeaderValue(String name, String startWidth, String endWidth) Gets a string header value, stripping the specified delimiters if present.Get the Transfer-Encoding header value.Gets the HTTP version of this packet.booleanChecks if the Connection header is set.booleanChecks if this HTTP packet has content.booleanChecks if a content input stream has been set.booleanChecks if the Content-Range or Range header is set.booleanChecks if the first line of the HTTP packet has been set.booleanChecks if a header with the specified name exists.booleanCheck if the Transfer-Encoding header is set.voidinit()Initializes the HTTP packet to empty state.booleanCheck if the content is chunked.booleanChecks if the Connection header is set to close.booleanChecks if the Connection header is set to keep-alive.booleanread(HTTPSocket httpSock) Reads and parses HTTP packet from a socket.protected booleanset(InputStream in) Parses HTTP packet data from an input stream including content.protected booleanset(InputStream in, boolean onlyHeaders) Parses HTTP packet data from an input stream.protected voidset(HTTPPacket httpPacket) Copies all data from another HTTP packet to this packet.protected booleanset(HTTPSocket httpSock) Parses HTTP packet data from an HTTP socket.voidsetCacheControl(int value) Set the Cache-Control header with a max-age value.voidsetCacheControl(String directive) Set the Cache-Control header.voidsetCacheControl(String directive, int value) Set the Cache-Control header with a directive and value.voidsetConnection(String value) Sets the Connection header.voidsetContent(byte[] data) Sets the content of this HTTP packet.voidsetContent(byte[] data, boolean updateWithContentLength) Sets the content of this HTTP packet.voidsetContent(String data) Sets the content of this HTTP packet from a string.voidsetContent(String data, boolean updateWithContentLength) Sets the content of this HTTP packet from a string.voidSets the content input stream.voidsetContentLanguage(String code) Sets the Content-Language header.voidsetContentLength(long len) Sets the Content-Length header.voidsetContentRange(long firstPos, long lastPos, long length) Sets the Content-Range header.voidsetContentType(String type) Sets the Content-Type header.voidSet the Date header.voidSets the value of a header from an integer.voidSets the value of a header from a long.voidSets the value of a header.voidsetHeader(HTTPHeader header) Sets the value of a header from an HTTP header object.voidSet the Host header.voidsetIntegerHeader(String name, int value) Sets an integer header value.voidsetLongHeader(String name, long value) Sets a long header value.voidSet the Server header.voidsetStringHeader(String name, String value) Sets a string header value, wrapping it with double quotes if not already wrapped.voidsetStringHeader(String name, String value, String startWidth, String endWidth) Sets a string header value, wrapping it with the specified delimiters if not already wrapped.voidsetTransferEncoding(String value) Set the Transfer-Encoding header.voidsetVersion(String ver) Sets the HTTP version for this packet.
Field Details
CALLBACK_START_WITH
/////////////////////////////////////////////- See Also:
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
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
Sets the service the subscription targets.- Parameters:
service- the service being subscribed to
setSubscribeRequest
Turn this request into an initial SUBSCRIBE for the given service.- Parameters:
service- the service to subscribe to, supplying the event URL and hostcallback- the event callback URL in angle brackets, where NOTIFYs gotimeout- the subscription duration in seconds
setRenewRequest
Turn this request into a renewal of an existing subscription.- Parameters:
service- the service holding the subscription, supplying the event URLuuid- the subscription ID of the subscription being renewedtimeout- the requested subscription duration in seconds
setUnsubscribeRequest
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
Set the NT (notification type) header.- Parameters:
value- the notification type, e.g. upnp:event for a subscription
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
Set the CALLBACK header, enclosing the value in angle brackets.- Parameters:
value- the event callback URL where NOTIFY requests are delivered
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
Set the SID header from a bare subscription ID.- Parameters:
id- the subscription ID to record in the header
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
Send this request and read the reply as a subscription response.- Parameters:
subRes- the response object to populate from the reply
post
Send this request to its host and port and wrap the reply.- Returns:
- the reply wrapped as a subscription response, never null