Commit 0d5d5867 authored by Tom Evans's avatar Tom Evans

OF-2: Logging for common exceptions less verbose

Modified older patch submitted by David Horowitz to accommodate more
recent changes.
parent 4a809ace
...@@ -24,6 +24,8 @@ import java.io.IOException; ...@@ -24,6 +24,8 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
...@@ -270,18 +272,24 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -270,18 +272,24 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
List<DNSUtil.HostAddress> hosts = DNSUtil.resolveXMPPDomain(hostname, port); List<DNSUtil.HostAddress> hosts = DNSUtil.resolveXMPPDomain(hostname, port);
for (Iterator<DNSUtil.HostAddress> it = hosts.iterator(); it.hasNext();) { for (Iterator<DNSUtil.HostAddress> it = hosts.iterator(); it.hasNext();) {
try { try {
socket = new Socket();
DNSUtil.HostAddress address = it.next(); DNSUtil.HostAddress address = it.next();
realHostname = address.getHost(); realHostname = address.getHost();
realPort = address.getPort(); realPort = address.getPort();
Log.debug("LocalOutgoingServerSession: OS - Trying to connect to " + hostname + ":" + port + Log.debug("LocalOutgoingServerSession: OS - Trying to connect to " + hostname + ":" + port +
"(DNS lookup: " + realHostname + ":" + realPort + ")"); "(DNS lookup: " + realHostname + ":" + realPort + ")");
// Establish a TCP connection to the Receiving Server // Establish a TCP connection to the Receiving Server
socket.connect(new InetSocketAddress(realHostname, realPort), socket = new Socket();
RemoteServerManager.getSocketTimeout()); socket.connect(new InetSocketAddress(realHostname, realPort), RemoteServerManager.getSocketTimeout());
Log.debug("LocalOutgoingServerSession: OS - Plain connection to " + hostname + ":" + port + " successful"); Log.debug("LocalOutgoingServerSession: OS - Plain connection to " + hostname + ":" + port + " successful");
break; break;
} }
catch (UnknownHostException uhe) {
Log.warn("Unkown host: " + realHostname);
}
catch (SocketTimeoutException ste) {
Log.error("Connection Timeed out trying to connect to remote server: " + hostname +
"(DNS lookup: " + realHostname + ":" + realPort + ")");
}
catch (Exception e) { catch (Exception e) {
Log.warn("Error trying to connect to remote server: " + hostname + Log.warn("Error trying to connect to remote server: " + hostname +
"(DNS lookup: " + realHostname + ":" + realPort + ")", e); "(DNS lookup: " + realHostname + ":" + realPort + ")", e);
...@@ -295,7 +303,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -295,7 +303,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
} }
} }
} }
if (!socket.isConnected()) { if (socket == null || !socket.isConnected()) {
return null; return null;
} }
...@@ -374,32 +382,27 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -374,32 +382,27 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
Log.debug("LocalOutgoingServerSession: OS - Error, <starttls> was not received"); Log.debug("LocalOutgoingServerSession: OS - Error, <starttls> was not received");
} }
} }
// Something went wrong so close the connection and try server dialback over
// a plain connection
if (connection != null) {
connection.close();
}
} }
catch (SSLHandshakeException e) { catch (SSLHandshakeException e) {
Log.debug("LocalOutgoingServerSession: Handshake error while creating secured outgoing session to remote " + Log.debug("LocalOutgoingServerSession: SSL Handshake error while creating secured outgoing session to remote " +
"server: " + hostname + "(DNS lookup: " + realHostname + ":" + realPort + "server: " + hostname + "(DNS lookup: " + realHostname + ":" + realPort + "): " + e.getMessage());
")", e);
// Close the connection
if (connection != null) {
connection.close();
}
} }
catch (XmlPullParserException e) { catch (XmlPullParserException e) {
Log.warn("Error creating secured outgoing session to remote server: " + hostname + Log.warn("Error creating secured outgoing session to remote server: " + hostname +
"(DNS lookup: " + realHostname + ":" + realPort + ")", e); "(DNS lookup: " + realHostname + ":" + realPort + "): ", e);
// Close the connection }
if (connection != null) { catch (UnknownHostException uhe) {
connection.close(); Log.warn("Unkown host: " + realHostname);
} }
catch (SocketTimeoutException ste) {
Log.error("Connection Timeed out trying to connect to remote server: " + hostname +
"(DNS lookup: " + realHostname + ":" + realPort + ")");
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error creating secured outgoing session to remote server: " + hostname + Log.error("Error creating secured outgoing session to remote server: " + hostname +
"(DNS lookup: " + realHostname + ":" + realPort + ")", e); "(DNS lookup: " + realHostname + ":" + realPort + ")", e);
}
finally {
// Close the connection // Close the connection
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment