package com.eactive.eai.util; import java.net.MalformedURLException; import java.net.URL; public class UrlUtil { public static String replaceIpAddress(String httpUrl, String newIp, String newPort) { try { URL url = new URL(httpUrl); String host = url.getHost(); int port = url.getPort(); String newUrl = ""; if (port == -1) { newUrl = httpUrl.replace(host, newIp + ":" + newPort); } else { newUrl = httpUrl.replace(host + ":" + port, newIp + ":" + newPort); } return newUrl; } catch (MalformedURLException e) { return httpUrl; } } // public static void main(String[] args) throws Exception { // System.out.println( // replaceIpAddress("http://i-ada.postbank.go.kr:123/web/jmd/ONL/EAI/abcd", "192.168.0.1", "5555")); // } }