Example usage for java.net NetworkInterface getInetAddresses

List of usage examples for java.net NetworkInterface getInetAddresses

Introduction

In this page you can find the example usage for java.net NetworkInterface getInetAddresses.

Prototype

public Enumeration<InetAddress> getInetAddresses() 

Source Link

Document

Get an Enumeration with all or a subset of the InetAddresses bound to this network interface.

Usage

From source file:org.opendaylight.ovsdb.openstack.netvirt.impl.BridgeConfigurationManagerImpl.java

private String getControllerTarget() {
    /* TODO SB_MIGRATION
     * hardcoding value, need to find better way to get local ip
     *///from w  w w .  j a v  a  2  s . c  om
    //String target = "tcp:" + getControllerIPAddress() + ":" + getControllerOFPort();
    //TODO: dirty fix, need to remove it once we have proper solution
    String ipaddress = null;
    try {
        for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();) {
            NetworkInterface iface = (NetworkInterface) ifaces.nextElement();

            for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
                InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
                if (!inetAddr.isLoopbackAddress()) {
                    if (inetAddr.isSiteLocalAddress()) {
                        ipaddress = inetAddr.getHostAddress();
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.warn("ROYALLY SCREWED : Exception while fetching local host ip address ", e);
    }
    return "tcp:" + ipaddress + ":6633";
}

From source file:com.shreymalhotra.crazyflieserver.MainActivity.java

public String getLocalIpAddress() {
    try {/*from  ww w  .  j  av a  2  s  .c om*/
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                // if (!inetAddress.isLoopbackAddress() &&
                // !inetAddress.isLinkLocalAddress() &&
                // inetAddress.isSiteLocalAddress() ) {
                if (!inetAddress.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
                    String ipAddr = inetAddress.getHostAddress();
                    return ipAddr;
                }
            }
        }
    } catch (SocketException ex) {
        Log.d("CrazyFlieServer", ex.toString());
    }
    return null;
}

From source file:de.yaacc.upnp.server.contentdirectory.YaaccContentDirectory.java

/**
 * get the ip address of the device//from  w w w .j  ava2s  .com
 * 
 * @return the address or null if anything went wrong
 * 
 */
public String getIpAddress() {
    String hostAddress = null;
    try {
        for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                .getNetworkInterfaces(); networkInterfaces.hasMoreElements();) {
            NetworkInterface networkInterface = networkInterfaces.nextElement();
            for (Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); inetAddresses
                    .hasMoreElements();) {
                InetAddress inetAddress = inetAddresses.nextElement();
                if (!inetAddress.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {

                    hostAddress = inetAddress.getHostAddress();
                }

            }
        }
    } catch (SocketException se) {
        Log.d(YaaccUpnpServerService.class.getName(), "Error while retrieving network interfaces", se);
    }
    // maybe wifi is off we have to use the loopback device
    hostAddress = hostAddress == null ? "0.0.0.0" : hostAddress;
    return hostAddress;
}

From source file:sce.ElasticJob.java

public void sendEmail(JobExecutionContext context, String email) throws JobExecutionException {
    try {//ww w. j ava  2s  .  co  m
        Date d = new Date();
        String message = "Job was executed at: " + d.toString() + "\n";
        SchedulerMetaData schedulerMetadata = context.getScheduler().getMetaData();
        //Get the scheduler instance id
        message += "Scheduler Instance Id: " + schedulerMetadata.getSchedulerInstanceId() + "\n";
        //Get the scheduler name
        message += "Scheduler Name: " + schedulerMetadata.getSchedulerName() + "\n";
        try {
            //Get the scheduler ip
            Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces();
            message += "Scheduler IP: ";
            for (; n.hasMoreElements();) {
                NetworkInterface e = n.nextElement();
                //System.out.println("Interface: " + e.getName());
                Enumeration<InetAddress> a = e.getInetAddresses();
                for (; a.hasMoreElements();) {
                    InetAddress addr = a.nextElement();
                    message += !addr.getHostAddress().equals("127.0.0.1") ? addr.getHostAddress() + " " : "";
                }
            }
            message += "\n";
        } catch (SocketException e) {
            throw new JobExecutionException(e);
        }
        //Returns the result (if any) that the Job set before its execution completed (the type of object set as the result is entirely up to the particular job).
        //The result itself is meaningless to Quartz, but may be informative to JobListeners or TriggerListeners that are watching the job's execution. 
        message += "Result: "
                + (context.getResult() != null ? truncateResult((String) context.getResult()) : "") + "\n";
        //Get the unique Id that identifies this particular firing instance of the trigger that triggered this job execution. It is unique to this JobExecutionContext instance as well. 
        message += "Fire Instance Id: "
                + (context.getFireInstanceId() != null ? context.getFireInstanceId() : "") + "\n";
        //Get a handle to the Calendar referenced by the Trigger instance that fired the Job. 
        message += "Calendar: " + (context.getCalendar() != null ? context.getCalendar().getDescription() : "")
                + "\n";
        //The actual time the trigger fired. For instance the scheduled time may have been 10:00:00 but the actual fire time may have been 10:00:03 if the scheduler was too busy. 
        message += "Fire Time: " + (context.getFireTime() != null ? context.getFireTime() : "") + "\n";
        //the job name
        message += "Job Name: "
                + (context.getJobDetail().getKey() != null ? context.getJobDetail().getKey().getName() : "")
                + "\n";
        //the job group
        message += "Job Group: "
                + (context.getJobDetail().getKey() != null ? context.getJobDetail().getKey().getGroup() : "")
                + "\n";
        //The amount of time the job ran for (in milliseconds). The returned value will be -1 until the job has actually completed (or thrown an exception), and is therefore generally only useful to JobListeners and TriggerListeners.
        //message += "RunTime: " + context.getJobRunTime() + "\n";
        //the next fire time
        message += "Next Fire Time: "
                + (context.getNextFireTime() != null && context.getNextFireTime().toString() != null
                        ? context.getNextFireTime().toString()
                        : "")
                + "\n";
        //the previous fire time
        message += "Previous Fire Time: "
                + (context.getPreviousFireTime() != null && context.getPreviousFireTime().toString() != null
                        ? context.getPreviousFireTime().toString()
                        : "")
                + "\n";
        //refire count
        message += "Refire Count: " + context.getRefireCount() + "\n";

        //job data map
        message += "\nJob data map: \n";
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        for (Map.Entry<String, Object> entry : jobDataMap.entrySet()) {
            message += entry.getKey() + " = " + entry.getValue() + "\n";
        }
        Mail.sendMail("SCE notification", message, email, null, null);
    } catch (SchedulerException e) {
        throw new JobExecutionException(e);
    }
}

From source file:com.jagornet.dhcpv6.server.DhcpV6Server.java

private List<InetAddress> getAllIPv6Addrs() {
    List<InetAddress> ipAddrs = new ArrayList<InetAddress>();
    try {/*from w w  w . j av  a 2  s.c om*/
        Enumeration<NetworkInterface> localInterfaces = NetworkInterface.getNetworkInterfaces();
        if (localInterfaces != null) {
            while (localInterfaces.hasMoreElements()) {
                NetworkInterface netIf = localInterfaces.nextElement();
                Enumeration<InetAddress> ifAddrs = netIf.getInetAddresses();
                while (ifAddrs.hasMoreElements()) {
                    InetAddress ip = ifAddrs.nextElement();
                    if (ip instanceof Inet6Address) {
                        ipAddrs.add(ip);
                    }
                }
            }
        } else {
            log.error("No network interfaces found!");
        }
    } catch (IOException ex) {
        log.error("Failed to get IPv6 addresses: " + ex);
    }
    return ipAddrs;
}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobConfigurationService.java

/**
 * Interface method implementation./*from www  . j  a va  2  s .  co m*/
 * Also sets the hostName
 * @see JobConfigurationService#setPort(int)
 */
@Override
public void setPort(int port) {
    String hostName = "";
    String ipAddr = "";
    try {
        hostName = InetAddress.getLocalHost().getHostName();
        ipAddr = InetAddress.getLocalHost().getHostAddress();
        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
        //Iterate through all network interfaces
        while (nets.hasMoreElements()) {
            NetworkInterface netint = (NetworkInterface) nets.nextElement();
            Enumeration<InetAddress> ips = netint.getInetAddresses();
            //Iterate through all IP adddress
            while (ips.hasMoreElements()) {
                InetAddress ip = ips.nextElement();
                //Take the first address which isn't a loopback and is in the local address
                if (!ip.isLoopbackAddress() && ip.isSiteLocalAddress()) {
                    LOGGER.info("Host IP Address: " + ip.getHostAddress());
                    ipAddr = ip.getHostAddress();
                    break;
                }
            }
        }
    } catch (UnknownHostException e) {
        LOGGER.error("Error while getting hostName ", e);
    } catch (SocketException e) {
        LOGGER.error("Error while getting hostName ", e);
    }
    this.hostName = new JobHost(hostName, ipAddr, port);
}

From source file:uk.org.openseizuredetector.MainActivity.java

/** get the ip address of the phone.
 * Based on http://stackoverflow.com/questions/11015912/how-do-i-get-ip-address-in-ipv4-format
 *///  w w  w  .j a va 2  s  .co m
public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                //Log.v(TAG,"ip1--:" + inetAddress);
                //Log.v(TAG,"ip2--:" + inetAddress.getHostAddress());

                // for getting IPV4 format
                if (!inetAddress.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {

                    String ip = inetAddress.getHostAddress().toString();
                    //Log.v(TAG,"ip---::" + ip);
                    return ip;
                }
            }
        }
    } catch (Exception ex) {
        Log.e("IP Address", ex.toString());
    }
    return null;
}

From source file:nl.eduvpn.app.service.VPNService.java

/**
 * Retrieves the IP4 and IPv6 addresses assigned by the VPN server to this client using a network interface lookup.
 *
 * @return The IPv4 and IPv6 addresses in this order as a pair. If not found, a null value is returned instead.
 */// www . ja  va 2s  . co m
private Pair<String, String> _lookupVpnIpAddresses() {
    try {
        List<NetworkInterface> networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface networkInterface : networkInterfaces) {
            if (VPN_INTERFACE_NAME.equals(networkInterface.getName())) {
                List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses());
                String ipV4 = null;
                String ipV6 = null;
                for (InetAddress address : addresses) {
                    String ip = address.getHostAddress();
                    boolean isIPv4 = ip.indexOf(':') < 0;
                    if (isIPv4) {
                        ipV4 = ip;
                    } else {
                        int delimiter = ip.indexOf('%');
                        ipV6 = delimiter < 0 ? ip.toLowerCase() : ip.substring(0, delimiter).toLowerCase();
                    }
                }
                if (ipV4 != null || ipV6 != null) {
                    return new Pair<>(ipV4, ipV6);
                } else {
                    return null;
                }
            }
        }
    } catch (SocketException ex) {
        Log.w(TAG, "Unable to retrieve network interface info!", ex);
    }
    return null;
}

From source file:net.pms.newgui.NetworkTab.java

public JComponent build() {
    FormLayout layout = new FormLayout("left:pref, 2dlu, p, 2dlu , p, 2dlu, p, 2dlu, pref:grow",
            "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p,  3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.DLU4_BORDER);
    builder.setOpaque(true);/* w ww  . j  a va  2 s  .  co  m*/

    CellConstraints cc = new CellConstraints();

    smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3"));
    smcheckBox.setContentAreaFilled(false);
    smcheckBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setMinimized((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (PMS.getConfiguration().isMinimized()) {
        smcheckBox.setSelected(true);
    }

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(1, 1, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    builder.addLabel(Messages.getString("NetworkTab.0"), cc.xy(1, 7));
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
            new Object[] { "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "is", "it",
                    "ja", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv" },
            new Object[] { "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech",
                    "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Icelandic",
                    "Italian", "Japanese", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)",
                    "Romanian", "Russian", "Slovenian", "Spanish", "Swedish" });
    langs = new JComboBox(kcbm);
    langs.setEditable(false);
    //langs.setSelectedIndex(0);
    String defaultLang = null;
    if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) {
        defaultLang = configuration.getLanguage();
    } else {
        defaultLang = Locale.getDefault().getLanguage();
    }
    if (defaultLang == null) {
        defaultLang = "en";
    }
    kcbm.setSelectedKey(defaultLang);
    if (langs.getSelectedIndex() == -1) {
        langs.setSelectedIndex(0);
    }

    langs.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setLanguage((String) kcbm.getSelectedKey());

            }
        }
    });
    builder.add(langs, cc.xyw(3, 7, 7));

    builder.add(smcheckBox, cc.xyw(1, 9, 9));

    JButton service = new JButton(Messages.getString("NetworkTab.4"));
    service.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.get().installWin32Service()) {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"),
                        "Information", JOptionPane.INFORMATION_MESSAGE);

            } else {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.14"), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    builder.add(service, cc.xy(1, 11));
    if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        service.setEnabled(false);
    }

    host = new JTextField(PMS.getConfiguration().getServerHostname());
    host.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setHostname(host.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });
    // host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
    port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : "");
    port.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                String p = port.getText();
                if (StringUtils.isEmpty(p)) {
                    p = "5001";
                }
                int ab = Integer.parseInt(p);
                configuration.setServerPort(ab);
                PMS.get().getFrame().setReloadable(true);
            } catch (NumberFormatException nfe) {
            }

        }
    });

    cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), cc.xyw(1, 21, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    ArrayList<String> names = new ArrayList<String>();
    names.add("");
    ArrayList<String> interfaces = new ArrayList<String>();
    interfaces.add("");
    Enumeration<NetworkInterface> enm;
    try {
        enm = NetworkInterface.getNetworkInterfaces();
        while (enm.hasMoreElements()) {
            NetworkInterface ni = enm.nextElement();
            // check for interface has at least one ip address.
            if (ni.getInetAddresses().hasMoreElements()) {
                names.add(ni.getName());
                String displayName = ni.getDisplayName();
                if (displayName == null) {
                    displayName = ni.getName();
                }
                interfaces.add(displayName.trim());
            }
        }
    } catch (SocketException e1) {
        logger.error(null, e1);
    }

    final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(names.toArray(), interfaces.toArray());
    networkinterfacesCBX = new JComboBox(networkInterfaces);
    networkInterfaces.setSelectedKey(configuration.getNetworkInterface());
    networkinterfacesCBX.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey());
                //host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
                PMS.get().getFrame().setReloadable(true);
            }
        }
    });

    ip_filter = new JTextField(PMS.getConfiguration().getIpFilter());
    ip_filter.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setIpFilter(ip_filter.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });

    builder.addLabel(Messages.getString("NetworkTab.20"), cc.xy(1, 23));
    builder.add(networkinterfacesCBX, cc.xyw(3, 23, 7));
    builder.addLabel(Messages.getString("NetworkTab.23"), cc.xy(1, 25));
    builder.add(host, cc.xyw(3, 25, 7));
    builder.addLabel(Messages.getString("NetworkTab.24"), cc.xy(1, 27));
    builder.add(port, cc.xyw(3, 27, 7));
    builder.addLabel(Messages.getString("NetworkTab.30"), cc.xy(1, 29));
    builder.add(ip_filter, cc.xyw(3, 29, 7));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), cc.xyw(1, 31, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32"));
    newHTTPEngine.setSelected(PMS.getConfiguration().isHTTPEngineV2());
    newHTTPEngine.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(newHTTPEngine, cc.xyw(1, 33, 9));

    preventSleep = new JCheckBox(Messages.getString("NetworkTab.33"));
    preventSleep.setSelected(PMS.getConfiguration().isPreventsSleep());
    preventSleep.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(preventSleep, cc.xyw(1, 35, 9));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), cc.xyw(1, 37, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    JPanel panel = builder.getPanel();
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    return scrollPane;
}

From source file:org.exoplatform.outlook.jcr.ContentLink.java

/**
 * Instantiates a new content link./*from  ww  w  . j ava 2s  .c  o m*/
 *
 * @param jcrService the jcr service
 * @param sessionProviders the session providers
 * @param finder the finder
 * @param organization the organization
 * @param identityRegistry the identity registry
 * @param cacheService the cache service
 * @param params the params
 * @throws ConfigurationException the configuration exception
 */
public ContentLink(RepositoryService jcrService, SessionProviderService sessionProviders, NodeFinder finder,
        OrganizationService organization, IdentityRegistry identityRegistry, CacheService cacheService,
        InitParams params) throws ConfigurationException {
    this.jcrService = jcrService;
    this.sessionProviders = sessionProviders;
    this.finder = finder;
    this.organization = organization;
    this.identityRegistry = identityRegistry;

    this.activeLinks = cacheService.getCacheInstance(LINK_CACHE_NAME);

    if (params != null) {
        PropertiesParam param = params.getPropertiesParam("link-configuration");
        if (param != null) {
            config = Collections.unmodifiableMap(param.getProperties());
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Property parameters link-configuration not found, will use default settings.");
            }
            config = Collections.<String, String>emptyMap();
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Component configuration not found, will use default settings.");
        }
        config = Collections.<String, String>emptyMap();
    }

    StringBuilder restUrl = new StringBuilder();
    String exoBaseUrl = System.getProperty(EXO_BASE_URL);
    if (exoBaseUrl == null || exoBaseUrl.toUpperCase().toLowerCase().startsWith("http://localhost")) {
        // seems we have base URL not set explicitly for the server
        String schema = config.get(CONFIG_SCHEMA);
        if (schema == null || (schema = schema.trim()).length() == 0) {
            schema = "http";
        }

        String host = config.get(CONFIG_HOST);
        if (host == null || host.trim().length() == 0) {
            host = null;
            try {
                Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
                while (host == null && interfaces.hasMoreElements()) {
                    NetworkInterface nic = interfaces.nextElement();
                    Enumeration<InetAddress> addresses = nic.getInetAddresses();
                    while (host == null && addresses.hasMoreElements()) {
                        InetAddress address = addresses.nextElement();
                        if (!address.isLoopbackAddress()) {
                            host = address.getHostName();
                        }
                    }
                }
            } catch (SocketException e) {
                // cannot get net interfaces
            }

            if (host == null) {
                try {
                    host = InetAddress.getLocalHost().getHostName();
                } catch (UnknownHostException e) {
                    host = "localhost:8080"; // assume development environment otherwise
                }
            }
        }
        restUrl.append(schema);
        restUrl.append("://");
        restUrl.append(host);
    } else {
        restUrl.append(exoBaseUrl);
    }

    restUrl.append('/');
    restUrl.append(PortalContainer.getCurrentPortalContainerName());
    restUrl.append('/');
    restUrl.append(PortalContainer.getCurrentRestContextName());
    this.restUrl = restUrl.toString();

    LOG.info("Default service URL for content links is " + this.restUrl);
}