java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPRequest
org.cybergarage.soap.SOAPRequest
org.cybergarage.upnp.event.NotifyRequest
Represents a UPnP event notification request.
This class extends SOAPRequest to handle GENA (General Event Notification Architecture) NOTIFY messages sent by UPnP devices to inform subscribers about state variable changes. It manages the creation and parsing of event notification messages.
Key features:
- Event notification message creation and parsing
- Property set and property XML structure handling
- SID (Subscription ID) and SEQ (sequence number) management
- NT (Notification Type) and NTS (Notification Sub-Type) headers
- Multi-property change notifications
This class is used by UPnP devices to send event notifications to subscribed control points, informing them of changes in service state variables. It handles both single and multiple property changes in a single notification message.
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty GENA notification request.NotifyRequest(HTTPRequest httpReq) Creates a notification request whose headers come from a received NOTIFY.Method Summary
Modifier and TypeMethodDescriptionprivate NodecreatePropertySetNode(String varName, String value) Builds the propertyset element holding one named value.private PropertygetProperty(Node varNode) Reads a Property element out of a variable node.Reads the changed variables carried in the notification body.longgetSEQ()Gets the event sequence number from the header.getSID()Gets the subscription identifier with itsuuid:prefix stripped.private NodeFinds the propertyset element in the request body.voidSets the notification type header.voidSets the notification sub-type header.booleansetRequest(Subscriber sub, String varName, String value) Fills in the NOTIFY method, URI, headers and property set for one change.voidsetSEQ(long value) Sets the event sequence number, wrapping it at 32 bits.voidSets the subscription identifier, adding the requireduuid:prefix.Methods inherited from class SOAPRequest
getBodyNode, getEnvelopeNode, getSOAPAction, isSOAPAction, postMessage, print, setContent, setEnvelopeNode, setSOAPActionModifier and TypeMethodDescriptionReturn the SOAP body node.Return the SOAP envelope node.Return the SOAP action header value.booleanisSOAPAction(String value) Check if the SOAP action matches the given value.postMessage(String host, int port) Post a SOAP message to the target host and port.voidprint()Writes the request and its root element to the debug log.voidsetContent(Node node) Set the XML content from a node.voidsetEnvelopeNode(Node node) Set the SOAP envelope node.voidsetSOAPAction(String action) Set the SOAP action header.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, 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.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
XMLNS
Element name for the event namespace declaration.- See Also:
PROPERTY
Element name for one property in the set.- See Also:
PROPERTYSET
Element name wrapping the property set.- See Also:
Constructor Details
NotifyRequest
public NotifyRequest()Creates an empty GENA notification request.NotifyRequest
Creates a notification request whose headers come from a received NOTIFY.- Parameters:
httpReq- the received NOTIFY request supplying the headers to parse
Method Details
setNT
setNTS
Sets the notification sub-type header.- Parameters:
value- the notification sub-type to send,NTS.PROPCHANGEfor a property change andNTS.ALIVEorNTS.BYEBYEfor an advertisement
setSID
Sets the subscription identifier, adding the requireduuid:prefix.- Parameters:
id- the subscription identifier to send, wrapped in theuuid:prefix the SID header requires
getSID
Gets the subscription identifier with itsuuid:prefix stripped.- Returns:
- the bare subscription identifier with the
uuid:prefix stripped, or "" when the request carries no SID header
setSEQ
public void setSEQ(long value) Sets the event sequence number, wrapping it at 32 bits.- Parameters:
value- the event sequence number to send, which wraps at 32 bits as the GENA specification requires
getSEQ
public long getSEQ()Gets the event sequence number from the header.- Returns:
- the event sequence number from the header, or 0 when absent or not parseable as a decimal integer
setRequest
Fills in the NOTIFY method, URI, headers and property set for one change.- Parameters:
sub- the subscriber to notify, supplying the delivery URL, host, port, path, subscription identifier and event countervarName- the name of the state variable that changedvalue- the new value of that state variable- Returns:
- true once the NOTIFY method, URI, headers and property set body have been filled in
createPropertySetNode
getVariableNode
Finds the propertyset element in the request body.- Returns:
- the node, null if the body has none
getProperty
getPropertyList
Reads the changed variables carried in the notification body.- Returns:
- the changed variables carried in the body, or an empty list when the request has no envelope or no properties to report