Search in sources :

Example 31 with SmackException

use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.

the class JingleContentDescriptionProvider method parse.

/**
     * Parse a iq/jingle/description element.
     *
     * @param parser the input to parse
     * @return a description element
     * @throws IOException 
     * @throws XmlPullParserException 
     * @throws SmackException 
     */
@Override
public JingleContentDescription parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    boolean done = false;
    JingleContentDescription desc = getInstance();
    while (!done) {
        int eventType = parser.next();
        String name = parser.getName();
        if (eventType == XmlPullParser.START_TAG) {
            if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) {
                desc.addJinglePayloadType(parsePayload(parser));
            } else {
                throw new SmackException("Unknow element \"" + name + "\" in content.");
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (name.equals(JingleContentDescription.NODENAME)) {
                done = true;
            }
        }
    }
    return desc;
}
Also used : JingleContentDescription(org.jivesoftware.smackx.jingleold.packet.JingleContentDescription) SmackException(org.jivesoftware.smack.SmackException)

Example 32 with SmackException

use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.

the class JingleDescriptionProvider method parse.

/**
     * Parse a iq/jingle/description element.
     * 
     * @param parser
     *            the input to parse
     * @return a description element
     * @throws SmackException 
     * @throws IOException 
     * @throws XmlPullParserException 
     */
@Override
public JingleDescription parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException, IOException {
    boolean done = false;
    JingleDescription desc = getInstance();
    while (!done) {
        int eventType = parser.next();
        String name = parser.getName();
        if (eventType == XmlPullParser.START_TAG) {
            if (name.equals(PayloadType.NODENAME)) {
                desc.addPayloadType(parsePayload(parser));
            } else {
                throw new SmackException("Unknow element \"" + name + "\" in content.");
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (name.equals(JingleDescription.NODENAME)) {
                done = true;
            }
        }
    }
    return desc;
}
Also used : JingleDescription(org.jivesoftware.smackx.jingleold.packet.JingleDescription) SmackException(org.jivesoftware.smack.SmackException)

Example 33 with SmackException

use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.

the class JingleProvider method parse.

/**
     * Parse a iq/jingle element.
     * @throws Exception 
     */
@Override
public Jingle parse(XmlPullParser parser, int intialDepth) throws Exception {
    Jingle jingle = new Jingle();
    String sid = "";
    JingleActionEnum action;
    Jid initiator = null;
    Jid responder = null;
    boolean done = false;
    JingleContent currentContent = null;
    // Sub-elements providers
    JingleContentProvider jcp = new JingleContentProvider();
    JingleDescriptionProvider jdpAudio = new JingleDescriptionProvider.Audio();
    JingleTransportProvider jtpRawUdp = new JingleTransportProvider.RawUdp();
    JingleTransportProvider jtpIce = new JingleTransportProvider.Ice();
    ExtensionElementProvider<?> jmipAudio = new JingleContentInfoProvider.Audio();
    int eventType;
    String elementName;
    String namespace;
    // Get some attributes for the <jingle> element
    sid = parser.getAttributeValue("", "sid");
    action = JingleActionEnum.getAction(parser.getAttributeValue("", "action"));
    initiator = ParserUtils.getJidAttribute(parser, "initiator");
    responder = ParserUtils.getJidAttribute(parser, "responder");
    jingle.setSid(sid);
    jingle.setAction(action);
    jingle.setInitiator(initiator);
    jingle.setResponder(responder);
    // Start processing sub-elements
    while (!done) {
        eventType = parser.next();
        elementName = parser.getName();
        namespace = parser.getNamespace();
        if (eventType == XmlPullParser.START_TAG) {
            if (elementName.equals(JingleContent.NODENAME)) {
                // Add a new <content> element to the jingle
                currentContent = jcp.parse(parser);
                jingle.addContent(currentContent);
            } else if (elementName.equals(JingleDescription.NODENAME) && namespace.equals(JingleDescription.Audio.NAMESPACE)) {
                // Set the <description> element of the <content>
                currentContent.setDescription(jdpAudio.parse(parser));
            } else if (elementName.equals(JingleTransport.NODENAME)) {
                // Parse the possible transport namespaces
                if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) {
                    currentContent.addJingleTransport(jtpRawUdp.parse(parser));
                } else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) {
                    currentContent.addJingleTransport(jtpIce.parse(parser));
                } else {
                    throw new SmackException("Unknown transport namespace \"" + namespace + "\" in Jingle packet.");
                }
            } else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) {
                jingle.setContentInfo((JingleContentInfo) jmipAudio.parse(parser));
            } else {
                throw new SmackException("Unknown combination of namespace \"" + namespace + "\" and element name \"" + elementName + "\" in Jingle packet.");
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(Jingle.getElementName())) {
                done = true;
            }
        }
    }
    return jingle;
}
Also used : Jid(org.jxmpp.jid.Jid) SmackException(org.jivesoftware.smack.SmackException) JingleActionEnum(org.jivesoftware.smackx.jingleold.JingleActionEnum) Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) JingleContentInfo(org.jivesoftware.smackx.jingleold.packet.JingleContentInfo) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent)

Example 34 with SmackException

use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.

the class TlsTest method tlsTest.

public static boolean tlsTest(EntityBareJid jid, String password, String host, int port, String tlsPin, boolean shouldThrow) throws KeyManagementException, NoSuchAlgorithmException {
    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
    // @formatter:off
    builder.setUsernameAndPassword(jid.getLocalpart(), password).setXmppDomain(JidCreate.domainBareFrom(jid.getDomain())).setHost(host).setPort(port).setSecurityMode(SecurityMode.required);
    // @formatter:on
    builder.setDebuggerEnabled(DEBUG);
    if (StringUtils.isNotEmpty(tlsPin)) {
        SSLContext sslContext = Java7Pinning.forPin(tlsPin);
        builder.setCustomSSLContext(sslContext);
    }
    XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
    connection.setReplyTimeout(20000);
    try {
        connection.connect().login();
        if (shouldThrow) {
            // Test not success, should have throwed on login().
            return false;
        }
    } catch (SecurityRequiredByClientException e) {
        if (!shouldThrow) {
            return false;
        }
    } catch (XMPPException | SmackException | IOException | InterruptedException e) {
        throw new IllegalStateException(e);
    } finally {
        connection.disconnect();
    }
    return true;
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SmackException(org.jivesoftware.smack.SmackException) SecurityRequiredByClientException(org.jivesoftware.smack.SmackException.SecurityRequiredByClientException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 35 with SmackException

use of org.jivesoftware.smack.SmackException in project Smack by igniterealtime.

the class SASLJavaXMechanism method authenticateInternal.

@Override
protected void authenticateInternal(CallbackHandler cbh) throws SmackException {
    String[] mechanisms = { getName() };
    Map<String, String> props = getSaslProps();
    try {
        sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, cbh);
    } catch (SaslException e) {
        throw new SmackException(e);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SaslException(javax.security.sasl.SaslException)

Aggregations

SmackException (org.jivesoftware.smack.SmackException)50 IOException (java.io.IOException)21 XMPPException (org.jivesoftware.smack.XMPPException)17 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Test (org.junit.Test)9 Socket (java.net.Socket)8 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)6 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)5 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)5 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 ConnectException (java.net.ConnectException)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ServerSocket (java.net.ServerSocket)3 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3