Class GatewayDevice

java.lang.Object
org.bitlet.weupnp.GatewayDevice

public class GatewayDevice extends 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 Details

    • GatewayDevice

      public GatewayDevice()
      Creates a new instance of GatewayDevice
  • Method Details

    • loadDescription

      public void loadDescription() throws SAXException, IOException
      Retrieves the properties and description of the GatewayDevice.

      Connects to the device's location and parses the response using a GatewayDeviceHandler to populate the fields of this class

      Throws:
      SAXException - if an error occurs while parsing the request
      IOException - on communication errors
      See Also:
    • simpleUPnPcommand

      public static Map<String,String> simpleUPnPcommand(String url, String service, String action, Map<String,String> args) throws IOException, 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 device
      service - the service to invoke
      action - the specific action to perform
      args - 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 errors
      SAXException - if errors occur while parsing the response
    • isConnected

      public boolean isConnected() throws IOException, SAXException
      Retrieves the connection status of this device
      Returns:
      true if connected, false otherwise
      Throws:
      IOException
      SAXException
      See Also:
    • getExternalIPAddress

      public String getExternalIPAddress() throws IOException, 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:
      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 mapping
      internalPort - the internal port associated with the new mapping
      internalClient - the internal client associated with the new mapping
      protocol - the protocol associated with the new mapping
      description - 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 port
      protocol - 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 mapping
      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:
    • getPortMappingNumberOfEntries

      public Integer getPortMappingNumberOfEntries() throws IOException, SAXException
      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 port
      protocol - the protocol
      Returns:
      true if removal was successful
      Throws:
      IOException
      SAXException
    • getLocalAddress

      public InetAddress getLocalAddress()
      Gets the local address to connect the gateway through
      Returns:
      the localAddress
    • setLocalAddress

      public void setLocalAddress(InetAddress localAddress)
      Sets the localAddress
      Parameters:
      localAddress - the address to set
    • getSt

      public String getSt()
    • setSt

      public void setSt(String st)
    • getLocation

      public String getLocation()
    • setLocation

      public void setLocation(String location)
    • getServiceType

      public String getServiceType()
    • setServiceType

      public void setServiceType(String serviceType)
    • getServiceTypeCIF

      public String getServiceTypeCIF()
    • setServiceTypeCIF

      public void setServiceTypeCIF(String serviceTypeCIF)
    • getControlURL

      public String getControlURL()
    • setControlURL

      public void setControlURL(String controlURL)
    • getControlURLCIF

      public String getControlURLCIF()
    • setControlURLCIF

      public void setControlURLCIF(String controlURLCIF)
    • getEventSubURL

      public String getEventSubURL()
    • setEventSubURL

      public void setEventSubURL(String eventSubURL)
    • getEventSubURLCIF

      public String getEventSubURLCIF()
    • setEventSubURLCIF

      public void setEventSubURLCIF(String eventSubURLCIF)
    • getSCPDURL

      public String getSCPDURL()
    • setSCPDURL

      public void setSCPDURL(String sCPDURL)
    • getSCPDURLCIF

      public String getSCPDURLCIF()
    • setSCPDURLCIF

      public void setSCPDURLCIF(String sCPDURLCIF)
    • getDeviceType

      public String getDeviceType()
    • setDeviceType

      public void setDeviceType(String deviceType)
    • getDeviceTypeCIF

      public String getDeviceTypeCIF()
    • setDeviceTypeCIF

      public void setDeviceTypeCIF(String deviceTypeCIF)
    • getURLBase

      public String getURLBase()
    • setURLBase

      public void setURLBase(String uRLBase)
    • getFriendlyName

      public String getFriendlyName()
    • setFriendlyName

      public void setFriendlyName(String friendlyName)
    • getManufacturer

      public String getManufacturer()
    • setManufacturer

      public void setManufacturer(String manufacturer)
    • getModelDescription

      public String getModelDescription()
    • setModelDescription

      public void setModelDescription(String modelDescription)
    • getPresentationURL

      public String getPresentationURL()
    • setPresentationURL

      public void setPresentationURL(String presentationURL)
    • getModelName

      public String getModelName()
    • setModelName

      public void setModelName(String modelName)
    • getModelNumber

      public String getModelNumber()
    • setModelNumber

      public void setModelNumber(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