diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ConnectionEstablisher.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ConnectionEstablisher.java index 9e58b8ced70..316afa088a2 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ConnectionEstablisher.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ConnectionEstablisher.java @@ -29,6 +29,7 @@ * David McKnight (IBM) - [368072] [dstore][ssl] no exception logged upon bind error * David McKnight (IBM) - [371401] [dstore][multithread] avoid use of static variables - causes memory leak after disconnect * David McKnight (IBM) - [378136] [dstore] miner.finish is stuck + * David McKnight (IBM) - [388472] [dstore] need alternative option for getting at server hostname *******************************************************************************/ package org.eclipse.dstore.core.server; @@ -522,14 +523,7 @@ public class ConnectionEstablisher System.err.println(ServerReturnCodes.RC_SUCCESS); System.err.println(_serverSocket.getLocalPort()); _msg = ServerReturnCodes.RC_SUCCESS; - try - { - System.err.println("Server running on: " + InetAddress.getLocalHost().getHostName()); //$NON-NLS-1$ - } - catch (UnknownHostException e) - { - // keep running - } + System.err.println("Server running on: " + ServerAttributes.getHostName()); //$NON-NLS-1$ } } catch (UnknownHostException e) diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ServerLauncher.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ServerLauncher.java index 6b0428c1a9e..976c40b0052 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ServerLauncher.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ServerLauncher.java @@ -17,6 +17,7 @@ * David McKnight (IBM) - [245714] [dstore] Multiple user ID/password prompts and connect fails * David McKnight (IBM) - [283613] [dstore] Create a Constants File for all System Properties we support * David McKnight (IBM) - [378878] [dstore] Need ability to log handshake messages from the authentication/server process to ServerLauncher + * David McKnight (IBM) - [388472] [dstore] need alternative option for getting at server hostname *******************************************************************************/ package org.eclipse.dstore.core.server; @@ -47,6 +48,7 @@ import org.eclipse.dstore.core.model.DE; import org.eclipse.dstore.core.model.IDataStoreConstants; import org.eclipse.dstore.core.model.ISSLProperties; import org.eclipse.dstore.internal.core.model.IDataStoreSystemProperties; +import org.eclipse.dstore.internal.core.server.ServerAttributes; import org.eclipse.dstore.internal.core.server.ServerReturnCodes; import org.eclipse.dstore.internal.core.server.ServerSSLProperties; import org.eclipse.dstore.internal.core.util.ssl.DStoreSSLContext; @@ -587,7 +589,7 @@ public class ServerLauncher extends Thread { if (_serverSocket != null && _serverSocket.getLocalPort() > 0) { socketBound = true; - String msg = "Daemon running on: " + InetAddress.getLocalHost().getHostName() + ", port: " + i; //$NON-NLS-1$ //$NON-NLS-2$ + String msg = "Daemon running on: " + ServerAttributes.getHostName() + ", port: " + i; //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(msg); logMessage(msg); } @@ -638,7 +640,7 @@ public class ServerLauncher extends Thread { } String msg = "Daemon running on: " //$NON-NLS-1$ - + InetAddress.getLocalHost().getHostName() + ", port: " //$NON-NLS-1$ + + ServerAttributes.getHostName() + ", port: " //$NON-NLS-1$ + port; System.out.println(msg); diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/server/ServerAttributes.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/server/ServerAttributes.java index ce37cf6beca..3346b25b689 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/server/ServerAttributes.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/server/ServerAttributes.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2011 IBM Corporation and others. + * Copyright (c) 2002, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,16 @@ * * Contributors: * David McKnight (IBM) - [283613] [dstore] Create a Constants File for all System Properties we support + * David McKnight (IBM) - [388472] [dstore] need alternative option for getting at server hostname *******************************************************************************/ package org.eclipse.dstore.internal.core.server; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.InetAddress; import java.net.UnknownHostException; @@ -38,37 +43,59 @@ public class ServerAttributes extends DataStoreAttributes { super(); - try + String pluginPath = System.getProperty(IDataStoreSystemProperties.A_PLUGIN_PATH); + if (pluginPath != null) pluginPath = pluginPath.trim(); + if ((pluginPath != null) && (pluginPath.length() > 0)) { - String pluginPath = System.getProperty(IDataStoreSystemProperties.A_PLUGIN_PATH); - if (pluginPath != null) pluginPath = pluginPath.trim(); - if ((pluginPath != null) && (pluginPath.length() > 0)) - { - File f = new File(pluginPath); - try - { - pluginPath = f.getCanonicalPath(); - } - catch (Exception e) - { - pluginPath = f.getAbsolutePath(); - } - - setAttribute(A_PLUGIN_PATH, pluginPath + File.separator); - } - else - { - setAttribute(A_PLUGIN_PATH, "/home/"); //$NON-NLS-1$ - } - - setAttribute(A_LOCAL_NAME, InetAddress.getLocalHost().getHostName()); - - setAttribute(A_HOST_NAME, "server_host"); //$NON-NLS-1$ - setAttribute(A_HOST_PATH, "/home/"); //$NON-NLS-1$ + File f = new File(pluginPath); + try + { + pluginPath = f.getCanonicalPath(); + } + catch (Exception e) + { + pluginPath = f.getAbsolutePath(); + } + + setAttribute(A_PLUGIN_PATH, pluginPath + File.separator); } - catch (UnknownHostException e) + else { + setAttribute(A_PLUGIN_PATH, "/home/"); //$NON-NLS-1$ } + setAttribute(A_LOCAL_NAME, getHostName()); + + setAttribute(A_HOST_NAME, "server_host"); //$NON-NLS-1$ + setAttribute(A_HOST_PATH, "/home/"); //$NON-NLS-1$ } -} + + /** + * Returns the server hostname, avoiding use of InetAddress.getLocalHost().getHostName() if possible + * @return the hostname + */ + public static String getHostName(){ + String hostname = System.getProperty("hostname"); //$NON-NLS-1$ + if (hostname == null || hostname.length() == 0){ + String readHostname = System.getProperty("read.hostname"); //$NON-NLS-1$ + if (readHostname != null && readHostname.equals("true")){ //$NON-NLS-1$ + try { + Process p = Runtime.getRuntime().exec("hostname"); //$NON-NLS-1$ + InputStream inStream = p.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); + hostname = reader.readLine(); + } catch (IOException e) { + } + } + if (hostname == null || hostname.length() == 0){ // still no hostname + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + } + } + // set this so we don't have to do it again + System.setProperty("hostname", hostname); //$NON-NLS-1$ + } + return hostname; + } +} \ No newline at end of file