db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r665818 - in /db/derby/code/branches/10.4/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/
Date Mon, 09 Jun 2008 18:34:08 GMT
Author: kmarsden
Date: Mon Jun  9 11:34:08 2008
New Revision: 665818

URL: http://svn.apache.org/viewvc?rev=665818&view=rev
Log:
DERBY-3704 If an IOException is encountered during establishment of the connection, Network
Server should print the root exception to the console instead of a generic message

DERBY-3701  java.lang.Exception: DRDA_UnableToAccept.S:Unable to accept connections and client
hang if tracing is turned on but traceDirectory does not exist


Modified:
    db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/ClientThread.java
    db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DssTrace.java
    db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/Session.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java

Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/ClientThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/ClientThread.java?rev=665818&r1=665817&r2=665818&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/ClientThread.java (original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/ClientThread.java Mon
Jun  9 11:34:08 2008
@@ -113,7 +113,9 @@
                     // shutdown
                     synchronized (parent.getShutdownSync()) {
                         if (!parent.getShutdown()) {
-                            parent.consolePropertyMessage("DRDA_UnableToAccept.S");
+                            parent.consoleExceptionPrintTrace(ioe);
+                            if (clientSocket != null)
+                                clientSocket.close();
                         }
                     }
                     return; // Exit the thread
@@ -122,6 +124,13 @@
                 // Catch and log all other exceptions
                 
                 parent.consoleExceptionPrintTrace(e);
+                try {
+                    if (clientSocket != null)
+                        clientSocket.close();
+                } catch (IOException closeioe)
+                {
+                    parent.consoleExceptionPrintTrace(closeioe);
+                }
             } // end outer try/catch block
             
         } // end for(;;)

Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DssTrace.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DssTrace.java?rev=665818&r1=665817&r2=665818&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DssTrace.java (original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/DssTrace.java Mon Jun
 9 11:34:08 2008
@@ -20,12 +20,15 @@
  */
 package org.apache.derby.impl.drda;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
+import org.apache.derby.iapi.util.PrivilegedFileOps;
+
 
 // Generic process and error tracing encapsulation.
 // This class also traces a DRDA communications buffer.
@@ -167,14 +170,13 @@
   // Start the communications buffer trace.
   // The name of the file to place the trace is passed to this method.
   // After calling this method, calls to isComBufferTraceOn() will return true.
-  protected void startComBufferTrace (final String fileName) throws IOException 
+  protected void startComBufferTrace (final String fileName) throws Exception 
   {
     synchronized (comBufferSync) {
         // Only start the trace if it is off.
         if (comBufferTraceOn == false) {
-          // The writer will be buffered for effeciency.
             try {
-                
+                // The writer will be buffered for effeciency.
                 comBufferWriter =  ((PrintWriter)AccessController.doPrivileged(
                             new PrivilegedExceptionAction() {
                                 public Object run() throws SecurityException, IOException
{
@@ -182,11 +184,8 @@
                                 }
                             }));
             } catch (PrivilegedActionException pae) {
-               Exception e = pae.getException();
-               if (e instanceof SecurityException)
-                   throw (SecurityException)pae.getException();
-               else
-                   throw (IOException) pae.getException();
+               throw  pae.getException();
+               
             }
           
           // Turn on the trace flag.

Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=665818&r1=665817&r2=665818&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Mon Jun  9 11:34:08 2008
@@ -3502,7 +3502,7 @@
 				    Session session = (Session) e.nextElement();
 					if (on)
 						try {
-							session.setTraceOn(traceDirectory);
+							session.setTraceOn(traceDirectory,true);
 						} catch (Exception te ) {
 							consoleExceptionPrintTrace(te);
 							setTraceSuccessful = false;
@@ -3522,7 +3522,7 @@
 			{	
 				if (on)
 					try {                         
-						session.setTraceOn(traceDirectory);
+						session.setTraceOn(traceDirectory,true);
 					}catch (Exception te) {
 						consoleExceptionPrintTrace(te);
 						setTraceSuccessful = false;
@@ -3838,7 +3838,7 @@
 		// Note that we always re-fetch the tracing configuration because it
 		// may have changed (there are administrative commands which allow
 		// dynamic tracing reconfiguration).
-		Session session = new Session(connectionNumber, clientSocket,
+		Session session = new Session(this,connectionNumber, clientSocket,
 									  getTraceDirectory(), getTraceAll());
 
 		sessionTable.put(new Integer(connectionNumber), session);

Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/Session.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/Session.java?rev=665818&r1=665817&r2=665818&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/Session.java (original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/Session.java Mon Jun
 9 11:34:08 2008
@@ -70,6 +70,9 @@
 										// client
 
 	private	Hashtable	dbtable;		// Table of databases accessed in this session
+	private NetworkServerControlImpl nsctrl;        // NetworkServerControlImpl needed for logging
+                                                        // message if tracing fails.
+                                                        
 
 	// constructor
 	/**
@@ -82,9 +85,10 @@
 	 *
 	 * @exception throws IOException
 	 */
-	Session (int connNum, Socket clientSocket, String traceDirectory,
-			boolean traceOn) throws IOException
+	Session (NetworkServerControlImpl nsctrl, int connNum, Socket clientSocket, String traceDirectory,
+			boolean traceOn) throws Exception
 	{
+        this.nsctrl = nsctrl;
 		this.connNum = connNum;
 		this.clientSocket = clientSocket;
 		this.traceOn = traceOn;
@@ -123,9 +127,12 @@
 	 * initialize a server trace for the DRDA protocol
 	 * 
 	 * @param traceDirectory - directory for trace file
+     * @param throwException - true if we should throw an exception if
+     *                         turning on tracing fails.  We do this
+     *                         for NetworkServerControl API commands.
 	 * @throws IOException 
 	 */
-	protected void initTrace(String traceDirectory) throws IOException 
+	protected void initTrace(String traceDirectory, boolean throwException)  throws Exception
 	{
 		if (traceDirectory != null)
 			traceFileName = traceDirectory + "/" + TRACENAME_PREFIX+
@@ -135,21 +142,31 @@
 		
 		if (dssTrace == null)
 			dssTrace = new DssTrace();
-		dssTrace.startComBufferTrace (traceFileName);
-		traceOn = true;
+        try {
+            dssTrace.startComBufferTrace(traceFileName);
+            traceOn = true;
+        } catch (Exception e) {   
+            if (throwException) {
+                throw e;
+            }
+            // If there is an error starting tracing for the session,
+            // log to the console and derby.log and do not turn tracing on.
+            // let connection continue.
+            nsctrl.consoleExceptionPrintTrace(e);
+        }              
 	}
 
 	/**
 	 * Set tracing on
 	 * 
 	 * @param traceDirectory 	directory for trace files
-	 * @throws IOException 
+	 * @throws Exception 
 	 */
-	protected void setTraceOn(String traceDirectory) throws IOException
+	protected void setTraceOn(String traceDirectory, boolean throwException) throws Exception
 	{
 		if (traceOn)
 			return;
-		initTrace(traceDirectory);    
+		initTrace(traceDirectory, throwException);    
 	}
 
 	/**
@@ -253,12 +270,12 @@
 	 * @param traceDirectory	- directory for trace files
 	 */
 	private void initialize(String traceDirectory)
-		throws IOException
+		throws Exception
 	{
 		sessionInput = clientSocket.getInputStream();
 		sessionOutput = clientSocket.getOutputStream();
 		if (traceOn)
-			initTrace(traceDirectory);
+			initTrace(traceDirectory,false);
 		state = INIT;
 	}
 

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java?rev=665818&r1=665817&r2=665818&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
Mon Jun  9 11:34:08 2008
@@ -29,8 +29,10 @@
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
+
 import java.io.File;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -38,7 +40,10 @@
 import java.security.Policy;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.Enumeration;
+import java.util.Properties;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -127,7 +132,28 @@
     
                         
     }
-
+    
+    /**
+     * Test tracing with system properties if we have no permission
+     * to write to the trace directory. Make sure we can still 
+     * get a connection.  Trace directory set to "/" in test setup.
+     * 
+     */
+    public void xtestTraceSystemPropertiesNoPermission() throws SQLException{
+        // our connection should go through fine and there should be an
+        // exception in the derby.log.
+        //access denied (java.io.FilePermission \\ read). I verified 
+        // this manually when creating this fixture but do not know 
+        // how to check in the test.
+        assertEquals(getSystemProperty("derby.drda.traceAll"),"true");
+        assertEquals(getSystemProperty("derby.drda.traceDirectory"),"/");
+        Connection conn = getConnection();
+        assertFalse(conn.getMetaData().isReadOnly());
+    }
+    
+  
+    
+    
     /**
      * Test NetworkServerControl ping command.
      * @throws Exception
@@ -253,6 +279,7 @@
              new String[] { TARGET_POLICY_FILE_NAME}
              );
 
+       
         return test;
     }
     
@@ -264,7 +291,22 @@
         // Need derbynet.jar in the classpath!
         if (!Derby.hasServer())
             return suite;
+        suite.addTest(decorateTest());
+        
+        suite = decorateSystemPropertyTests(suite);
+                    
+        return suite;
+    }
+
+    private static TestSuite decorateSystemPropertyTests(TestSuite suite) {
+        Properties traceProps = new Properties();
+        traceProps.put("derby.drda.traceDirectory","/");
+        traceProps.put("derby.drda.traceAll","true");
+        suite.addTest(new SystemPropertyTestSetup(TestConfiguration.clientServerDecorator(
+                new NetworkServerControlApiTest("xtestTraceSystemPropertiesNoPermission")),
+                    traceProps));
+        
         
-        return decorateTest();
+        return suite;
     }
 }



Mime
View raw message