1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-09 04:21:08 +01:00

Merge branch '4.3'

This commit is contained in:
Florian Schmaus 2018-06-23 17:18:17 +02:00
commit ce4f3352a2
33 changed files with 119 additions and 77 deletions

View file

@ -69,6 +69,10 @@ public abstract class XMPPException extends Exception {
super(message, wrappedThrowable);
}
/**
* An exception caused by an XMPP error stanza response on the protocol level. You can examine the underlying
* {@link StanzaError} by calling {@link #getStanzaError()}.
*/
public static class XMPPErrorException extends XMPPException {
/**
*
@ -123,11 +127,23 @@ public abstract class XMPPException extends Exception {
* one.
*
* @return the XMPPError associated with this exception.
* @deprecated use {@link #getStanzaError()} instead.
*/
@Deprecated
// TODO Remove in Smack 4.4.
public StanzaError getXMPPError() {
return error;
}
/**
* Returns the stanza error extension element associated with this exception.
*
* @return the stanza error extension element associated with this exception.
*/
public StanzaError getStanzaError() {
return error;
}
/**
* Get the request which triggered the error response causing this exception.
*

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus.
* Copyright 2017-2018 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
entityBare,
domainFull,
domainBare,
any,
;
}
@ -55,6 +56,8 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
return jid.isDomainFullJid();
case domainBare:
return jid.isDomainBareJid();
case any:
return true;
default:
throw new AssertionError();
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus.
* Copyright 2017-2018 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ public final class FromTypeFilter extends AbstractJidTypeFilter {
public static final FromTypeFilter ENTITY_BARE_JID = new FromTypeFilter(JidType.entityBare);
public static final FromTypeFilter DOMAIN_FULL_JID = new FromTypeFilter(JidType.domainFull);
public static final FromTypeFilter DOMAIN_BARE_JID = new FromTypeFilter(JidType.domainBare);
public static final FromTypeFilter FROM_ANY_JID = new FromTypeFilter(JidType.any);
private FromTypeFilter(JidType jidType) {
super(jidType);

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus.
* Copyright 2017-2018 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ public final class ToTypeFilter extends AbstractJidTypeFilter {
public static final ToTypeFilter ENTITY_BARE_JID = new ToTypeFilter(JidType.entityBare);
public static final ToTypeFilter DOMAIN_FULL_JID = new ToTypeFilter(JidType.domainFull);
public static final ToTypeFilter DOMAIN_BARE_JID = new ToTypeFilter(JidType.domainBare);
public static final ToTypeFilter TO_ANY_JID = new ToTypeFilter(JidType.any);
public static final StanzaFilter ENTITY_FULL_OR_BARE_JID = new OrFilter(ENTITY_FULL_JID, ENTITY_BARE_JID);

View file

@ -62,9 +62,16 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* @see <a href="http://xmpp.org/rfcs/rfc6120.html#stanzas-error-syntax">RFC 6120 - 8.3.2 Syntax: The Syntax of XMPP error stanzas</a>
*/
// TODO Use StanzaErrorTextElement here.
public class StanzaError extends AbstractError {
public class StanzaError extends AbstractError implements ExtensionElement {
public static final String ERROR_CONDITION_AND_TEXT_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas";
/**
* TODO describe me.
*/
@Deprecated
public static final String NAMESPACE = ERROR_CONDITION_AND_TEXT_NAMESPACE;
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas";
public static final String ERROR = "error";
private static final Logger LOGGER = Logger.getLogger(StanzaError.class.getName());
@ -117,7 +124,7 @@ public class StanzaError extends AbstractError {
*/
public StanzaError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<ExtensionElement> extensions, Stanza stanza) {
super(descriptiveTexts, NAMESPACE, extensions);
super(descriptiveTexts, ERROR_CONDITION_AND_TEXT_NAMESPACE, extensions);
this.condition = Objects.requireNonNull(condition, "condition must not be null");
this.stanza = stanza;
// Some implementations may send the condition as non-empty element containing the empty string, that is
@ -197,20 +204,34 @@ public class StanzaError extends AbstractError {
return sb.toString();
}
@Override
public String getElementName() {
return ERROR;
}
@Override
public String getNamespace() {
return StreamOpen.CLIENT_NAMESPACE;
}
/**
* Returns the error as XML.
*
* @return the error as XML.
*/
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(ERROR);
return toXML(null);
}
@Override
public XmlStringBuilder toXML(String enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
xml.attribute("type", type.toString());
xml.optAttribute("by", errorGenerator);
xml.rightAngleBracket();
xml.halfOpenElement(condition.toString());
xml.xmlnsAttribute(NAMESPACE);
xml.xmlnsAttribute(ERROR_CONDITION_AND_TEXT_NAMESPACE);
if (conditionText != null) {
xml.rightAngleBracket();
xml.escape(conditionText);
@ -222,7 +243,7 @@ public class StanzaError extends AbstractError {
addDescriptiveTextsAndExtensions(xml);
xml.closeElement(ERROR);
xml.closeElement(this);
return xml;
}

View file

@ -18,7 +18,7 @@ package org.jivesoftware.smack.packet;
public class StanzaErrorTextElement extends AbstractTextElement {
public static final String NAMESPACE = StanzaError.NAMESPACE;
public static final String NAMESPACE = StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE;
public StanzaErrorTextElement(String text, String lang) {
super(text, lang);

View file

@ -855,7 +855,7 @@ public class PacketParserUtils {
String name = parser.getName();
String namespace = parser.getNamespace();
switch (namespace) {
case StanzaError.NAMESPACE:
case StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE:
switch (name) {
case Stanza.TEXT:
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);