Class 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 Detail

      • GatewayDevice

        public GatewayDevice()
        Creates a new instance of GatewayDevice
    • 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's location and parses the response using a GatewayDeviceHandler to populate the fields of this class

        Throws:
        org.xml.sax.SAXException - if an error occurs while parsing the request
        java.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 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:
        java.io.IOException - on communication errors
        org.xml.sax.SAXException - if errors occur while parsing the response
      • 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 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:
        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 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:
        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 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:
        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 port
        protocol - 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 the localAddress
        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