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 TypeMethodDescriptionbooleanaddPortMapping(int externalPort, int internalPort, String internalClient, String protocol, String description) Adds a new port mapping to the GatewayDevices using the supplied parameters.booleandeletePortMapping(int externalPort, String protocol) Deletes the port mapping associated to externalPort and protocolRetrieves the external IP address associated with this devicebooleangetGenericPortMappingEntry(int index, PortMappingEntry portMappingEntry) Returns a specific port mapping entry, depending on a the supplied index.static intGets 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.booleangetSpecificPortMappingEntry(int externalPort, String protocol, PortMappingEntry portMappingEntry) Queries the GatewayDevice to retrieve a specific port mapping entry, corresponding to specified criteria, if present.getSt()booleanRetrieves the connection status of this devicevoidRetrieves the properties and description of the GatewayDevice.voidsetControlURL(String controlURL) voidsetControlURLCIF(String controlURLCIF) voidsetDeviceType(String deviceType) voidsetDeviceTypeCIF(String deviceTypeCIF) voidsetEventSubURL(String eventSubURL) voidsetEventSubURLCIF(String eventSubURLCIF) voidsetFriendlyName(String friendlyName) static voidsetHttpReadTimeout(int milliseconds) Sets the timeout for actions on the device.voidsetLocalAddress(InetAddress localAddress) Sets thelocalAddressvoidsetLocation(String location) voidsetManufacturer(String manufacturer) voidsetModelDescription(String modelDescription) voidsetModelName(String modelName) voidsetModelNumber(String modelNumber) voidsetPresentationURL(String presentationURL) voidsetSCPDURL(String sCPDURL) voidsetSCPDURLCIF(String sCPDURLCIF) voidsetServiceType(String serviceType) voidsetServiceTypeCIF(String serviceTypeCIF) voidvoidsetURLBase(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'slocationand parses the response using aGatewayDeviceHandlerto 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:
IOExceptionSAXException- 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:
IOExceptionSAXException- 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:
IOExceptionSAXException- 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:
IOExceptionSAXException- 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:
IOExceptionSAXException- See Also:
-
getPortMappingNumberOfEntries
Retrieves the number of port mappings that are registered on the GatewayDevice.- Returns:
- the number of port mappings
- Throws:
IOExceptionSAXException
-
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:
IOExceptionSAXException
-
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
-