Java 类org.jivesoftware.smack.XMPPException.StreamErrorException 实例源码

项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Creates a new XMPP connection over TCP (optionally using proxies).
 * <p>
 * Note that XMPPTCPConnection constructors do not establish a connection to the server
 * and you must call {@link #connect()}.
 * </p>
 *
 * @param config the connection configuration.
 */
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
    super(config);
    this.config = config;
    addConnectionListener(new AbstractConnectionListener() {
        @Override
        public void connectionClosedOnError(Exception e) {
            if (e instanceof XMPPException.StreamErrorException) {
                dropSmState();
            }
        }
    });
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Creates a new XMPP connection over TCP (optionally using proxies).
 * <p>
 * Note that XMPPTCPConnection constructors do not establish a connection to the server
 * and you must call {@link #connect()}.
 * </p>
 *
 * @param config the connection configuration.
 */
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
    super(config);
    this.config = config;
    addConnectionListener(new AbstractConnectionListener() {
        @Override
        public void connectionClosedOnError(Exception e) {
            if (e instanceof XMPPException.StreamErrorException || e instanceof StreamManagementException) {
                dropSmState();
            }
        }
    });
}
项目:Smack    文件:XMPPBOSHConnection.java   
/**
 * Parse the received packets and notify the corresponding connection.
 *
 * @param event the BOSH client response which includes the received packet.
 */
public void responseReceived(BOSHMessageEvent event) {
    AbstractBody body = event.getBody();
    if (body != null) {
        try {
            if (sessionID == null) {
                sessionID = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "sid"));
            }
            if (streamId == null) {
                streamId = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
            }
            final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            parser.setInput(new StringReader(body.toXML()));
            int eventType = parser.getEventType();
            do {
                eventType = parser.next();
                switch (eventType) {
                case XmlPullParser.START_TAG:
                    String name = parser.getName();
                    switch (name) {
                    case Message.ELEMENT:
                    case IQ.IQ_ELEMENT:
                    case Presence.ELEMENT:
                        parseAndProcessStanza(parser);
                        break;
                    case "challenge":
                        // The server is challenging the SASL authentication
                        // made by the client
                        final String challengeData = parser.nextText();
                        getSASLAuthentication().challengeReceived(challengeData);
                        break;
                    case "success":
                        send(ComposableBody.builder().setNamespaceDefinition("xmpp",
                                        XMPPBOSHConnection.XMPP_BOSH_NS).setAttribute(
                                        BodyQName.createWithPrefix(XMPPBOSHConnection.XMPP_BOSH_NS, "restart",
                                                        "xmpp"), "true").setAttribute(
                                        BodyQName.create(XMPPBOSHConnection.BOSH_URI, "to"), getServiceName()).build());
                        Success success = new Success(parser.nextText());
                        getSASLAuthentication().authenticated(success);
                        break;
                    case "features":
                        parseFeatures(parser);
                        break;
                    case "failure":
                        if ("urn:ietf:params:xml:ns:xmpp-sasl".equals(parser.getNamespace(null))) {
                            final SASLFailure failure = PacketParserUtils.parseSASLFailure(parser);
                            getSASLAuthentication().authenticationFailed(failure);
                        }
                        break;
                    case "error":
                        throw new StreamErrorException(PacketParserUtils.parseStreamError(parser));
                    }
                    break;
                }
            }
            while (eventType != XmlPullParser.END_DOCUMENT);
        }
        catch (Exception e) {
            if (isConnected()) {
                notifyConnectionError(e);
            }
        }
    }
}