Search in sources :

Example 1 with XMPPError

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

the class XMPPErrorTest method testCancelWithMessage.

/**
     * Check the parser with an xml with the 404 error.
    */
public void testCancelWithMessage() {
    // Make the XML to test
    String xml = "<error type='cancel'>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='langcode'>" + "Some special application diagnostic information!" + "</text>" + "</error>";
    try {
        // Create the xml parser
        XmlPullParser parser = getParserFromXML(xml);
        // Create a packet from the xml
        XMPPError error = parseError(parser);
        assertNotNull(error);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XMPPError(org.jivesoftware.smack.packet.XMPPError) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 2 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project camel by apache.

the class XmppEndpoint method resolveRoom.

/*
     * If there is no "@" symbol in the room, find the chat service JID and
     * return fully qualified JID for the room as room@conference.server.domain
     */
public String resolveRoom(XMPPConnection connection) throws XMPPException, SmackException {
    ObjectHelper.notEmpty(room, "room");
    if (room.indexOf('@', 0) != -1) {
        return room;
    }
    Iterator<String> iterator = MultiUserChat.getServiceNames(connection).iterator();
    if (!iterator.hasNext()) {
        throw new XMPPErrorException("Cannot find Multi User Chat service", new XMPPError(new XMPPError.Condition("Cannot find Multi User Chat service on connection: " + getConnectionMessage(connection))));
    }
    String chatServer = iterator.next();
    LOG.debug("Detected chat server: {}", chatServer);
    return room + "@" + chatServer;
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 3 with XMPPError

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

the class AdHocCommandDataProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    boolean done = false;
    AdHocCommandData adHocCommandData = new AdHocCommandData();
    DataFormProvider dataFormProvider = new DataFormProvider();
    int eventType;
    String elementName;
    String namespace;
    adHocCommandData.setSessionID(parser.getAttributeValue("", "sessionid"));
    adHocCommandData.setNode(parser.getAttributeValue("", "node"));
    // Status
    String status = parser.getAttributeValue("", "status");
    if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.executing);
    } else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.completed);
    } else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.canceled);
    }
    // Action
    String action = parser.getAttributeValue("", "action");
    if (action != null) {
        Action realAction = AdHocCommand.Action.valueOf(action);
        if (realAction == null || realAction.equals(Action.unknown)) {
            adHocCommandData.setAction(Action.unknown);
        } else {
            adHocCommandData.setAction(realAction);
        }
    }
    while (!done) {
        eventType = parser.next();
        elementName = parser.getName();
        namespace = parser.getNamespace();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("actions")) {
                String execute = parser.getAttributeValue("", "execute");
                if (execute != null) {
                    adHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(execute));
                }
            } else if (parser.getName().equals("next")) {
                adHocCommandData.addAction(AdHocCommand.Action.next);
            } else if (parser.getName().equals("complete")) {
                adHocCommandData.addAction(AdHocCommand.Action.complete);
            } else if (parser.getName().equals("prev")) {
                adHocCommandData.addAction(AdHocCommand.Action.prev);
            } else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
                adHocCommandData.setForm((DataForm) dataFormProvider.parseExtension(parser));
            } else if (parser.getName().equals("note")) {
                AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(parser.getAttributeValue("", "type"));
                String value = parser.nextText();
                adHocCommandData.addNote(new AdHocCommandNote(type, value));
            } else if (parser.getName().equals("error")) {
                XMPPError error = PacketParserUtils.parseError(parser);
                adHocCommandData.setError(error);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("command")) {
                done = true;
            }
        }
    }
    return adHocCommandData;
}
Also used : Action(org.jivesoftware.smackx.commands.AdHocCommand.Action) AdHocCommandNote(org.jivesoftware.smackx.commands.AdHocCommandNote) AdHocCommandData(org.jivesoftware.smackx.packet.AdHocCommandData) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 4 with XMPPError

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

the class FileTransferNegotiator method getNegotiator.

private StreamNegotiator getNegotiator(final FormField field) throws XMPPException {
    String variable;
    boolean isByteStream = false;
    boolean isIBB = false;
    for (Iterator<FormField.Option> it = field.getOptions(); it.hasNext(); ) {
        variable = it.next().getValue();
        if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
            isByteStream = true;
        } else if (variable.equals(InBandBytestreamManager.NAMESPACE)) {
            isIBB = true;
        }
    }
    if (!isByteStream && !isIBB) {
        XMPPError error = new XMPPError(XMPPError.Condition.bad_request, "No acceptable transfer mechanism");
        throw new XMPPException(error.getMessage(), error);
    }
    // if (isByteStream && isIBB && field.getType().equals(FormField.TYPE_LIST_MULTI)) {
    if (isByteStream && isIBB) {
        return new FaultTolerantNegotiator(connection, byteStreamTransferManager, inbandTransferManager);
    } else if (isByteStream) {
        return byteStreamTransferManager;
    } else {
        return inbandTransferManager;
    }
}
Also used : XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException)

Example 5 with XMPPError

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

the class Socks5BytestreamManager method replyRejectPacket.

/**
 * Responses to the given packet's sender with a XMPP error that a SOCKS5 Bytestream is not
 * accepted.
 *
 * @param packet Packet that should be answered with a not-acceptable error
 */
protected void replyRejectPacket(IQ packet) {
    XMPPError xmppError = new XMPPError(XMPPError.Condition.no_acceptable);
    IQ errorIQ = IQ.createErrorResponse(packet, xmppError);
    this.connection.sendPacket(errorIQ);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Aggregations

XMPPError (org.jivesoftware.smack.packet.XMPPError)36 XMPPException (org.jivesoftware.smack.XMPPException)11 IQ (org.jivesoftware.smack.packet.IQ)10 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 SmackException (org.jivesoftware.smack.SmackException)5 XmlPullParser (org.xmlpull.v1.XmlPullParser)5 AdHocCommandData (org.jivesoftware.smackx.packet.AdHocCommandData)3 NetworkException (com.xabber.android.data.NetworkException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Form (org.jivesoftware.smackx.Form)2 Action (org.jivesoftware.smackx.commands.AdHocCommand.Action)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 AccountItem (com.xabber.android.data.account.AccountItem)1 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)1 UserJid (com.xabber.android.data.entity.UserJid)1 Realm (io.realm.Realm)1 BufferedImage (java.awt.image.BufferedImage)1