java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPResponse
org.cybergarage.upnp.ssdp.SSDPResponse
- Direct Known Subclasses:
SSDPSearchResponse
Represents an SSDP response message.
This class extends HTTPResponse to handle SSDP (Simple Service Discovery Protocol) response messages used in UPnP device discovery. It manages the creation and parsing of responses to M-SEARCH requests from control points.
Key features:
- SSDP response header management
- ST (Search Target) header handling
- USN (Unique Service Name) header management
- MYNAME header support for Intel compatibility
- HTTP/1.1 version compliance
This class is used by UPnP devices to respond to discovery searches from control points, providing information about device capabilities and availability. It handles both standard UPnP responses and vendor-specific extensions.
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty response declaring HTTP 1.1.Creates a response whose headers are parsed from a stream.Method Summary
All MethodsModifier and TypeMethodDescriptionintGets the boot identifier header.Renders the whole response as a status line, headers and blank line.intGets the advertisement lifetime from the CACHE-CONTROL header.Gets the Location header.Gets the MYNAME header.getST()Gets the search target header.getUSN()Gets the unique service name header.voidsetBootId(int bootId) Sets the boot identifier header.voidsetLeaseTime(int len) Sets the CACHE-CONTROL max-age header from a lifetime in seconds.voidsetLocation(String value) Sets the Location header to a device description URL.voidSets the MYNAME header, Intel's friendly-name extension.voidSets the search target header.voidSets the unique service name header.Methods inherited from class HTTPResponse
getStatusCode, getStatusLineString, isSuccessful, print, setStatusCode, toStringModifier and TypeMethodDescriptionintGets 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
SSDPResponse
public SSDPResponse()Creates an empty response declaring HTTP 1.1.SSDPResponse
Creates a response whose headers are parsed from a stream.- Parameters:
in- the response stream to parse the headers from
Method Details
setST
Sets the search target header.- Parameters:
value- the search target, identifying which service answered
getST
Gets the search target header.- Returns:
- the ST header, or null if this response carries none
setLocation
Sets the Location header to a device description URL.- Parameters:
value- the URL of the device description document that was searched
getLocation
Gets the Location header.- Returns:
- the Location header, or null if this response carries none
setUSN
Sets the unique service name header.- Parameters:
value- the unique service name identifying the answering device
getUSN
Gets the unique service name header.- Returns:
- the USN header, or null if this response carries none
setMYNAME
Sets the MYNAME header, Intel's friendly-name extension.- Parameters:
value- the friendly device name, for Intel's MYNAME extension
getMYNAME
Gets the MYNAME header.- Returns:
- the MYNAME header, or null if this response carries none
setLeaseTime
public void setLeaseTime(int len) Sets the CACHE-CONTROL max-age header from a lifetime in seconds.- Parameters:
len- the advertisement lifetime in seconds, advertised as max-age
getLeaseTime
public int getLeaseTime()Gets the advertisement lifetime from the CACHE-CONTROL header.- Returns:
- the max-age value in seconds, 0 if the header is absent or unparsable
setBootId
public void setBootId(int bootId) Sets the boot identifier header.- Parameters:
bootId- the device's boot identifier, bumped on each reboot
getBootId
public int getBootId()Gets the boot identifier header.- Returns:
- the BOOTID.UPNP.ORG value, 0 if this response carries none
getHeader
Renders the whole response as a status line, headers and blank line.- Overrides:
getHeaderin classHTTPResponse- Returns:
- the header string