mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 21:17:58 +01:00
Use error codes on connection creation failure (SMACK-78).
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2042 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
6a1cb7c2db
commit
c58b84a6e2
3 changed files with 46 additions and 9 deletions
|
@ -66,6 +66,8 @@ import java.security.cert.X509Certificate;
|
||||||
import java.security.cert.CertificateExpiredException;
|
import java.security.cert.CertificateExpiredException;
|
||||||
import java.security.cert.CertificateNotYetValidException;
|
import java.security.cert.CertificateNotYetValidException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an SSL connection to a XMPP server.
|
* Creates an SSL connection to a XMPP server.
|
||||||
|
@ -79,7 +81,11 @@ public class SSLXMPPConnection extends XMPPConnection {
|
||||||
* SSL port (5223).
|
* SSL port (5223).
|
||||||
*
|
*
|
||||||
* @param host the XMPP host.
|
* @param host the XMPP host.
|
||||||
* @throws XMPPException if an error occurs making the connection.
|
* @throws XMPPException if an error occurs while trying to establish the connection.
|
||||||
|
* Two possible errors can occur which will be wrapped by an XMPPException --
|
||||||
|
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
||||||
|
* 502). The error codes and wrapped exceptions can be used to present more
|
||||||
|
* appropiate error messages to end-users.
|
||||||
*/
|
*/
|
||||||
public SSLXMPPConnection(String host) throws XMPPException {
|
public SSLXMPPConnection(String host) throws XMPPException {
|
||||||
this(host, 5223);
|
this(host, 5223);
|
||||||
|
@ -90,7 +96,11 @@ public class SSLXMPPConnection extends XMPPConnection {
|
||||||
*
|
*
|
||||||
* @param host the XMPP host.
|
* @param host the XMPP host.
|
||||||
* @param port the port to use for the connection (default XMPP SSL port is 5223).
|
* @param port the port to use for the connection (default XMPP SSL port is 5223).
|
||||||
* @throws XMPPException if an error occurs making the connection.
|
* @throws XMPPException if an error occurs while trying to establish the connection.
|
||||||
|
* Two possible errors can occur which will be wrapped by an XMPPException --
|
||||||
|
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
||||||
|
* 502). The error codes and wrapped exceptions can be used to present more
|
||||||
|
* appropiate error messages to end-users.
|
||||||
*/
|
*/
|
||||||
public SSLXMPPConnection(String host, int port) throws XMPPException {
|
public SSLXMPPConnection(String host, int port) throws XMPPException {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
@ -100,10 +110,12 @@ public class SSLXMPPConnection extends XMPPConnection {
|
||||||
this.socket = sslFactory.createSocket(host, port);
|
this.socket = sslFactory.createSocket(host, port);
|
||||||
}
|
}
|
||||||
catch (UnknownHostException uhe) {
|
catch (UnknownHostException uhe) {
|
||||||
throw new XMPPException("Could not connect to " + host + ":" + port + ".", uhe);
|
throw new XMPPException("Could not connect to " + host + ":" + port + ".",
|
||||||
|
new XMPPError(504), uhe);
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".", ioe);
|
throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".",
|
||||||
|
new XMPPError(502), ioe);
|
||||||
}
|
}
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,11 @@ public class XMPPConnection {
|
||||||
* be used.
|
* be used.
|
||||||
*
|
*
|
||||||
* @param host the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
* @param host the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
||||||
* @throws XMPPException if an error occurs while trying to establish a connection.
|
* @throws XMPPException if an error occurs while trying to establish the connection.
|
||||||
|
* Two possible errors can occur which will be wrapped by an XMPPException --
|
||||||
|
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
||||||
|
* 502). The error codes and wrapped exceptions can be used to present more
|
||||||
|
* appropiate error messages to end-users.
|
||||||
*/
|
*/
|
||||||
public XMPPConnection(String host) throws XMPPException {
|
public XMPPConnection(String host) throws XMPPException {
|
||||||
this(host, 5222);
|
this(host, 5222);
|
||||||
|
@ -149,7 +153,11 @@ public class XMPPConnection {
|
||||||
*
|
*
|
||||||
* @param host the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
* @param host the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
||||||
* @param port the port on the server that should be used; e.g. <tt>5222</tt>.
|
* @param port the port on the server that should be used; e.g. <tt>5222</tt>.
|
||||||
* @throws XMPPException if an error occurs while trying to establish a connection.
|
* @throws XMPPException if an error occurs while trying to establish the connection.
|
||||||
|
* Two possible errors can occur which will be wrapped by an XMPPException --
|
||||||
|
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
||||||
|
* 502). The error codes and wrapped exceptions can be used to present more
|
||||||
|
* appropiate error messages to end-users.
|
||||||
*/
|
*/
|
||||||
public XMPPConnection(String host, int port) throws XMPPException {
|
public XMPPConnection(String host, int port) throws XMPPException {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
@ -158,10 +166,12 @@ public class XMPPConnection {
|
||||||
this.socket = new Socket(host, port);
|
this.socket = new Socket(host, port);
|
||||||
}
|
}
|
||||||
catch (UnknownHostException uhe) {
|
catch (UnknownHostException uhe) {
|
||||||
throw new XMPPException("Could not connect to " + host + ":" + port + ".", uhe);
|
throw new XMPPException("Could not connect to " + host + ":" + port + ".",
|
||||||
|
new XMPPError(502), uhe);
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".", ioe);
|
throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".",
|
||||||
|
new XMPPError(502), ioe);
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
@ -601,7 +611,8 @@ public class XMPPConnection {
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
|
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
throw new XMPPException("XMPPError establishing connection with server.", ioe);
|
throw new XMPPException("XMPPError establishing connection with server.",
|
||||||
|
new XMPPError(502), ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If debugging is enabled, we open a window and write out all network traffic.
|
// If debugging is enabled, we open a window and write out all network traffic.
|
||||||
|
|
|
@ -121,6 +121,20 @@ public class XMPPException extends Exception {
|
||||||
this.wrappedThrowable = wrappedThrowable;
|
this.wrappedThrowable = wrappedThrowable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new XMPPException with a description of the exception, an XMPPError,
|
||||||
|
* and the Throwable that was the root cause of the exception.
|
||||||
|
*
|
||||||
|
* @param message a description of the exception.
|
||||||
|
* @param error the root cause of the exception.
|
||||||
|
* @param wrappedThrowable the root cause of the exception.
|
||||||
|
*/
|
||||||
|
public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) {
|
||||||
|
super(message);
|
||||||
|
this.error = error;
|
||||||
|
this.wrappedThrowable = wrappedThrowable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new XMPPException with a description of the exception and the
|
* Creates a new XMPPException with a description of the exception and the
|
||||||
* XMPPException that was the root cause of the exception.
|
* XMPPException that was the root cause of the exception.
|
||||||
|
|
Loading…
Reference in a new issue