1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Merge remote-tracking branch 'my/master'

This commit is contained in:
Florian Schmaus 2016-12-07 21:20:02 +01:00
commit b558a128c3
30 changed files with 203 additions and 136 deletions

View file

@ -248,11 +248,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/
private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(
// @formatter:off
// CHECKSTYLE:OFF
new SmackExecutorThreadFactory( // threadFactory
this,
"Cached Executor"
)
// @formatter:on
// CHECKSTYLE:ON
);
/**

View file

@ -149,7 +149,7 @@ public final class SmackConfiguration {
* @param mech the SASL mechanism to be added
*/
public static void addSaslMech(String mech) {
if(! defaultMechs.contains(mech) ) {
if(!defaultMechs.contains(mech)) {
defaultMechs.add(mech);
}
}

View file

@ -17,9 +17,11 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jxmpp.jid.Jid;
/**
* A generic exception that is thrown when an error occurs performing an
@ -72,48 +74,28 @@ public abstract class XMPPException extends Exception {
*/
private static final long serialVersionUID = 212790389529249604L;
private final XMPPError error;
private final Stanza stanza;
/**
* Creates a new XMPPErrorException with the given builder.
*
* @param xmppErrorBuilder
* @deprecated Use {@link #XMPPErrorException(Stanza, XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(XMPPError.Builder xmppErrorBuilder) {
this(xmppErrorBuilder.build());
this(null, xmppErrorBuilder.build());
}
/**
* Creates a new XMPPException with the XMPPError that was the root case of the exception.
* Creates a new XMPPErrorException with the XMPPError that was the root case of the exception.
*
* @param error the root cause of the exception.
*/
public XMPPErrorException(XMPPError error) {
public XMPPErrorException(Stanza stanza, XMPPError error) {
super();
this.error = error;
}
/**
* 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.
* @deprecated use {@link #XMPPException.XMPPErrorException(XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(String message, XMPPError error, Throwable wrappedThrowable) {
super(message, wrappedThrowable);
this.error = error;
}
/**
* 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.
* @deprecated use {@link #XMPPException.XMPPErrorException(XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(String message, XMPPError error) {
super(message);
this.error = error;
this.stanza = stanza;
}
/**
@ -128,23 +110,53 @@ public abstract class XMPPException extends Exception {
@Override
public String getMessage() {
String superMessage = super.getMessage();
if (superMessage != null) {
return superMessage;
}
else {
return error.toString();
StringBuilder sb = new StringBuilder();
if (stanza != null) {
Jid from = stanza.getFrom();
if (from != null) {
sb.append("XMPP error reply received from " + from + ": ");
}
}
sb.append(error);
return sb.toString();
}
public static void ifHasErrorThenThrow(Stanza packet) throws XMPPErrorException {
XMPPError xmppError = packet.getError();
if (xmppError != null) {
throw new XMPPErrorException(xmppError);
throw new XMPPErrorException(packet, xmppError);
}
}
}
public static class FailedNonzaException extends XMPPException {
/**
*
*/
private static final long serialVersionUID = 1L;
private final XMPPError.Condition condition;
private final Nonza nonza;
public FailedNonzaException(Nonza nonza, XMPPError.Condition condition) {
this.condition = condition;
this.nonza = nonza;
}
public XMPPError.Condition getCondition() {
return condition;
}
public Nonza getNonza() {
return nonza;
}
}
public static class StreamErrorException extends XMPPException {
/**
*

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2015 Florian Schmaus
* Copyright © 2015-2016 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ public class UnparsedIQ extends IQ {
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
throw new UnsupportedOperationException();
xml.escape(content);
return xml;
}
}

View file

@ -39,7 +39,7 @@ public class ProxyInfo
private ProxyType proxyType;
private final ProxySocketConnection proxySocketConnection;
public ProxyInfo( ProxyType pType, String pHost, int pPort, String pUser,
public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser,
String pPass)
{
this.proxyType = pType;

View file

@ -983,9 +983,9 @@ public class PacketParserUtils {
private static String getLanguageAttribute(XmlPullParser parser) {
// CHECKSTYLE:OFF
for (int i = 0; i < parser.getAttributeCount(); i++) {
// CHECKSTYLE:ON
String attributeName = parser.getAttributeName(i);
if ( "xml:lang".equals(attributeName) ||
// CHECKSTYLE:ON
("lang".equals(attributeName) &&
"xml".equals(parser.getAttributePrefix(i)))) {
// CHECKSTYLE:OFF

View file

@ -249,7 +249,7 @@ public class StringUtils {
*/
public static String encodeHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_CHARS[v >>> 4];
hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];