@@ -0,0 +1,2735 @@
+/*%0A * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.wso2.carbon.uis.internal.http.util;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.net.Inet4Address;%0Aimport java.net.InetAddress;%0Aimport java.net.NetworkInterface;%0Aimport java.net.SocketException;%0Aimport java.util.Enumeration;%0Aimport java.util.Optional;%0A%0A/**%0A * Utility functions for Internet Protocol  addresses.%0A *%0A * @since 0.18.0%0A */%0Apublic class IpAddressUtils %7B%0A%0A    private static final Logger LOGGER = LoggerFactory.getLogger(IpAddressUtils.class);%0A    private static String localInternetAddress;%0A%0A    /**%0A     * Returns Internet Protocol version 4 (IPv4) address of this computer.%0A     *%0A     * @return IP address of this computer%0A     */%0A    public static Optional%3CString%3E getLocalIpAddress() %7B%0A        if (localInternetAddress != null) %7B%0A            return Optional.of(localInternetAddress);%0A        %7D%0A%0A        try %7B%0A            Enumeration%3CNetworkInterface%3E networkInterfaces = NetworkInterface.getNetworkInterfaces();%0A            outer_loop:%0A            while (networkInterfaces.hasMoreElements()) %7B%0A                NetworkInterface networkInterface = networkInterfaces.nextElement();%0A                if (!networkInterface.isUp() %7C%7C networkInterface.isLoopback() %7C%7C networkInterface.isVirtual()) %7B%0A                    continue;%0A                %7D%0A%0A                Enumeration%3CInetAddress%3E inetAddresses = networkInterface.getInetAddresses();%0A                while (inetAddresses.hasMoreElements()) %7B%0A                    InetAddress inetAddress = inetAddresses.nextElement();%0A                    if ((inetAddress instanceof Inet4Address) && !inetAddress.isLoopbackAddress()) %7B%0A                        localInternetAddress = inetAddress.getHostAddress();%0A                        break outer_loop;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D catch (SocketException e) %7B%0A            // Log level DEBUG since this is not a 'breaking' error.%0A            LOGGER.debug(%22Cannot access information on network interfaces.%22, e);%0A        %7D%0A        return Optional.ofNullable(localInternetAddress);%0A    %7D%0A%7D%0A

add IpAddressUtils class