1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-05 16:15:25 +02:00

[388472] [dstore] need alternative option for getting at server hostname

This commit is contained in:
David McKnight 2012-08-30 20:45:35 +00:00
parent 1ea4c1a2eb
commit fcc908556b
3 changed files with 62 additions and 39 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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;
}
}