Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-12351 - ensure jmx connections to as7 / wf properly format the host for ip6 #326

Merged
merged 1 commit into from Feb 6, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -79,14 +79,10 @@ private void pollerRun() {
}

private static String getURL(IServer server) {
String host = server.getHost();
// v6_safe
String host2 = ServerUtil.formatPossibleIpv6Address(server.getHost());
String url = "http://"+host2; //$NON-NLS-1$
IJBossServer jbs = ServerConverter.getJBossServer(server);
int port = jbs.getJBossWebPort();
url += ":" + port; //$NON-NLS-1$
return url;
return ServerUtil.createSafeURLString("http", server.getHost(), port, null); //$NON-NLS-1$
}

public static boolean onePing(IServer server) {
@@ -214,21 +214,20 @@ public static URL getModuleRootURL(IModule module, String host, int port, String
return null;

IWebModule webModule =(IWebModule)module.loadAdapter(IWebModule.class,null);
String host2 = ServerUtil.formatPossibleIpv6Address(host);
String url = host2;
if( !url.startsWith("http://") && !url.startsWith("https://") ) { //$NON-NLS-1$ //$NON-NLS-2$
url = "http://"+host2; //$NON-NLS-1$
}
if (port != 80)
url += ":" + port; //$NON-NLS-1$

if( contextRoot == null ) {
contextRoot = webModule.getContextRoot();
}
if( !contextRoot.equals("/") && !contextRoot.equals("./")) //$NON-NLS-1$ //$NON-NLS-2$
url += contextRoot.startsWith("/") ? contextRoot : "/"+contextRoot; //$NON-NLS-1$ //$NON-NLS-2$
if (!url.endsWith("/")) //$NON-NLS-1$
url += "/"; //$NON-NLS-1$
// Ensure trailing slash
if( !contextRoot.endsWith("/")) { //$NON-NLS-1$
contextRoot += "/"; //$NON-NLS-1$
}

String url = null;
if( port == 80 ) {
url = ServerUtil.createSafeURLString("http", host, contextRoot); //$NON-NLS-1$
} else {
url = ServerUtil.createSafeURLString("http", host, port, contextRoot); //$NON-NLS-1$
}

try {
return new URL(url);
@@ -18,6 +18,7 @@
import org.jboss.ide.eclipse.as.core.server.bean.JBossServerType;
import org.jboss.ide.eclipse.as.core.server.bean.ServerBeanLoader;
import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
import org.jboss.ide.eclipse.as.core.util.ServerUtil;

public class JBossAS710ExtendedProperties extends JBossAS7ExtendedProperties implements IJMXURLProvider {

@@ -71,8 +72,8 @@ protected String getJMXUrl(int defaultPort, String jmxScheme) {
ServerDelegate sd = (ServerDelegate)server.loadAdapter(ServerDelegate.class, null);
int port = (sd instanceof IManagementPortProvider) ?
((IManagementPortProvider)sd).getManagementPort() : defaultPort;
String url = jmxScheme + "://" + server.getHost() + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$
return url;
String ret = ServerUtil.createSafeURLString(jmxScheme, server.getHost(), port, null);
return ret;
}


@@ -89,14 +89,13 @@ public boolean hasWelcomePage() {
return true;
}

@Deprecated
protected static final String WELCOME_PAGE_URL_PATTERN = "http://{0}:{1}/"; //$NON-NLS-1$
public String getWelcomePageUrl() {
try {
JBossServer jbossServer = ServerUtil.checkedGetServerAdapter(server, JBossServer.class);
String host = jbossServer.getHost();
host = ServerUtil.formatPossibleIpv6Address(host);
int webPort = jbossServer.getJBossWebPort();
String consoleUrl = MessageFormat.format(WELCOME_PAGE_URL_PATTERN, host, String.valueOf(webPort));
String consoleUrl = ServerUtil.createSafeURLString("http", server.getHost(), webPort, null); //$NON-NLS-1$
return consoleUrl;
} catch(CoreException ce) {
return null;
@@ -259,6 +259,50 @@ public static void storeInSecureStorage(IServerAttributes server, String key, St
ServerSecureStorageUtil.storeInSecureStorage(SECURE_PREFERNCES_BASEKEY, server, key, val);
}

/**
* Create a URL string which is safe for all valid versions of IP.
*
* For example, given a host 192.168.1.1, scheme http, and path my/folder,
* this will return http://192.168.1.1/my/folder
*
* @param scheme A scheme to connect over
* @param host A host
* @param path A path
* @return
*/
public static String createSafeURLString(String scheme, String host, String path) {
return createSafeURLString(scheme, host, -1, path);
}

/**
* Create a URL string which is safe for all valid versions of IP.
*
* For example, given a host 5a:55:4f:e6:e7:ea, scheme http, port 8080, and path my/folder,
* this will return http://[5a:55:4f:e6:e7:ea]:8080/my/folder
*
* @param scheme A scheme to connect over
* @param host A host
* @param port A port to connect over, or -1 if none is to be set
* @param path A path
* @return
*/
public static String createSafeURLString(String scheme, String host, int port, String path) {
StringBuilder sb = new StringBuilder();
sb.append(scheme);
sb.append("://"); //$NON-NLS-1$
sb.append(formatPossibleIpv6Address(host));
if( port != -1 ) {
sb.append(":"); //$NON-NLS-1$
sb.append(port);
}
if( path != null ) {
if( !path.startsWith("/")) //$NON-NLS-1$
sb.append("/"); //$NON-NLS-1$
sb.append(path);
}
return sb.toString();
}

public static String formatPossibleIpv6Address(String address) {
if (address == null) {
return address;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.