Mercurial > hg > monetdb-java
changeset 225:5ddb1f20d5d5
Socket may also throw an UnknownHostException. Add it to MapiSocket.connect() and catch it in MonetConnection(Properties props).
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 03 May 2018 17:48:16 +0200 (2018-05-03) |
parents | ea729e0cf24d |
children | 5ea126405bac |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java |
diffstat | 2 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -12,6 +12,7 @@ import java.io.File; import java.io.IOException; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -248,8 +249,8 @@ public class MonetConnection // check mandatory input arguments if (hostname == null || hostname.isEmpty()) throw new IllegalArgumentException("Missing or empty host name"); - if (port <= 0) - throw new IllegalArgumentException("Invalid port number. It should not be " + (port < 0 ? "negative" : "0")); + if (port <= 0 || port > 65535) + throw new IllegalArgumentException("Invalid port number: " + port + ". It should not be " + (port < 0 ? "negative" : (port > 65535 ? "larger than 65535" : "0"))); if (username == null || username.isEmpty()) throw new IllegalArgumentException("Missing or empty user name"); if (password == null || password.isEmpty()) @@ -305,6 +306,8 @@ public class MonetConnection String error = in.waitForPrompt(); if (error != null) throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001"); + } catch (UnknownHostException e) { + throw new SQLNonTransientConnectionException("Unknown Host (" + hostname + "): " + e.getMessage(), "08006"); } catch (IOException e) { throw new SQLNonTransientConnectionException("Unable to connect (" + hostname + ":" + port + "): " + e.getMessage(), "08006"); } catch (MCLParseException e) {
--- a/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java +++ b/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java @@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingExcept import java.io.Writer; import java.net.Socket; import java.net.SocketException; +import java.net.UnknownHostException; import java.net.URI; import java.net.URISyntaxException; import java.security.MessageDigest; @@ -242,17 +243,19 @@ public final class MapiSocket { * thrown when a redirect is encountered. * * @param host the hostname, or null for the loopback address - * @param port the port number + * @param port the port number (must be between 0 and 65535, inclusive) * @param user the username * @param pass the password * @return A List with informational (warning) messages. If this * list is empty; then there are no warnings. * @throws IOException if an I/O error occurs when creating the socket + * @throws SocketException - if there is an error in the underlying protocol, such as a TCP error. + * @throws UnknownHostException if the IP address of the host could not be determined * @throws MCLParseException if bogus data is received * @throws MCLException if an MCL related error occurs */ public List<String> connect(String host, int port, String user, String pass) - throws IOException, MCLParseException, MCLException + throws IOException, UnknownHostException, SocketException, MCLParseException, MCLException { // Wrap around the internal connect that needs to know if it // should really make a TCP connection or not. @@ -260,7 +263,7 @@ public final class MapiSocket { } private List<String> connect(String host, int port, String user, String pass, boolean makeConnection) - throws IOException, MCLParseException, MCLException + throws IOException, UnknownHostException, SocketException, MCLParseException, MCLException { if (ttl-- <= 0) throw new MCLException("Maximum number of redirects reached, aborting connection attempt. Sorry.");