diff --git a/jdbc/src/java/org/apache/hive/jdbc/Utils.java b/jdbc/src/java/org/apache/hive/jdbc/Utils.java index 2d1bb5e..d907f0a 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/Utils.java +++ b/jdbc/src/java/org/apache/hive/jdbc/Utils.java @@ -193,10 +193,14 @@ public static JdbcConnectionParams parseURL(String uri) throws IllegalArgumentEx 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/HiveServer2Host@YOUR-REALM.COM - if((jdbcURI.getPath().equals("")) && (jdbcURI.getHost()==null)){ - throw new IllegalArgumentException("Bad URL format and it should be in the format of jdbc:hive2://:/"); + 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()); diff --git a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java index 12472cc..fd990a8 100644 --- a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -196,18 +196,23 @@ protected void tearDown() throws Exception { } public void testBadURL() throws Exception { - Class.forName(driverName); - try{ + checkBadUrl("jdbc:hive2://localhost:10000;principal=test"); + checkBadUrl("jdbc:hive2://localhost:10000;" + + "principal=hive/HiveServer2Host@YOUR-REALM.COM"); + 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://:/", 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();