use of org.jivesoftware.smack.compress.packet.Failure in project Smack by igniterealtime.
the class FailureProviderTest method simpleFailureTest.
@Test
public void simpleFailureTest() throws Exception {
final String xml = "<failure xmlns='http://jabber.org/protocol/compress'><processing-failed/></failure>";
final XmlPullParser parser = PacketParserUtils.getParserFor(xml);
final Failure failure = FailureProvider.INSTANCE.parse(parser);
assertEquals(Failure.CompressFailureError.processing_failed, failure.getCompressFailureError());
}
use of org.jivesoftware.smack.compress.packet.Failure in project Smack by igniterealtime.
the class FailureProviderTest method withStanzaErrrorFailureTest.
@Test
public void withStanzaErrrorFailureTest() throws Exception {
final String xml = "<failure xmlns='http://jabber.org/protocol/compress'>" + "<setup-failed/>" + "<error xmlns='jabber:client' type='modify'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</failure>";
final XmlPullParser parser = PacketParserUtils.getParserFor(xml);
final Failure failure = FailureProvider.INSTANCE.parse(parser);
assertEquals(Failure.CompressFailureError.setup_failed, failure.getCompressFailureError());
final StanzaError error = failure.getStanzaError();
assertEquals(Condition.bad_request, error.getCondition());
}
use of org.jivesoftware.smack.compress.packet.Failure in project Smack by igniterealtime.
the class FailureProvider method parse.
@Override
public Failure parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
Failure.CompressFailureError compressFailureError = null;
StanzaError stanzaError = null;
XmlEnvironment failureXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment);
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
switch(namespace) {
case Failure.NAMESPACE:
compressFailureError = Failure.CompressFailureError.valueOf(name.replace("-", "_"));
if (compressFailureError == null) {
LOGGER.warning("Unknown element in " + Failure.NAMESPACE + ": " + name);
}
break;
case StreamOpen.CLIENT_NAMESPACE:
case StreamOpen.SERVER_NAMESPACE:
switch(name) {
case StanzaError.ERROR:
stanzaError = PacketParserUtils.parseError(parser, failureXmlEnvironment);
break;
default:
LOGGER.warning("Unknown element in " + namespace + ": " + name);
break;
}
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
// fall out
default:
}
}
return new Failure(compressFailureError, stanzaError);
}
Aggregations