[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tm-cvs-commit] dmcknight org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server ServerLauncher.java

Update of /cvsroot/tools/org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server
In directory dev1:/tmp/cvs-serv8212/src/org/eclipse/dstore/core/server

Modified Files:
      Tag: R3_0_maintenance
	ServerLauncher.java 
Log Message:
[378878] [dstore] Need ability to log handshake messages from the authentication/server process to ServerLauncher


Index: ServerLauncher.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/server/ServerLauncher.java,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -C2 -d -r1.17 -r1.17.2.1
*** ServerLauncher.java	3 Sep 2008 19:24:12 -0000	1.17
--- ServerLauncher.java	14 May 2012 14:00:07 -0000	1.17.2.1
***************
*** 1,4 ****
  /*******************************************************************************
!  * Copyright (c) 2002, 2008 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
--- 1,4 ----
  /*******************************************************************************
!  * 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
***************
*** 16,19 ****
--- 16,21 ----
   * David McKnight   (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
   * 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
   *******************************************************************************/
  
***************
*** 27,30 ****
--- 29,33 ----
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
+ import java.io.RandomAccessFile;
  import java.net.BindException;
  import java.net.InetAddress;
***************
*** 33,36 ****
--- 36,40 ----
  import java.net.UnknownHostException;
  import java.util.ArrayList;
+ import java.util.Date;
  
  import javax.net.ssl.HandshakeCompletedEvent;
***************
*** 97,101 ****
  						.getInputStream(), DE.ENCODING_UTF_8));
  			} catch (java.io.IOException e) {
! 				System.out.println("ServerLauncher:" + e); //$NON-NLS-1$
  			}
  		}
--- 101,107 ----
  						.getInputStream(), DE.ENCODING_UTF_8));
  			} catch (java.io.IOException e) {
! 				String msg = "ServerLauncher:" + e; //$NON-NLS-1$
! 				System.out.println(msg);
! 				logError(msg, e);
  			}
  		}
***************
*** 142,150 ****
  						_serverProcess.waitFor();
  					} catch (Exception e) {
! 						System.out.println("ServerLauncher:" + e); //$NON-NLS-1$
  					}
  				}
  
! 				System.out.println("finished on port " + _port); //$NON-NLS-1$
  				_outReader = null;
  				_errReader = null;
--- 148,160 ----
  						_serverProcess.waitFor();
  					} catch (Exception e) {
! 						String msg = "ServerLauncher:" + e; //$NON-NLS-1$
! 						System.out.println(msg);
! 						logError(msg, e);
  					}
  				}
  
! 				String msg = "finished on port " + _port; //$NON-NLS-1$
! 				System.out.println(msg);
! 				
  				_outReader = null;
  				_errReader = null;
***************
*** 333,336 ****
--- 343,347 ----
  						}
  	
+ 						logMessage("launch status = "+launchStatus); //$NON-NLS-1$
  						if ((launchStatus == null) || !launchStatus.equals("success")) //$NON-NLS-1$
  						{
***************
*** 342,345 ****
--- 353,357 ----
  							// somewhere in the line.
  							String status = _errReader.readLine();
+ 							logMessage("status = "+status); //$NON-NLS-1$
  							while (status!=null && (status.indexOf(ServerReturnCodes.RC_DSTORE_SERVER_MAGIC) < 0))
  							{
***************
*** 359,363 ****
  								_writer.println(ticket);
  	
! 								System.out.println("launched new server on " + _port); //$NON-NLS-1$
  								connected = true;
  							}
--- 371,377 ----
  								_writer.println(ticket);
  	
! 								String msg = "launched new server on " + _port; //$NON-NLS-1$
! 								System.out.println(msg);
! 								logMessage(msg);
  								connected = true;
  							}
***************
*** 399,403 ****
  			catch (IOException e)
  			{
! 				System.out.println("ServerLauncher:" + e); //$NON-NLS-1$
  			}
  
--- 413,419 ----
  			catch (IOException e)
  			{
! 				String msg = "ServerLauncher:" + e; //$NON-NLS-1$
! 				System.out.println(msg);
! 				logError(msg, e);
  			}
  
***************
*** 406,412 ****
  
  		public void handshakeCompleted(HandshakeCompletedEvent event) {
! 			System.out.println("handshake completed"); //$NON-NLS-1$
  			System.out.println(event);
! 
  		}
  	}
--- 422,430 ----
  
  		public void handshakeCompleted(HandshakeCompletedEvent event) {
! 			String msg = "handshake completed"; //$NON-NLS-1$
! 			System.out.println(msg);
  			System.out.println(event);
! 			
! 			logMessage(msg);
  		}
  	}
***************
*** 422,425 ****
--- 440,446 ----
  	private ISSLProperties _sslProperties;
  
+ 	private boolean _logDaemon = false;
+ 	private RandomAccessFile _logFile = null;
+ 	
  	public static int DEFAULT_DAEMON_PORT = 4075;
  
***************
*** 502,505 ****
--- 523,551 ----
  	 */
  	public void init(String portStr) {
+ 		
+ 		String logdaemonLocation = System.getProperty("logdaemonpath"); //$NON-NLS-1$
+ 		if (logdaemonLocation != null && logdaemonLocation.length() > 0){
+ 			// create temp file for logging
+ 			File traceFileHandle = new File(logdaemonLocation);
+ 			if (!traceFileHandle.exists()){
+ 				try { // try to create it
+ 					traceFileHandle.createNewFile();
+ 				} catch (IOException e) {
+ 				}
+ 			}
+ 			if (traceFileHandle.canWrite()){
+ 				try {
+ 					_logFile = new RandomAccessFile(traceFileHandle, "rw"); //$NON-NLS-1$					
+ 					_logFile.seek(traceFileHandle.length());
+ 
+ 					logMessage("-----------------------------------------"); //$NON-NLS-1$
+ 					logMessage("Start Tracing at " + System.currentTimeMillis()); //$NON-NLS-1$
+ 					_logDaemon = true;
+ 				}
+ 				catch (Exception e){	
+ 				}
+ 			}
+ 		}
+ 		
  		// create server socket from port
  		_sslProperties = new ServerSSLProperties();
***************
*** 541,561 ****
  							&& _serverSocket.getLocalPort() > 0) {
  						socketBound = true;
! 						System.out.println("Daemon running on: " //$NON-NLS-1$
! 								+ InetAddress.getLocalHost().getHostName()
! 								+ ", port: " + i); //$NON-NLS-1$
  					}
  				} catch (UnknownHostException e) {
! 					System.err
! 							.println("Networking problem, can't resolve local host"); //$NON-NLS-1$
  					// don't display exceptions 193426
! 					//e.printStackTrace();
  					System.exit(-1);
  				} catch (BindException e) {
! 					System.err.println("socket taken on " + i); //$NON-NLS-1$
  					// keep going
  				} catch (IOException e) {
! 					System.err.println("Failure to create ServerSocket"); //$NON-NLS-1$
  					// don't display exceptions 193426
  					//e.printStackTrace();
  					System.exit(-1);
  				}
--- 587,611 ----
  							&& _serverSocket.getLocalPort() > 0) {
  						socketBound = true;
! 						String msg = "Daemon running on: " + InetAddress.getLocalHost().getHostName() + ", port: " + i; //$NON-NLS-1$ //$NON-NLS-2$
! 						System.out.println(msg);
! 						logMessage(msg);
  					}
  				} catch (UnknownHostException e) {
! 					String msg = "Networking problem, can't resolve local host"; //$NON-NLS-1$
! 					System.err.println(msg);
  					// don't display exceptions 193426
! 					logError(msg, e);
  					System.exit(-1);
  				} catch (BindException e) {
! 					String msg = "socket taken on " + i; //$NON-NLS-1$
! 					System.err.println(msg);
! 					logError(msg, e);
  					// keep going
  				} catch (IOException e) {
! 					String msg = "Failure to create ServerSocket"; //$NON-NLS-1$
! 					System.err.println(msg);
  					// don't display exceptions 193426
  					//e.printStackTrace();
+ 					logError(msg, e);
  					System.exit(-1);
  				}
***************
*** 580,583 ****
--- 630,634 ----
  						//e.printStackTrace();
  						System.err.println(e.getMessage());
+ 						logError(e.getMessage(), e);
  						System.exit(-1);
  					}
***************
*** 585,605 ****
  					_serverSocket = new ServerSocket(port);
  				}
! 				System.out.println("Daemon running on: " //$NON-NLS-1$
! 						+ InetAddress.getLocalHost().getHostName() + ", port: " //$NON-NLS-1$
! 						+ port);
  			} catch (UnknownHostException e) {
! 				System.err
! 						.println("Networking problem, can't resolve local host"); //$NON-NLS-1$
  				// don't display exceptions 193426
  				//e.printStackTrace();
  				System.exit(-1);
  			} catch (IOException e) {
! 				System.err.println("Failure to create ServerSocket"); //$NON-NLS-1$
  				// don't display exceptions 193426
  				//e.printStackTrace();
  				System.exit(-1);
  			}
  		}
  	}
  
  	/**
--- 636,697 ----
  					_serverSocket = new ServerSocket(port);
  				}
! 				
! 				String msg = "Daemon running on: " //$NON-NLS-1$
! 					+ InetAddress.getLocalHost().getHostName() + ", port: " //$NON-NLS-1$
! 					+ port;
! 				
! 				System.out.println(msg);
! 				logMessage(msg);
  			} catch (UnknownHostException e) {
! 				String msg = "Networking problem, can't resolve local host"; //$NON-NLS-1$
! 				System.err.println(msg);
  				// don't display exceptions 193426
  				//e.printStackTrace();
+ 				logError(msg, e);
  				System.exit(-1);
  			} catch (IOException e) {
! 				String msg = "Failure to create ServerSocket"; //$NON-NLS-1$
! 				System.err.println(msg);
  				// don't display exceptions 193426
  				//e.printStackTrace();
+ 				logError(msg, e);
  				System.exit(-1);
  			}
  		}
  	}
+ 	
+ 	private void logMessage(String msg){
+ 		if (_logDaemon && _logFile != null){
+ 			try {
+ 				_logFile.writeBytes((new Date()).toString() + ": "); //$NON-NLS-1$
+ 				_logFile.writeBytes(msg);
+ 				_logFile.writeBytes(System.getProperty("line.separator")); //$NON-NLS-1$
+ 			}
+ 			catch (IOException e)
+ 			{
+ 			}
+ 		}
+ 	}
+ 	
+ 	private void logError(String msg, Throwable e){
+ 		if (_logDaemon && _logFile != null){
+ 			try {
+ 				_logFile.writeBytes((new Date()).toString() + ": "); //$NON-NLS-1$
+ 				_logFile.writeBytes(msg);
+ 				_logFile.writeBytes(System.getProperty("line.separator")); //$NON-NLS-1$
+ 
+ 				StackTraceElement[] stack = e.getStackTrace();
+ 				for (int i = 0;i<stack.length;i++){
+ 					_logFile.writeBytes(stack[i].toString());
+ 					_logFile.writeBytes(System.getProperty("line.separator")); //$NON-NLS-1$
+ 				}
+ 				_logFile.writeBytes(System.getProperty("line.separator")); //$NON-NLS-1$
+ 			}
+ 			catch (IOException ex)
+ 			{
+ 			}
+ 		}
+ 	}
+ 
  
  	/**
***************
*** 638,642 ****
  								public void handshakeCompleted(
  										HandshakeCompletedEvent event) {
! 									System.out.println("handshake completed"); //$NON-NLS-1$
  								}
  
--- 730,736 ----
  								public void handshakeCompleted(
  										HandshakeCompletedEvent event) {
! 									String msg = "handshake completed"; //$NON-NLS-1$
! 									System.out.println(msg);
! 									logMessage(msg);
  								}
  
***************
*** 644,649 ****
  					SSLSession session = sslSocket.getSession();
  					if (session == null) {
! 						System.out.println("handshake failed"); //$NON-NLS-1$
! 
  						sslSocket.close();
  						connectionOkay = false;
--- 738,744 ----
  					SSLSession session = sslSocket.getSession();
  					if (session == null) {
! 						String msg = "handshake failed"; //$NON-NLS-1$
! 						System.out.println(msg);
! 						logMessage(msg);
  						sslSocket.close();
  						connectionOkay = false;
***************
*** 657,661 ****
  				}
  			} catch (IOException ioe) {
! 				System.err.println("Server: error initializing socket: " + ioe); //$NON-NLS-1$
  				System.exit(-1);
  			}
--- 752,758 ----
  				}
  			} catch (IOException ioe) {
! 				String msg = "Server: error initializing socket: " + ioe; //$NON-NLS-1$
! 				System.err.println(msg);
! 				logMessage(msg);
  				System.exit(-1);
  			}