Search in sources :

Example 1 with StreamError

use of org.jivesoftware.smack.packet.StreamError in project ecf by eclipse.

the class PacketParserUtils method parseStreamError.

/**
 * Parses stream error packets.
 *
 * @param parser the XML parser.
 * @return an stream error packet.
 * @throws Exception if an exception occurs while parsing the packet.
 */
public static StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException {
    StreamError streamError = null;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            streamError = new StreamError(parser.getName());
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("error")) {
                done = true;
            }
        }
    }
    return streamError;
}
Also used : StreamError(org.jivesoftware.smack.packet.StreamError)

Example 2 with StreamError

use of org.jivesoftware.smack.packet.StreamError in project ecf by eclipse.

the class ReconnectionManager method connectionClosedOnError.

public void connectionClosedOnError(Exception e) {
    done = false;
    if (e instanceof XMPPException) {
        XMPPException xmppEx = (XMPPException) e;
        StreamError error = xmppEx.getStreamError();
        // Make sure the error is not null
        if (error != null) {
            String reason = error.getCode();
            if ("conflict".equals(reason)) {
                return;
            }
        }
    }
    if (this.isReconnectionAllowed()) {
        this.reconnect();
    }
}
Also used : StreamError(org.jivesoftware.smack.packet.StreamError)

Example 3 with StreamError

use of org.jivesoftware.smack.packet.StreamError in project Smack by igniterealtime.

the class PacketParserUtils method parseStreamError.

/**
 * Parses stream error packets.
 *
 * @param parser the XML parser.
 * @param outerXmlEnvironment the outer XML environment (optional).
 * @return an stream error packet.
 * @throws IOException if an I/O error occurred.
 * @throws XmlPullParserException if an error in the XML parser occurred.
 * @throws SmackParsingException if the Smack parser (provider) encountered invalid input.
 */
public static StreamError parseStreamError(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    final int initialDepth = parser.getDepth();
    List<XmlElement> extensions = new ArrayList<>();
    Map<String, String> descriptiveTexts = null;
    StreamError.Condition condition = null;
    String conditionText = null;
    XmlEnvironment streamErrorXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                String name = parser.getName();
                String namespace = parser.getNamespace();
                switch(namespace) {
                    case StreamError.NAMESPACE:
                        switch(name) {
                            case "text":
                                descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
                                break;
                            default:
                                // If it's not a text element, that is qualified by the StreamError.NAMESPACE,
                                // then it has to be the stream error code
                                condition = StreamError.Condition.fromString(name);
                                conditionText = parser.nextText();
                                if (conditionText.isEmpty()) {
                                    conditionText = null;
                                }
                                break;
                        }
                        break;
                    default:
                        PacketParserUtils.addExtensionElement(extensions, parser, name, namespace, streamErrorXmlEnvironment);
                        break;
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return new StreamError(condition, conditionText, descriptiveTexts, extensions);
}
Also used : StreamError(org.jivesoftware.smack.packet.StreamError) ArrayList(java.util.ArrayList) XmlElement(org.jivesoftware.smack.packet.XmlElement) XmlEnvironment(org.jivesoftware.smack.packet.XmlEnvironment)

Example 4 with StreamError

use of org.jivesoftware.smack.packet.StreamError in project Smack by igniterealtime.

the class ModularXmppClientToServerConnection method parseAndProcessElement.

private void parseAndProcessElement(String element) {
    try {
        XmlPullParser parser = PacketParserUtils.getParserFor(element);
        // Skip the enclosing stream open what is guaranteed to be there.
        parser.next();
        XmlPullParser.Event event = parser.getEventType();
        outerloop: while (true) {
            switch(event) {
                case START_ELEMENT:
                    final String name = parser.getName();
                    // Note that we don't handle "stream" here as it's done in the splitter.
                    switch(name) {
                        case Message.ELEMENT:
                        case IQ.IQ_ELEMENT:
                        case Presence.ELEMENT:
                            try {
                                parseAndProcessStanza(parser);
                            } finally {
                            // TODO: Here would be the following stream management code.
                            // clientHandledStanzasCount = SMUtils.incrementHeight(clientHandledStanzasCount);
                            }
                            break;
                        case "error":
                            StreamError streamError = PacketParserUtils.parseStreamError(parser, null);
                            StreamErrorException streamErrorException = new StreamErrorException(streamError);
                            currentXmppException = streamErrorException;
                            notifyWaitingThreads();
                            throw streamErrorException;
                        case "features":
                            parseFeatures(parser);
                            afterFeaturesReceived();
                            break;
                        default:
                            parseAndProcessNonza(parser);
                            break;
                    }
                    break;
                case END_DOCUMENT:
                    break outerloop;
                // fall out
                default:
            }
            event = parser.next();
        }
    } catch (XmlPullParserException | IOException | InterruptedException | StreamErrorException | SmackParsingException e) {
        notifyConnectionError(e);
    }
}
Also used : StreamErrorException(org.jivesoftware.smack.XMPPException.StreamErrorException) StreamError(org.jivesoftware.smack.packet.StreamError) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlPullParserException(org.jivesoftware.smack.xml.XmlPullParserException) IOException(java.io.IOException) SmackParsingException(org.jivesoftware.smack.parsing.SmackParsingException)

Aggregations

StreamError (org.jivesoftware.smack.packet.StreamError)4 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StreamErrorException (org.jivesoftware.smack.XMPPException.StreamErrorException)1 XmlElement (org.jivesoftware.smack.packet.XmlElement)1 XmlEnvironment (org.jivesoftware.smack.packet.XmlEnvironment)1 SmackParsingException (org.jivesoftware.smack.parsing.SmackParsingException)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)1