mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 03:52:06 +01:00
[websocket] Do not swallow exceptions and use QName
Follow up on c4d11eae299e ("[websocket] Reduce fragility")
This commit is contained in:
parent
2ebffa7615
commit
097ab20485
1 changed files with 10 additions and 4 deletions
|
@ -17,9 +17,11 @@
|
||||||
package org.jivesoftware.smack.websocket.impl;
|
package org.jivesoftware.smack.websocket.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackFuture;
|
import org.jivesoftware.smack.SmackFuture;
|
||||||
import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
|
import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
|
||||||
|
@ -28,6 +30,8 @@ import org.jivesoftware.smack.packet.TopLevelStreamElement;
|
||||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smack.websocket.WebSocketException;
|
import org.jivesoftware.smack.websocket.WebSocketException;
|
||||||
|
import org.jivesoftware.smack.websocket.elements.WebSocketCloseElement;
|
||||||
|
import org.jivesoftware.smack.websocket.elements.WebSocketOpenElement;
|
||||||
import org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint;
|
import org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||||
|
@ -107,9 +111,10 @@ public abstract class AbstractWebSocket {
|
||||||
XmlPullParser parser;
|
XmlPullParser parser;
|
||||||
try {
|
try {
|
||||||
parser = PacketParserUtils.getParserFor(text);
|
parser = PacketParserUtils.getParserFor(text);
|
||||||
parser.nextTag();
|
QName qname = parser.getQName();
|
||||||
return "open".equals(parser.getName()) && "urn:ietf:params:xml:ns:xmpp-framing".equals(parser.getNamespace());
|
return qname.equals(WebSocketOpenElement.QNAME);
|
||||||
} catch (XmlPullParserException | IOException e) {
|
} catch (XmlPullParserException | IOException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not inspect \"" + text + "\" for open element", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,9 +123,10 @@ public abstract class AbstractWebSocket {
|
||||||
XmlPullParser parser;
|
XmlPullParser parser;
|
||||||
try {
|
try {
|
||||||
parser = PacketParserUtils.getParserFor(text);
|
parser = PacketParserUtils.getParserFor(text);
|
||||||
parser.nextTag();
|
QName qname = parser.getQName();
|
||||||
return "close".equals(parser.getName()) && "urn:ietf:params:xml:ns:xmpp-framing".equals(parser.getNamespace());
|
return qname.equals(WebSocketCloseElement.QNAME);
|
||||||
} catch (XmlPullParserException | IOException e) {
|
} catch (XmlPullParserException | IOException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not inspect \"" + text + "\" for close element", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue