package com.microservices.dms.utils;

import com.microservices.common.core.utils.StringUtils;

import java.net.MalformedURLException;
import java.net.URL;

public class UrlUtil {

    public static String getUrlPath(String urlString) {
        if (StringUtils.isEmpty(urlString)) {
            return "";
        }

        URL url;
        try {
            url = new URL(urlString);
        } catch (MalformedURLException e) {
            return "";
        }
        return url.getPath();
    }


    public static String replaceUrlIp(String urlString,String newIp) {

        urlString = getUrlPath(urlString);

        if (StringUtils.isEmpty(urlString) || StringUtils.isEmpty(newIp)) {
            return "";
        }


        return newIp + urlString;
    }
}
