Package org.bitlet.weupnp
Class GatewayDevice
- java.lang.Object
-
- org.bitlet.weupnp.GatewayDevice
-
public class GatewayDevice extends java.lang.ObjectA 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 booleanaddPortMapping(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.booleandeletePortMapping(int externalPort, java.lang.String protocol)Deletes the port mapping associated to externalPort and protocoljava.lang.StringgetControlURL()java.lang.StringgetControlURLCIF()java.lang.StringgetDeviceType()java.lang.StringgetDeviceTypeCIF()java.lang.StringgetEventSubURL()java.lang.StringgetEventSubURLCIF()java.lang.StringgetExternalIPAddress()Retrieves the external IP address associated with this devicejava.lang.StringgetFriendlyName()booleangetGenericPortMappingEntry(int index, PortMappingEntry portMappingEntry)Returns a specific port mapping entry, depending on a the supplied index.static intgetHttpReadTimeout()Gets the timeout for actions on the device.java.net.InetAddressgetLocalAddress()Gets the local address to connect the gateway throughjava.lang.StringgetLocation()java.lang.StringgetManufacturer()java.lang.StringgetModelDescription()java.lang.StringgetModelName()java.lang.StringgetModelNumber()java.lang.IntegergetPortMappingNumberOfEntries()Retrieves the number of port mappings that are registered on the GatewayDevice.java.lang.StringgetPresentationURL()java.lang.StringgetSCPDURL()java.lang.StringgetSCPDURLCIF()java.lang.StringgetServiceType()java.lang.StringgetServiceTypeCIF()booleangetSpecificPortMappingEntry(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.StringgetSt()java.lang.StringgetURLBase()booleanisConnected()Retrieves the connection status of this devicevoidloadDescription()Retrieves the properties and description of the GatewayDevice.voidsetControlURL(java.lang.String controlURL)voidsetControlURLCIF(java.lang.String controlURLCIF)voidsetDeviceType(java.lang.String deviceType)voidsetDeviceTypeCIF(java.lang.String deviceTypeCIF)voidsetEventSubURL(java.lang.String eventSubURL)voidsetEventSubURLCIF(java.lang.String eventSubURLCIF)voidsetFriendlyName(java.lang.String friendlyName)static voidsetHttpReadTimeout(int milliseconds)Sets the timeout for actions on the device.voidsetLocalAddress(java.net.InetAddress localAddress)Sets thelocalAddressvoidsetLocation(java.lang.String location)voidsetManufacturer(java.lang.String manufacturer)voidsetModelDescription(java.lang.String modelDescription)voidsetModelName(java.lang.String modelName)voidsetModelNumber(java.lang.String modelNumber)voidsetPresentationURL(java.lang.String presentationURL)voidsetSCPDURL(java.lang.String sCPDURL)voidsetSCPDURLCIF(java.lang.String sCPDURLCIF)voidsetServiceType(java.lang.String serviceType)voidsetServiceTypeCIF(java.lang.String serviceTypeCIF)voidsetSt(java.lang.String st)voidsetURLBase(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.IOExceptionRetrieves the properties and description of the GatewayDevice. Connects to the device'slocationand parses the response using aGatewayDeviceHandlerto 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.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:
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.SAXExceptionRetrieves the connection status of this device- Returns:
- true if connected, false otherwise
- Throws:
java.io.IOExceptionorg.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.SAXExceptionRetrieves 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.IOExceptionorg.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.SAXExceptionAdds 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.IOExceptionorg.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.SAXExceptionQueries 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.IOExceptionorg.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.SAXExceptionReturns 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.IOExceptionorg.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.SAXExceptionRetrieves the number of port mappings that are registered on the GatewayDevice.- Returns:
- the number of port mappings
- Throws:
java.io.IOExceptionorg.xml.sax.SAXException
-
deletePortMapping
public boolean deletePortMapping(int externalPort, java.lang.String protocol) throws java.io.IOException, org.xml.sax.SAXExceptionDeletes the port mapping associated to externalPort and protocol- Parameters:
externalPort- the external portprotocol- the protocol- Returns:
- true if removal was successful
- Throws:
java.io.IOExceptionorg.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
-
-