Author: hashutosh
Date: Mon Jul 8 14:52:50 2013
New Revision: 1500781
URL: http://svn.apache.org/r1500781
Log:
HIVE-4802 : Fix url check for missing / or /<db> after hostname in jdb uri
(Thejas Nair via Ashutosh Chauhan)
Modified:
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java
hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java
URL:
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java?rev=1500781&r1=1500780&r2=1500781&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/Utils.java Mon Jul 8
14:52:50 2013
@@ -193,10 +193,14 @@ public class Utils {
URI jdbcURI = URI.create(uri.substring(URI_JDBC_PREFIX.length()));
- // If the url format contains like this, then condition will get execute.
+ //Check to prevent unintentional use of embedded mode. A missing "/" can
+ // to separate the 'path' portion of URI can result in this.
+ //The missing "/" common typo while using secure mode, eg of such url -
//
jdbc:hive2://localhost:10000;principal=hive/[email protected]
- if((jdbcURI.getPath().equals("")) && (jdbcURI.getHost()==null)){
- throw new IllegalArgumentException("Bad URL format and it should be in
the format of jdbc:hive2://<hostame>:<port>/<DB_name>");
+ if((jdbcURI.getAuthority() != null) && (jdbcURI.getHost()==null)){
+ throw new IllegalArgumentException("Bad URL format. Hostname not found "
+ + " in authority part of the url: " + jdbcURI.getAuthority()
+ + ". Are you missing a '/' after the hostname ?");
}
connParams.setHost(jdbcURI.getHost());
Modified: hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
URL:
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1500781&r1=1500780&r2=1500781&view=diff
==============================================================================
--- hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
(original)
+++ hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java Mon Jul
8 14:52:50 2013
@@ -196,18 +196,23 @@ public class TestJdbcDriver2 extends Tes
}
public void testBadURL() throws Exception {
- Class.forName(driverName);
- try{
+ checkBadUrl("jdbc:hive2://localhost:10000;principal=test");
+ checkBadUrl("jdbc:hive2://localhost:10000;" +
+ "principal=hive/[email protected]");
+ checkBadUrl("jdbc:hive2://localhost:10000test");
+ }
-
DriverManager.getConnection("jdbc:hive2://localhost:10000;principal=test", "",
"");
- fail("should have thrown IllegalArgumentException but did not ");
- }catch(IllegalArgumentException i){
- assertEquals("Bad URL format and it should be in the format of
jdbc:hive2://<hostame>:<port>/<DB_name>", i.getMessage());
- }
+ private void checkBadUrl(String url) throws SQLException {
+ try{
+ DriverManager.getConnection(url, "", "");
+ fail("should have thrown IllegalArgumentException but did not ");
+ }catch(IllegalArgumentException i){
+ assertTrue(i.getMessage().contains("Bad URL format. Hostname not found "
+ + " in authority part of the url"));
+ }
}
-
public void testDataTypes2() throws Exception {
Statement stmt = con.createStatement();