2003-01-13 17:58:47 +01:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:53:30 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack;
|
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2005-11-08 21:10:33 +01:00
|
|
|
import org.jivesoftware.smack.packet.StreamError;
|
2006-07-18 07:14:33 +02:00
|
|
|
import org.jivesoftware.smack.packet.XMPPError;
|
2003-03-07 20:54:10 +01:00
|
|
|
|
2003-01-28 06:49:25 +01:00
|
|
|
/**
|
|
|
|
* A generic exception that is thrown when an error occurs performing an
|
2003-03-14 17:00:03 +01:00
|
|
|
* XMPP operation. XMPP servers can respond to error conditions with an error code
|
|
|
|
* and textual description of the problem, which are encapsulated in the XMPPError
|
2005-11-08 21:10:33 +01:00
|
|
|
* class. When appropriate, an XMPPError instance is attached instances of this exception.<p>
|
|
|
|
*
|
2014-03-12 11:50:05 +01:00
|
|
|
* When a stream error occurred, the server will send a stream error to the client before
|
2005-11-08 21:10:33 +01:00
|
|
|
* closing the connection. Stream errors are unrecoverable errors. When a stream error
|
|
|
|
* is sent to the client an XMPPException will be thrown containing the StreamError sent
|
|
|
|
* by the server.
|
2003-01-28 06:49:25 +01:00
|
|
|
*
|
2003-03-14 17:00:03 +01:00
|
|
|
* @see XMPPError
|
2003-01-28 06:49:25 +01:00
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
2014-03-12 11:50:05 +01:00
|
|
|
public abstract class XMPPException extends Exception {
|
2013-03-23 12:59:08 +01:00
|
|
|
private static final long serialVersionUID = 6881651633890968625L;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2003-01-28 06:49:25 +01:00
|
|
|
|
2003-03-14 17:00:03 +01:00
|
|
|
/**
|
|
|
|
* Creates a new XMPPException.
|
|
|
|
*/
|
2014-03-12 11:50:05 +01:00
|
|
|
protected XMPPException() {
|
2003-01-13 17:58:47 +01:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2003-03-14 17:00:03 +01:00
|
|
|
/**
|
|
|
|
* Creates a new XMPPException with a description of the exception.
|
|
|
|
*
|
|
|
|
* @param message description of the exception.
|
|
|
|
*/
|
2014-03-12 11:50:05 +01:00
|
|
|
protected XMPPException(String message) {
|
2003-01-13 17:58:47 +01:00
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
2003-03-14 17:00:03 +01:00
|
|
|
/**
|
|
|
|
* Creates a new XMPPException with a description of the exception and the
|
|
|
|
* Throwable that was the root cause of the exception.
|
|
|
|
*
|
|
|
|
* @param message a description of the exception.
|
|
|
|
* @param wrappedThrowable the root cause of the exception.
|
|
|
|
*/
|
2014-03-12 11:50:05 +01:00
|
|
|
protected XMPPException(String message, Throwable wrappedThrowable) {
|
2013-11-11 09:33:31 +01:00
|
|
|
super(message, wrappedThrowable);
|
2003-08-19 18:32:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
public static class XMPPErrorException extends XMPPException {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 212790389529249604L;
|
|
|
|
private final XMPPError error;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new XMPPException with the XMPPError that was the root case of the exception.
|
|
|
|
*
|
|
|
|
* @param error the root cause of the exception.
|
|
|
|
*/
|
|
|
|
public XMPPErrorException(XMPPError error) {
|
|
|
|
super();
|
|
|
|
this.error = error;
|
|
|
|
}
|
2003-03-07 20:47:31 +01:00
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
/**
|
|
|
|
* 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 XMPPErrorException(String message, XMPPError error, Throwable wrappedThrowable) {
|
|
|
|
super(message, wrappedThrowable);
|
|
|
|
this.error = error;
|
|
|
|
}
|
2003-03-14 17:00:03 +01:00
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
/**
|
|
|
|
* Creates a new XMPPException with a description of the exception and the XMPPException
|
|
|
|
* that was the root cause of the exception.
|
|
|
|
*
|
|
|
|
* @param message a description of the exception.
|
|
|
|
* @param error the root cause of the exception.
|
|
|
|
*/
|
|
|
|
public XMPPErrorException(String message, XMPPError error) {
|
|
|
|
super(message);
|
|
|
|
this.error = error;
|
|
|
|
}
|
2013-03-23 12:59:08 +01:00
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
/**
|
|
|
|
* Returns the XMPPError associated with this exception, or <tt>null</tt> if there isn't
|
|
|
|
* one.
|
|
|
|
*
|
|
|
|
* @return the XMPPError associated with this exception.
|
|
|
|
*/
|
|
|
|
public XMPPError getXMPPError() {
|
|
|
|
return error;
|
|
|
|
}
|
2005-11-08 21:10:33 +01:00
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
@Override
|
|
|
|
public String getMessage() {
|
|
|
|
String superMessage = super.getMessage();
|
|
|
|
if (superMessage != null) {
|
|
|
|
return superMessage;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return error.toString();
|
|
|
|
}
|
2003-10-13 22:42:22 +02:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
public static void ifHasErrorThenThrow(Stanza packet) throws XMPPErrorException {
|
2014-08-16 00:04:24 +02:00
|
|
|
XMPPError xmppError = packet.getError();
|
|
|
|
if (xmppError != null) {
|
|
|
|
throw new XMPPErrorException(xmppError);
|
|
|
|
}
|
|
|
|
}
|
2003-10-13 22:42:22 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
public static class StreamErrorException extends XMPPException {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 3400556867134848886L;
|
|
|
|
private final StreamError streamError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new XMPPException with the stream error that was the root case of the
|
|
|
|
* exception. When a stream error is received from the server then the underlying connection
|
|
|
|
* will be closed by the server.
|
|
|
|
*
|
|
|
|
* @param streamError the root cause of the exception.
|
|
|
|
*/
|
|
|
|
public StreamErrorException(StreamError streamError) {
|
2015-02-28 10:16:32 +01:00
|
|
|
super(streamError.getCondition().toString()
|
|
|
|
+ " You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions\n"
|
|
|
|
+ streamError.toString());
|
2014-03-12 11:50:05 +01:00
|
|
|
this.streamError = streamError;
|
2003-10-13 22:42:22 +02:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the StreamError associated with this exception. The underlying TCP connection is
|
|
|
|
* closed by the server after sending the stream error to the client.
|
|
|
|
*
|
|
|
|
* @return the StreamError associated with this exception.
|
|
|
|
*/
|
|
|
|
public StreamError getStreamError() {
|
|
|
|
return streamError;
|
2005-11-08 21:10:33 +01:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
|
2003-09-19 09:54:34 +02:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|