Package org.bitlet.weupnp
Class GatewayDevice
java.lang.Object
org.bitlet.weupnp.GatewayDevice
A GatewayDevice is a class that abstracts UPnP-compliant gateways
It holds all the information that comes back as UPnP responses, and
provides methods to issue UPnP commands to a gateway.
- Author:
- casta
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addPortMapping
(int externalPort, int internalPort, String internalClient, String protocol, String description) Adds a new port mapping to the GatewayDevices using the supplied parameters.boolean
deletePortMapping
(int externalPort, String protocol) Deletes the port mapping associated to externalPort and protocolRetrieves the external IP address associated with this deviceboolean
getGenericPortMappingEntry
(int index, PortMappingEntry portMappingEntry) Returns a specific port mapping entry, depending on a the supplied index.static int
Gets the timeout for actions on the device.Gets the local address to connect the gateway throughRetrieves the number of port mappings that are registered on the GatewayDevice.boolean
getSpecificPortMappingEntry
(int externalPort, String protocol, PortMappingEntry portMappingEntry) Queries the GatewayDevice to retrieve a specific port mapping entry, corresponding to specified criteria, if present.getSt()
boolean
Retrieves the connection status of this devicevoid
Retrieves the properties and description of the GatewayDevice.void
setControlURL
(String controlURL) void
setControlURLCIF
(String controlURLCIF) void
setDeviceType
(String deviceType) void
setDeviceTypeCIF
(String deviceTypeCIF) void
setEventSubURL
(String eventSubURL) void
setEventSubURLCIF
(String eventSubURLCIF) void
setFriendlyName
(String friendlyName) static void
setHttpReadTimeout
(int milliseconds) Sets the timeout for actions on the device.void
setLocalAddress
(InetAddress localAddress) Sets thelocalAddress
void
setLocation
(String location) void
setManufacturer
(String manufacturer) void
setModelDescription
(String modelDescription) void
setModelName
(String modelName) void
setModelNumber
(String modelNumber) void
setPresentationURL
(String presentationURL) void
setSCPDURL
(String sCPDURL) void
setSCPDURLCIF
(String sCPDURLCIF) void
setServiceType
(String serviceType) void
setServiceTypeCIF
(String serviceTypeCIF) void
void
setURLBase
(String uRLBase) Issues UPnP commands to a GatewayDevice that can be reached at the specified url
-
Constructor Details
-
GatewayDevice
public GatewayDevice()Creates a new instance of GatewayDevice
-
-
Method Details
-
loadDescription
Retrieves the properties and description of the GatewayDevice. Connects to the device'slocation
and parses the response using aGatewayDeviceHandler
to populate the fields of this class- Throws:
SAXException
- if an error occurs while parsing the requestIOException
- on communication errors- See Also:
-
simpleUPnPcommand
public static Map<String,String> simpleUPnPcommand(String url, String service, String action, Map<String, String> args) throws IOException, SAXExceptionIssues UPnP commands to a GatewayDevice that can be reached at the specified url The command is identified by a service and an action and can receive arguments- Parameters:
url
- the url to use to contact the deviceservice
- the service to invokeaction
- the specific action to performargs
- the command arguments- Returns:
- the response to the performed command, as a name-value map. In case errors occur, the returned map will be empty.
- Throws:
IOException
- on communication errorsSAXException
- if errors occur while parsing the response
-
isConnected
Retrieves the connection status of this device- Returns:
- true if connected, false otherwise
- Throws:
IOException
SAXException
- See Also:
-
getExternalIPAddress
Retrieves the external IP address associated with this device The external address is the address that can be used to connect to the GatewayDevice from the external network- Returns:
- the external IP
- Throws:
IOException
SAXException
- See Also:
-
addPortMapping
public boolean addPortMapping(int externalPort, int internalPort, String internalClient, String protocol, String description) throws IOException, SAXException Adds a new port mapping to the GatewayDevices using the supplied parameters.- Parameters:
externalPort
- the external associated with the new mappinginternalPort
- the internal port associated with the new mappinginternalClient
- the internal client associated with the new mappingprotocol
- the protocol associated with the new mappingdescription
- the mapping description- Returns:
- true if the mapping was successfully added, false otherwise
- Throws:
IOException
SAXException
- See Also:
-
getSpecificPortMappingEntry
public boolean getSpecificPortMappingEntry(int externalPort, String protocol, PortMappingEntry portMappingEntry) throws IOException, SAXException Queries the GatewayDevice to retrieve a specific port mapping entry, corresponding to specified criteria, if present. Retrieves the PortMappingEntry associated with externalPort and protocol, if present.- Parameters:
externalPort
- the external portprotocol
- the protocol (TCP or UDP)portMappingEntry
- the entry containing the details, in any is present, null otherwise. (used as return value)- Returns:
- true if a valid mapping is found
- Throws:
IOException
SAXException
- See Also:
-
getGenericPortMappingEntry
public boolean getGenericPortMappingEntry(int index, PortMappingEntry portMappingEntry) throws IOException, SAXException Returns a specific port mapping entry, depending on a the supplied index.- Parameters:
index
- the index of the desired port mappingportMappingEntry
- the entry containing the details, in any is present, null otherwise. (used as return value)- Returns:
- true if a valid mapping is found
- Throws:
IOException
SAXException
- See Also:
-
getPortMappingNumberOfEntries
Retrieves the number of port mappings that are registered on the GatewayDevice.- Returns:
- the number of port mappings
- Throws:
IOException
SAXException
-
deletePortMapping
public boolean deletePortMapping(int externalPort, String protocol) throws IOException, SAXException Deletes the port mapping associated to externalPort and protocol- Parameters:
externalPort
- the external portprotocol
- the protocol- Returns:
- true if removal was successful
- Throws:
IOException
SAXException
-
getLocalAddress
Gets the local address to connect the gateway through- Returns:
- the
localAddress
-
setLocalAddress
Sets thelocalAddress
- Parameters:
localAddress
- the address to set
-
getSt
-
setSt
-
getLocation
-
setLocation
-
getServiceType
-
setServiceType
-
getServiceTypeCIF
-
setServiceTypeCIF
-
getControlURL
-
setControlURL
-
getControlURLCIF
-
setControlURLCIF
-
getEventSubURL
-
setEventSubURL
-
getEventSubURLCIF
-
setEventSubURLCIF
-
getSCPDURL
-
setSCPDURL
-
getSCPDURLCIF
-
setSCPDURLCIF
-
getDeviceType
-
setDeviceType
-
getDeviceTypeCIF
-
setDeviceTypeCIF
-
getURLBase
-
setURLBase
-
getFriendlyName
-
setFriendlyName
-
getManufacturer
-
setManufacturer
-
getModelDescription
-
setModelDescription
-
getPresentationURL
-
setPresentationURL
-
getModelName
-
setModelName
-
getModelNumber
-
setModelNumber
-
getHttpReadTimeout
public static int getHttpReadTimeout()Gets the timeout for actions on the device.- Returns:
- timeout in milliseconds
-
setHttpReadTimeout
public static void setHttpReadTimeout(int milliseconds) Sets the timeout for actions on the device.- Parameters:
milliseconds
- the new timeout in milliseconds
-