private static void addParsedURL(String url, Set newURLs) { if (! newURLs.contains(url)) { newURLs.add(updateIPv6(url)); } }
private static void addInetAddress(InetAddress local, String url, Set newURLs) throws Exception { String localHostAddress = local.getHostAddress(); if (localHostAddress != null) { addLocalServerURL(url, localHostAddress, newURLs); } String localHostName = local.getHostName(); if (localHostName != null) { addLocalServerURL(url, localHostName, newURLs); InetAddress[] addrs = InetAddress.getAllByName(localHostName); for (int i = 0; i < addrs.length; i++) { InetAddress addr = addrs[i]; String hostName = addr.getHostName(); if (! hostName.equals(localHostName)) { addLocalServerURL(url, hostName, newURLs); } String hostAddress = addr.getHostAddress(); if (! hostAddress.equals(localHostAddress)) { addLocalServerURL(url, hostAddress, newURLs); } } } }
private static void addLocalServerURL(String url, String sub, Set newURLs) { String toSub = null; // if ipv6, then add square brackets if (sub.indexOf(":") != -1) { StringBuffer ipv6Sub = new StringBuffer("["); ipv6Sub.append(sub); ipv6Sub.append("]"); toSub = ipv6Sub.toString(); } else { toSub = sub; } String newUrl = StringUtils.substitute(url, SERVER_NAME_TOKEN, toSub); addParsedURL(newUrl, newURLs); }
public static Set replaceAllTokensCalculateServerName(List urls, String contextPath) { List contextParsedUrls = new ArrayList(urls.size()); Set newURLs = new HashSet(urls.size()); // first replace context path for (int i = 0; i < urls.size(); i++) { String url = (String)urls.get(i); url = url.toLowerCase().trim(); url = SettingsReplaceUtil.replaceContextPath(url, contextPath); contextParsedUrls.add(url); } // then replace {server.name} replaceServerNameWithLocalHost(contextParsedUrls, newURLs); return newURLs; }
url = SettingsReplaceUtil.replaceContextPath(url, contextPath); return updateIPv6(url);
addLocalServerURL(url, "localhost", newURLs); addLocalServerURL(url, "127.0.0.1", newURLs); addLocalServerURL(url, "[::1]", newURLs); // for IPv6 addInetAddress(local, url, newURLs); addInetAddress(local, url, newURLs); addParsedURL(url, newURLs);
public static String updateIPv6(String src) { // if the ip address has "[" and "]" then it's IPv6, check that it's long form as well if ((src != null) && (src.indexOf('[') != -1) && (src.indexOf(']') != -1)) { // then, it's IPv6 and remove the square brackets and update to long form if required int start = src.indexOf('['); int end = src.indexOf(']'); StringBuffer updated = new StringBuffer(src.substring(0, start + 1)); updated.append(updateToLongForm(src.substring(start + 1, end))); updated.append(src.substring(end)); return updated.toString(); } else { return src; } }
redirectURL = SettingsReplaceUtil.replaceContextPath(redirectURL, req.getContextPath()); res.sendRedirect(redirectURL);
/** * This method replaces the dynamic tokens of the default url with the specified * values and returns the resulting url. * * @param contextPath The context path to be used in dynamic url replacement. * @param serverName The server name to be used in dynamic url replacement. * @param serverPort The server port to be used in dynamic url replacement. * @param serverProtocol The server protocol to be used in dynamic url replacement. * @return The fully parsed url where the dynamic tokens have been replaced. */ public String getParsedDefaultUrl(String contextPath, String serverName, String serverPort, String serverProtocol) { if (defaultUrl != null) { parsedDefaultUrl = SettingsReplaceUtil.replaceAllTokensGivenServerName(defaultUrl, contextPath, serverName, serverPort, serverProtocol); } return parsedDefaultUrl; }
boolean computeAuth = true; Set parsedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(dynamicUrls, contextPath); for (Iterator iter = parsedUrls.iterator(); iter.hasNext();)
url = SettingsReplaceUtil.replaceContextPath(url, contextPath); return updateIPv6(url);
addLocalServerURL(url, "localhost", newURLs); addLocalServerURL(url, "127.0.0.1", newURLs); addLocalServerURL(url, "[::1]", newURLs); // for IPv6 addInetAddress(local, url, newURLs); addInetAddress(local, url, newURLs); addParsedURL(url, newURLs);
/** * Replace all tokens in the urls. * @param urls a list of urls * @param contextPath the context path * @return Set a set of urls after replacement */ public static Set replaceAllTokensCalculateServerName(List urls, String contextPath) { List contextParsedUrls = new ArrayList(urls.size()); Set newURLs = new HashSet(urls.size()); // first replace context path for (int i = 0; i < urls.size(); i++) { String url = (String)urls.get(i); url = url.toLowerCase().trim(); url = SettingsReplaceUtil.replaceContextPath(url, contextPath); contextParsedUrls.add(url); } // then replace {server.name} replaceServerNameWithLocalHost(contextParsedUrls, newURLs); return newURLs; }
/** * Update IPv6 IP address. * @param src the source IP address string * @return String the updated IP address string */ public static String updateIPv6(String src) { // if the ip address has "[" and "]" then it's IPv6, check that it's long form as well if ((src != null) && (src.indexOf('[') != -1) && (src.indexOf(']') != -1)) { // then, it's IPv6 and remove the square brackets and update to long form if required int start = src.indexOf('['); int end = src.indexOf(']'); StringBuffer updated = new StringBuffer(src.substring(0, start + 1)); updated.append(updateToLongForm(src.substring(start + 1, end))); updated.append(src.substring(end)); return updated.toString(); } else { return src; } }
redirectURL = SettingsReplaceUtil.replaceContextPath(redirectURL, req.getContextPath()); res.sendRedirect(redirectURL);
/** * This method replaces the dynamic tokens of the default url with the specified * values and returns the resulting url. * * @param contextPath The context path to be used in dynamic url replacement. * @param serverName The server name to be used in dynamic url replacement. * @param serverPort The server port to be used in dynamic url replacement. * @param serverProtocol The server protocol to be used in dynamic url replacement. * @return The fully parsed url where the dynamic tokens have been replaced. */ public String getParsedDefaultUrl(String contextPath, String serverName, String serverPort, String serverProtocol) { if (defaultUrl != null) { parsedDefaultUrl = SettingsReplaceUtil.replaceAllTokensGivenServerName(defaultUrl, contextPath, serverName, serverPort, serverProtocol); } return parsedDefaultUrl; }
boolean computeAuth = true; Set parsedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(dynamicUrls, contextPath); for (Iterator iter = parsedUrls.iterator(); iter.hasNext();)
url = SettingsReplaceUtil.replaceContextPath(url, contextPath); return updateIPv6(url);
addLocalServerURL(url, "localhost", newURLs); addLocalServerURL(url, "127.0.0.1", newURLs); addLocalServerURL(url, "[::1]", newURLs); // for IPv6 addInetAddress(local, url, newURLs); addInetAddress(local, url, newURLs); addParsedURL(url, newURLs);
private static void addParsedURL(String url, Set newURLs) { if (! newURLs.contains(url)) { newURLs.add(updateIPv6(url)); } }