Search in sources :

Example 1 with Failure

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());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Failure(org.jivesoftware.smack.compress.packet.Failure) Test(org.junit.Test)

Example 2 with Failure

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());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Failure(org.jivesoftware.smack.compress.packet.Failure) StanzaError(org.jivesoftware.smack.packet.StanzaError) Test(org.junit.Test)

Example 3 with Failure

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);
}
Also used : Failure(org.jivesoftware.smack.compress.packet.Failure) StanzaError(org.jivesoftware.smack.packet.StanzaError) XmlEnvironment(org.jivesoftware.smack.packet.XmlEnvironment)

Aggregations

Failure (org.jivesoftware.smack.compress.packet.Failure)3 StanzaError (org.jivesoftware.smack.packet.StanzaError)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)2 Test (org.junit.Test)2 XmlEnvironment (org.jivesoftware.smack.packet.XmlEnvironment)1