db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r292917 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ client/org/apache/derby/jdbc/ drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/...
Date Sat, 01 Oct 2005 04:31:01 GMT
Author: kmarsden
Date: Fri Sep 30 21:30:43 2005
New Revision: 292917

URL: http://svn.apache.org/viewcvs?rev=292917&view=rev
Log:
DERBY-374

Invalid URL with Derby Client when connecting to Network Server causes protocol exception.

This patch does the following:

1. Network server used to give NPE when InternalDriver returns null connection for certain
malformed URLs. With this patch, network server checks for null connections returned by InternalDriver
and returns RDBAFLRM and SQLCARD with null SQLException.
2. The client parses the SQLCARD and if finds null SQLException, it sets connectionNull variable
in NetConnection to true.
3. ClientDriver connect method, which calls the constructor of NetConnection, gets back an
object with connectionNull set to true. And it inturn returns null connection.
4. Added tests to checkDriver.java for more Client URLs. 

Contributed by Deepa Remesh


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Fri Sep
30 21:30:43 2005
@@ -128,6 +128,13 @@
 
     // stored the password for deferred reset only.
     private transient char[] deferredResetPassword_ = null;
+    
+    //If Network Server gets null connection from the embedded driver, 
+    //it sends RDBAFLRM followed by SQLCARD with null SQLException.
+    //Client will parse the SQLCARD and set connectionNull to true if the
+    //SQLCARD is empty. If connectionNull=true, connect method in 
+    //ClientDriver will in turn return null connection.
+    private boolean connectionNull = false;
 
     private void setDeferredResetPassword(String password) {
         deferredResetPassword_ = (password == null) ? null : flipBits(password.toCharArray());
@@ -186,7 +193,8 @@
         String password = ClientDataSource.getPassword(properties);
         securityMechanism_ = ClientDataSource.getSecurityMechanism(properties);
         flowConnect(password, securityMechanism_);
-        completeConnect();
+        if(!isConnectionNull())
+        	completeConnect();
     }
 
     // For JDBC 2 Connections
@@ -1502,5 +1510,18 @@
         agent_.flowOutsideUOW();
         agent_.endReadChain();
     }
+    
+	/**
+	 * @return Returns the connectionNull.
+	 */
+	public boolean isConnectionNull() {
+		return connectionNull;
+	}
+	/**
+	 * @param connectionNull The connectionNull to set.
+	 */
+	public void setConnectionNull(boolean connectionNull) {
+		this.connectionNull = connectionNull;
+	}
 }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java Fri
Sep 30 21:30:43 2005
@@ -485,7 +485,12 @@
         }
 
         NetSqlca netSqlca = parseSQLCARD(null);
-        netConnection.completeSqlca(netSqlca);
+        
+        //Check if the SQLCARD has null SQLException
+        if(netSqlca.getSqlErrmc() == null)
+        	netConnection.setConnectionNull(true);
+        else
+        	netConnection.completeSqlca(netSqlca);
     }
 
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java Fri Sep 30 21:30:43
2005
@@ -129,6 +129,10 @@
                         port,
                         database,
                         augmentedProperties);
+        
+        if(conn.isConnectionNull())
+        	return null;
+        
         return conn;
     }
 

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Fri Sep 30
21:30:43 2005
@@ -973,6 +973,13 @@
 		verifyRequiredObject(codePoint,CodePoint.ACCRDB);
 		int svrcod = parseACCRDB();
 
+		//If network server gets a null connection form InternalDriver, reply with
+		//RDBAFLRM and SQLCARD with null SQLException 
+		if(database.getConnection() == null && databaseAccessException == null){
+			writeRDBfailure(CodePoint.RDBAFLRM);
+			return false;
+		}		
+		
 		//if earlier we couldn't access the database
 		if (databaseAccessException != null)
 		{
@@ -983,43 +990,16 @@
 				|| failureType == CodePoint.RDBATHRM)
 			{
 				writeRDBfailure(failureType);
-				writeSQLCARD(databaseAccessException,
-					CodePoint.SVRCOD_ERROR,0,0);
 			}
 			else
 			{
 				writeRDBfailure(CodePoint.RDBAFLRM);
-
-				// RDBAFLRM requires TYPDEFNAM and TYPDEFOVR
-				writer.createDssObject();
-				writer.writeScalarString(CodePoint.TYPDEFNAM,
-										 CodePoint.TYPDEFNAM_QTDSQLASC);
-				writeTYPDEFOVR();
-				writer.endDss();
-
-				// Finally, per DDM spec, "an SQLCARD always follows
-				// the RDBAFLRM".
-				writeSQLCARD(databaseAccessException,
-							 CodePoint.SVRCOD_ERROR,0,0);
 			}
-
-			// Ignore anything that was chained to the ACCRDB.
-			skipRemainder(false);
-
-			// Finalize chain state for whatever we wrote in
-			// response to ACCRDB.
-			finalizeChain();
 			return false;
 		}
 		else if (database.accessCount > 1 )	// already in conversation with database
 		{
 			writeRDBfailure(CodePoint.RDBACCRM);
-
-			// Ignore anything that was chained to the ACCRDB.
-			skipRemainder(false);
-
-			// Finalize chain state for RDBACCRM
-			finalizeChain();
 			return false;
 		}
 		else // everything is fine 
@@ -1049,7 +1029,28 @@
 		writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR);
 		writeRDBNAM(database.dbName);
     	writer.endDdmAndDss();
-
+    	
+    	switch(codePoint){
+    		case CodePoint.RDBAFLRM:
+    			//RDBAFLRM requires TYPDEFNAM and TYPDEFOVR
+    			writer.createDssObject();
+    			writer.writeScalarString(CodePoint.TYPDEFNAM,
+    									 CodePoint.TYPDEFNAM_QTDSQLASC);
+    			writeTYPDEFOVR();
+    			writer.endDss();
+    		case CodePoint.RDBNFNRM:
+    		case CodePoint.RDBATHRM:
+    			writeSQLCARD(databaseAccessException,CodePoint.SVRCOD_ERROR,0,0);
+    		case CodePoint.RDBACCRM:
+    			//Ignore anything that was chained to the ACCRDB.
+    			skipRemainder(false);
+
+    			// Finalize chain state for whatever we wrote in
+    			// response to ACCRDB.
+    			finalizeChain();
+    			break;
+    	}
+    	
 	}
 
 	/* Check the database access exception and return the appropriate

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java Fri Sep 30 21:30:43
2005
@@ -116,7 +116,8 @@
 		throws SQLException
 	{
 		this.conn = conn;
-		defaultStatement.setStatement(conn);
+		if(conn != null)
+			defaultStatement.setStatement(conn);
 	}
 	/**
 	 * Get the connection
@@ -245,9 +246,11 @@
                 // take care of case of SECMEC_USRIDONL
                 if(password != null) 
 		    p.put(Attribute.PASSWORD_ATTR, password);
-		Connection conn = NetworkServerControlImpl.getDriver().connect(Attribute.PROTOCOL
-							 + dbName + attrString, p);
-		conn.setAutoCommit(false);
+        Connection conn = NetworkServerControlImpl.getDriver().connect(Attribute.PROTOCOL
+							 + shortDbName + attrString, p);
+		if(conn != null){
+			conn.setAutoCommit(false);
+		}
 		setConnection(conn);
 		return conn;
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
Fri Sep 30 21:30:43 2005
@@ -42,3 +42,20 @@
 getUserName() = APP
 CURRENT SCHEMA = APP
  trace file exists
+doClientURLTest()
+doClientURLTest with url: jdbc:derby://localhost:1527/wombat:create=true
+Null connection returned for url jdbc:derby://localhost:1527/wombat:create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/[DERBY_SYSTEM_HOME]/wombat:create=true
+EXPECTED EXCEPTION:DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040, SQLERRMC: Failed to start
database '[DERBY_SYSTEM_HOME]/wombat:create=true', see the next exception for details.::SQLSTATE:
XJ001Java exception: 'The filename, directory name, or volume label syntax is incorrect: java.io.IOException'.
+doClientURLTest with url: jdbc:derby://localhost:1527/"wombat";create=true
+EXPECTED EXCEPTION:DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ041, SQLERRMC: Failed to create
database '"wombat"', see the next exception for details.::SQLSTATE: XBM0HDirectory [DERBY_SYSTEM_HOME]/"wombat"
cannot be created.
+doClientURLTest with url: jdbc:derby://localhost:1527/"[DERBY_SYSTEM_HOME]/wombat";create=true
+Null connection returned for url jdbc:derby://localhost:1527/"[DERBY_SYSTEM_HOME]/wombat";create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/'[DERBY_SYSTEM_HOME]/wombat';create=true
+Null connection returned for url jdbc:derby://localhost:1527/'[DERBY_SYSTEM_HOME]/wombat';create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/'wombat';create=true
+Connection info for connect(jdbc:derby://localhost:1527/'wombat';create=true, null)
+getURL() = jdbc:derby://localhost:1527/'wombat';create=true
+getUserName() = APP
+CURRENT SCHEMA = APP
+PASSED:Connection Successful with url: jdbc:derby://localhost:1527/'wombat';create=true

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java?rev=292917&r1=292916&r2=292917&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java
Fri Sep 30 21:30:43 2005
@@ -49,6 +49,19 @@
 	
 	private static String DERBY_SYSTEM_HOME = System.getProperty("derby.system.home");
 	
+	private static String CLIENT_URL_WITH_COLON1 = 
+		"jdbc:derby://localhost:1527/wombat:create=true";
+	private static String CLIENT_URL_WITH_COLON2 = 
+		"jdbc:derby://localhost:1527/"+ DERBY_SYSTEM_HOME + File.separator +"wombat:create=true";
+	private static String CLIENT_URL_WITH_DOUBLE_QUOTES1 = 
+		"jdbc:derby://localhost:1527/\"wombat\";create=true"; 
+	private static String CLIENT_URL_WITH_DOUBLE_QUOTES2 = 
+		"jdbc:derby://localhost:1527/\"" + DERBY_SYSTEM_HOME + File.separator + "wombat\";create=true";
+	private static String CLIENT_URL_WITH_SINGLE_QUOTES1 = 
+		"jdbc:derby://localhost:1527/'" + DERBY_SYSTEM_HOME + File.separator + "wombat';create=true";
+	private static String CLIENT_URL_WITH_SINGLE_QUOTES2 = 
+		"jdbc:derby://localhost:1527/'wombat';create=true";
+	
 	// URLS to check.  New urls need to also be added to the acceptsUrl table
 	private static String[] urls = new String[]
 	{
@@ -58,6 +71,16 @@
 		INVALID_URL,
 	};
 	
+	//Client URLS
+	private static String[] clientUrls = new String[]
+	{
+		CLIENT_URL_WITH_COLON1,
+		CLIENT_URL_WITH_COLON2,
+		CLIENT_URL_WITH_DOUBLE_QUOTES1,
+		CLIENT_URL_WITH_DOUBLE_QUOTES2,
+		CLIENT_URL_WITH_SINGLE_QUOTES1,
+		CLIENT_URL_WITH_SINGLE_QUOTES2
+	};
 	
 	/**
 	 * url prefix for this framework
@@ -102,6 +125,7 @@
 			checkAcceptsURL(driver);
 			testEmbeddedAttributes(driver);
 			testClientAttributes(driver);
+			doClientURLTest(driver);
 		}
 		catch (SQLException se)
 		{
@@ -321,6 +345,34 @@
 	}
 	
 	/**
+	 * Tests client URLs to see connection is successful or the correct exception is thrown.
+	 * 
+	 * @param driver
+	 * @throws SQLException
+	 */
+	private static void doClientURLTest(Driver driver){
+		if (!TestUtil.isDerbyNetClientFramework())
+			return;
+		
+		System.out.println("doClientURLTest()");
+		Properties info = null;		//test with null Properties object
+
+		for (int i = 0; i < clientUrls.length;i++)
+		{
+			String url = clientUrls[i];
+			System.out.println("doClientURLTest with url: " + replaceSystemHome(url));
+			try{
+				Connection conn = testConnect(driver,url,info);
+				if(conn != null)
+					System.out.println("PASSED:Connection Successful with url: " + replaceSystemHome(url)
);
+			}
+			catch(SQLException se){
+				System.out.println("EXPECTED EXCEPTION:"+replaceSystemHome(se.getMessage()));
+			}
+		}
+	}	
+	
+	/**
 	 * Make  java.sql.Driver.connect(String url, Properties info call) and print the status
of
 	 * the connection.
 	 * 
@@ -330,7 +382,7 @@
 	 * 
 	 * @throws SQLException on error.
 	 */
-	private static void testConnect(Driver driver, String url, Properties info) throws SQLException
+	private static Connection testConnect(Driver driver, String url, Properties info) throws
SQLException
 	{
 		String infoString = null;
 		if (info != null)
@@ -338,6 +390,11 @@
 		String urlString = replaceSystemHome(url);
 		Connection conn = driver.connect(url,info);
 		
+		if(conn == null){
+			System.out.println("Null connection returned for url "+urlString);
+			return conn;
+		}
+		
 		System.out.println("\nConnection info for connect(" + urlString + ", " + infoString +")");
 		String getUrlValue = conn.getMetaData().getURL();
 		// URL may include path of DERBY_SYSTEM_HOME for traceFile
@@ -350,7 +407,7 @@
 		rs.next();
 		System.out.println("CURRENT SCHEMA = " + rs.getString(1));
 		conn.close();
-
+		return conn;
 	}
 
 



Mime
View raw message