java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPResponse
org.cybergarage.upnp.event.SubscriptionResponse
Represents a UPnP event subscription response.
This class extends HTTPResponse to handle GENA (General Event Notification Architecture) subscription responses for UPnP event notifications. It manages the response to SUBSCRIBE and UNSUBSCRIBE requests, including success and error handling.
Key features:
- Subscription response status management
- SID (Subscription ID) header handling
- Timeout response management
- Error response generation
- UPnP server identification
This class is used by UPnP devices to respond to subscription requests from control points, providing subscription confirmation, timeout information, and error status when necessary.
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty response naming this library as the server.SubscriptionResponse(HTTPResponse httpRes) Wraps the response received from the subscriber.Method Summary
All MethodsModifier and TypeMethodDescriptiongetSID()Returns the subscription identifier from the SID header.longReturns the subscription lifetime from the TIMEOUT header.voidsetErrorResponse(int code) Sets the error status code and clears the body length.voidsetResponse(int code) Sets the status code and clears the body length.voidWrites the subscription identifier to the SID header.voidsetTimeout(long value) Writes the subscription lifetime to the TIMEOUT header.Methods inherited from class HTTPResponse
getHeader, getStatusCode, getStatusLineString, isSuccessful, print, setStatusCode, toStringModifier and TypeMethodDescriptionReturn the full header string for this HTTP response.intGets the HTTP status code of this response.Gets the status line string of this HTTP response.booleanChecks if this response has a successful status code.voidprint()Outputs the full HTTP response to the debug log.voidsetStatusCode(int code) Sets the HTTP status code of this response.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.
Constructor Details
SubscriptionResponse
public SubscriptionResponse()Creates an empty response naming this library as the server.SubscriptionResponse
Wraps the response received from the subscriber.- Parameters:
httpRes- the response received from the subscriber, holding the headers
Method Details
setResponse
public void setResponse(int code) Sets the status code and clears the body length.- Parameters:
code- the HTTP status code to record, sent with an empty body
setErrorResponse
public void setErrorResponse(int code) Sets the error status code and clears the body length.- Parameters:
code- the HTTP error status code to record, sent with an empty body
setSID
Writes the subscription identifier to the SID header.- Parameters:
id- the bare subscription identifier to publish in the SID header
getSID
Returns the subscription identifier from the SID header.- Returns:
- the subscription identifier from the SID header, or the empty string when absent
setTimeout
public void setTimeout(long value) Writes the subscription lifetime to the TIMEOUT header.- Parameters:
value- the subscription lifetime in seconds, or INFINITE_VALUE for unlimited
getTimeout
public long getTimeout()Returns the subscription lifetime from the TIMEOUT header.- Returns:
- the subscription lifetime in seconds from the TIMEOUT header, or INFINITE_VALUE when the header is absent or unparseable