java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPRequest
org.cybergarage.upnp.ssdp.SSDPRequest
- Direct Known Subclasses:
SSDPNotifyRequest, SSDPSearchRequest
Base class for SSDP request messages.
This class extends HTTPRequest to provide common functionality for SSDP (Simple Service Discovery Protocol) request messages used in UPnP device discovery and advertisement. It serves as the foundation for specific SSDP request types.
Key features:
- SSDP request header management
- HTTP/1.1 version compliance
- Common SSDP header operations
- Request parsing and creation
- Multicast communication support
This class provides the base functionality for SSDP M-SEARCH and NOTIFY requests, handling common header management and HTTP protocol compliance for SSDP operations in UPnP networks.
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty request announcing the HTTP/1.1 version SSDP requires.Construct a request from headers already read off the wire.Method Summary
All MethodsModifier and TypeMethodDescriptionintReturn the BOOTID.UPNP.ORG header.intReturn the max-age lease carried by the Cache-Control header.Return the Location header.getNT()Return the NT header.getNTS()Return the NTS header.getUSN()Return the USN header.voidsetBootId(int bootId) Set the BOOTID.UPNP.ORG header, recording the sender's boot generation.voidsetLeaseTime(int len) Set the Cache-Control header, carrying this advertisement's max-age lease.voidsetLocation(String value) Set the Location header, giving the URL of the device description document.voidSet the NT header, naming the notification type being advertised.voidSet the NTS header, naming the notification sub type.voidSet the USN header, naming the service being notified.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.
Constructor Details
SSDPRequest
public SSDPRequest()Construct an empty request announcing the HTTP/1.1 version SSDP requires.SSDPRequest
Construct a request from headers already read off the wire.- Parameters:
in- the stream to parse the request headers from
Method Details
setNT
Set the NT header, naming the notification type being advertised.- Parameters:
value- the notification type, such as "upnp:rootdevice" or "ssdp:all"
getNT
setNTS
Set the NTS header, naming the notification sub type.- Parameters:
value- the notification sub type, either "ssdp:alive" or "ssdp:byebye"
getNTS
Return the NTS header.- Returns:
- the NTS header value, or empty string if not set
setLocation
Set the Location header, giving the URL of the device description document.- Parameters:
value- the URL of the device description document this request points at
getLocation
Return the Location header.- Returns:
- the Location header value, or empty string if not set
setUSN
Set the USN header, naming the service being notified.- Parameters:
value- the unique service name identifying the service being notified
getUSN
Return the USN header.- Returns:
- the USN header value, or empty string if not set
setLeaseTime
public void setLeaseTime(int len) Set the Cache-Control header, carrying this advertisement's max-age lease.- Parameters:
len- how many seconds this advertisement stays valid, written as max-age
getLeaseTime
public int getLeaseTime()Return the max-age lease carried by the Cache-Control header.- Returns:
- the max-age lease in seconds, or 0 if the header is absent or unparseable
setBootId
public void setBootId(int bootId) Set the BOOTID.UPNP.ORG header, recording the sender's boot generation.- Parameters:
bootId- the device boot ID, incremented on each reboot so stale advertisements are rejected
getBootId
public int getBootId()Return the BOOTID.UPNP.ORG header.- Returns:
- the BOOTID.UPNP.ORG value, or 0 if not set