Package org.bitlet.weupnp
Class GatewayDevice
- java.lang.Object
-
- org.bitlet.weupnp.GatewayDevice
-
public class GatewayDevice extends java.lang.Object
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 Constructor Description GatewayDevice()
Creates a new instance of GatewayDevice
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addPortMapping(int externalPort, int internalPort, java.lang.String internalClient, java.lang.String protocol, java.lang.String description)
Adds a new port mapping to the GatewayDevices using the supplied parameters.boolean
deletePortMapping(int externalPort, java.lang.String protocol)
Deletes the port mapping associated to externalPort and protocoljava.lang.String
getControlURL()
java.lang.String
getControlURLCIF()
java.lang.String
getDeviceType()
java.lang.String
getDeviceTypeCIF()
java.lang.String
getEventSubURL()
java.lang.String
getEventSubURLCIF()
java.lang.String
getExternalIPAddress()
Retrieves the external IP address associated with this devicejava.lang.String
getFriendlyName()
boolean
getGenericPortMappingEntry(int index, PortMappingEntry portMappingEntry)
Returns a specific port mapping entry, depending on a the supplied index.static int
getHttpReadTimeout()
Gets the timeout for actions on the device.java.net.InetAddress
getLocalAddress()
Gets the local address to connect the gateway throughjava.lang.String
getLocation()
java.lang.String
getManufacturer()
java.lang.String
getModelDescription()
java.lang.String
getModelName()
java.lang.String
getModelNumber()
java.lang.Integer
getPortMappingNumberOfEntries()
Retrieves the number of port mappings that are registered on the GatewayDevice.java.lang.String
getPresentationURL()
java.lang.String
getSCPDURL()
java.lang.String
getSCPDURLCIF()
java.lang.String
getServiceType()
java.lang.String
getServiceTypeCIF()
boolean
getSpecificPortMappingEntry(int externalPort, java.lang.String protocol, PortMappingEntry portMappingEntry)
Queries the GatewayDevice to retrieve a specific port mapping entry, corresponding to specified criteria, if present.java.lang.String
getSt()
java.lang.String
getURLBase()
boolean
isConnected()
Retrieves the connection status of this devicevoid
loadDescription()
Retrieves the properties and description of the GatewayDevice.void
setControlURL(java.lang.String controlURL)
void
setControlURLCIF(java.lang.String controlURLCIF)
void
setDeviceType(java.lang.String deviceType)
void
setDeviceTypeCIF(java.lang.String deviceTypeCIF)
void
setEventSubURL(java.lang.String eventSubURL)
void
setEventSubURLCIF(java.lang.String eventSubURLCIF)
void
setFriendlyName(java.lang.String friendlyName)
static void
setHttpReadTimeout(int milliseconds)
Sets the timeout for actions on the device.void
setLocalAddress(java.net.InetAddress localAddress)
Sets thelocalAddress
void
setLocation(java.lang.String location)
void
setManufacturer(java.lang.String manufacturer)
void
setModelDescription(java.lang.String modelDescription)
void
setModelName(java.lang.String modelName)
void
setModelNumber(java.lang.String modelNumber)
void
setPresentationURL(java.lang.String presentationURL)
void
setSCPDURL(java.lang.String sCPDURL)
void
setSCPDURLCIF(java.lang.String sCPDURLCIF)
void
setServiceType(java.lang.String serviceType)
void
setServiceTypeCIF(java.lang.String serviceTypeCIF)
void
setSt(java.lang.String st)
void
setURLBase(java.lang.String uRLBase)
static java.util.Map<java.lang.String,java.lang.String>
simpleUPnPcommand(java.lang.String url, java.lang.String service, java.lang.String action, java.util.Map<java.lang.String,java.lang.String> args)
Issues UPnP commands to a GatewayDevice that can be reached at the specified url
-
-
-
Method Detail
-
loadDescription
public void loadDescription() throws org.xml.sax.SAXException, java.io.IOException
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:
org.xml.sax.SAXException
- if an error occurs while parsing the requestjava.io.IOException
- on communication errors- See Also:
GatewayDeviceHandler
-
simpleUPnPcommand
public static java.util.Map<java.lang.String,java.lang.String> simpleUPnPcommand(java.lang.String url, java.lang.String service, java.lang.String action, java.util.Map<java.lang.String,java.lang.String> args) throws java.io.IOException, org.xml.sax.SAXException
Issues 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:
java.io.IOException
- on communication errorsorg.xml.sax.SAXException
- if errors occur while parsing the response
-
isConnected
public boolean isConnected() throws java.io.IOException, org.xml.sax.SAXException
Retrieves the connection status of this device- Returns:
- true if connected, false otherwise
- Throws:
java.io.IOException
org.xml.sax.SAXException
- See Also:
simpleUPnPcommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
-
getExternalIPAddress
public java.lang.String getExternalIPAddress() throws java.io.IOException, org.xml.sax.SAXException
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:
java.io.IOException
org.xml.sax.SAXException
- See Also:
simpleUPnPcommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
-
addPortMapping
public boolean addPortMapping(int externalPort, int internalPort, java.lang.String internalClient, java.lang.String protocol, java.lang.String description) throws java.io.IOException, org.xml.sax.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:
java.io.IOException
org.xml.sax.SAXException
- See Also:
simpleUPnPcommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
,PortMappingEntry
-
getSpecificPortMappingEntry
public boolean getSpecificPortMappingEntry(int externalPort, java.lang.String protocol, PortMappingEntry portMappingEntry) throws java.io.IOException, org.xml.sax.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:
java.io.IOException
org.xml.sax.SAXException
- See Also:
simpleUPnPcommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
,PortMappingEntry
-
getGenericPortMappingEntry
public boolean getGenericPortMappingEntry(int index, PortMappingEntry portMappingEntry) throws java.io.IOException, org.xml.sax.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:
java.io.IOException
org.xml.sax.SAXException
- See Also:
simpleUPnPcommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
,PortMappingEntry
-
getPortMappingNumberOfEntries
public java.lang.Integer getPortMappingNumberOfEntries() throws java.io.IOException, org.xml.sax.SAXException
Retrieves the number of port mappings that are registered on the GatewayDevice.- Returns:
- the number of port mappings
- Throws:
java.io.IOException
org.xml.sax.SAXException
-
deletePortMapping
public boolean deletePortMapping(int externalPort, java.lang.String protocol) throws java.io.IOException, org.xml.sax.SAXException
Deletes the port mapping associated to externalPort and protocol- Parameters:
externalPort
- the external portprotocol
- the protocol- Returns:
- true if removal was successful
- Throws:
java.io.IOException
org.xml.sax.SAXException
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Gets the local address to connect the gateway through- Returns:
- the
localAddress
-
setLocalAddress
public void setLocalAddress(java.net.InetAddress localAddress)
Sets thelocalAddress
- Parameters:
localAddress
- the address to set
-
getSt
public java.lang.String getSt()
-
setSt
public void setSt(java.lang.String st)
-
getLocation
public java.lang.String getLocation()
-
setLocation
public void setLocation(java.lang.String location)
-
getServiceType
public java.lang.String getServiceType()
-
setServiceType
public void setServiceType(java.lang.String serviceType)
-
getServiceTypeCIF
public java.lang.String getServiceTypeCIF()
-
setServiceTypeCIF
public void setServiceTypeCIF(java.lang.String serviceTypeCIF)
-
getControlURL
public java.lang.String getControlURL()
-
setControlURL
public void setControlURL(java.lang.String controlURL)
-
getControlURLCIF
public java.lang.String getControlURLCIF()
-
setControlURLCIF
public void setControlURLCIF(java.lang.String controlURLCIF)
-
getEventSubURL
public java.lang.String getEventSubURL()
-
setEventSubURL
public void setEventSubURL(java.lang.String eventSubURL)
-
getEventSubURLCIF
public java.lang.String getEventSubURLCIF()
-
setEventSubURLCIF
public void setEventSubURLCIF(java.lang.String eventSubURLCIF)
-
getSCPDURL
public java.lang.String getSCPDURL()
-
setSCPDURL
public void setSCPDURL(java.lang.String sCPDURL)
-
getSCPDURLCIF
public java.lang.String getSCPDURLCIF()
-
setSCPDURLCIF
public void setSCPDURLCIF(java.lang.String sCPDURLCIF)
-
getDeviceType
public java.lang.String getDeviceType()
-
setDeviceType
public void setDeviceType(java.lang.String deviceType)
-
getDeviceTypeCIF
public java.lang.String getDeviceTypeCIF()
-
setDeviceTypeCIF
public void setDeviceTypeCIF(java.lang.String deviceTypeCIF)
-
getURLBase
public java.lang.String getURLBase()
-
setURLBase
public void setURLBase(java.lang.String uRLBase)
-
getFriendlyName
public java.lang.String getFriendlyName()
-
setFriendlyName
public void setFriendlyName(java.lang.String friendlyName)
-
getManufacturer
public java.lang.String getManufacturer()
-
setManufacturer
public void setManufacturer(java.lang.String manufacturer)
-
getModelDescription
public java.lang.String getModelDescription()
-
setModelDescription
public void setModelDescription(java.lang.String modelDescription)
-
getPresentationURL
public java.lang.String getPresentationURL()
-
setPresentationURL
public void setPresentationURL(java.lang.String presentationURL)
-
getModelName
public java.lang.String getModelName()
-
setModelName
public void setModelName(java.lang.String modelName)
-
getModelNumber
public java.lang.String getModelNumber()
-
setModelNumber
public void setModelNumber(java.lang.String modelNumber)
-
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
-
-