powered by Jive Software

Smack 4.2.1 exception while login

Hello,

I try to make jabber bot using smack 4.2.1, connection is established, but on login there is

Here’s my code:

Наpackage ru.mir.xammpOpenVpnSwitcher;

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

import java.io.IOException;
import java.net.InetAddress;

import static org.jivesoftware.smack.ConnectionConfiguration.SecurityMode.disabled;

public class Connector {

    private static Connector instance;

    private Connector() {

    }

    public static synchronized Connector getConnectorInstance() {

        if (instance == null) {
            instance = new Connector();
            return instance;

        }else return instance;
    }

    public void connect() throws IOException, InterruptedException, XMPPException, SmackException {

        // Create a connection to the jabber.org server on a specific port.
        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword("vladimirovaav", "1")
                .setXmppDomain("192.168.3.18")
                .setResource("willbrake")
                .setHostAddress(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, 3, 18}))
                .setPort(5222)
                .setDebuggerEnabled(true)
                .setConnectTimeout(1000)
                .setSecurityMode(disabled)
                .build();

        AbstractXMPPConnection connection = new XMPPTCPConnection(config);

        InetAddress address = InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, 3, 18});
        boolean reachable = address.isReachable(10000);

        System.out.println("Is host reachable?: " + reachable);

        System.out.println("Connecting...");
        connection.setReplyTimeout(100000);
        connection.connect();

        boolean conn = connection.isConnected();
        System.out.println("Is connected?: " +conn + " to "
                + connection.getXMPPServiceDomain());

        if (conn) {
            try {
                connection.login();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }

        Chutter.getChutterInstance(connection).beginChat();

        connection.disconnect();
    }
}

Here is output:

/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -javaagent:/opt/idea-IU-171.3780.107/lib/idea_rt.jar=33157:/opt/idea-IU-171.3780.107/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/icedtea-sound.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/management-agent.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/rt.jar:/home/obrien83/Projects/xamppTest/target/classes:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-java7/4.2.1/smack-java7-4.2.1.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-core/4.2.1/smack-core-4.2.1.jar:/home/obrien83/.m2/repository/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar:/home/obrien83/.m2/repository/org/jxmpp/jxmpp-core/0.5.0/jxmpp-core-0.5.0.jar:/home/obrien83/.m2/repository/org/jxmpp/jxmpp-util-cache/0.5.0/jxmpp-util-cache-0.5.0.jar:/home/obrien83/.m2/repository/org/jxmpp/jxmpp-jid/0.5.0/jxmpp-jid-0.5.0.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-resolver-javax/4.2.1/smack-resolver-javax-4.2.1.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-sasl-javax/4.2.1/smack-sasl-javax-4.2.1.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-tcp/4.2.1/smack-tcp-4.2.1.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-im/4.2.1/smack-im-4.2.1.jar:/home/obrien83/.m2/repository/org/igniterealtime/smack/smack-extensions/4.2.1/smack-extensions-4.2.1.jar ru.mir.xammpOpenVpnSwitcher.Main
Starting session...
Is server mode? : false
Is host reachable?: true
Connecting...
12:10:44 SENT (0): <stream:stream xmlns='jabber:client' to='192.168.3.18' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='vladimirovaav@192.168.3.18' xml:lang='en'>
12:10:44 RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="willbrake" id="a4xczdkiav" xml:lang="en" version="1.0">
12:10:44 RECV (0): <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>SCRAM-SHA-1</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
Is connected?: true to 192.168.3.18
12:10:44 SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='SCRAM-SHA-1'>biwsbj12bGFkaW1pcm92YWF2LHI9Nzk1WCNkL0dtOTlsanxPRG56PGdDa2F4MjdAYyp5RCk=</auth>
12:10:44 RECV (0): <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cj03OTVYI2QvR205OWxqfE9Ebno8Z0NrYXgyN0BjKnlEKTAzODE1ZjRlLTdhM2UtNDdlMS05NGYxLTdjNjM3YTZhZGY4ZCxzPWlJOVcrRFFmNHVrRXdHMU9XYXF5Ri94NVc4RXlYaWlwLGk9NDA5Ng==</challenge>
Exception in thread "Smack Packet Reader (0)" java.lang.ExceptionInInitializerError
	at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
	at java.nio.file.Paths.get(Paths.java:84)
	at javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:274)
	at javax.crypto.JceSecurity.access$000(JceSecurity.java:50)
	at javax.crypto.JceSecurity$1.run(JceSecurity.java:85)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.crypto.JceSecurity.<clinit>(JceSecurity.java:82)
	at javax.crypto.Mac.getInstance(Mac.java:176)
	at org.jivesoftware.smack.util.MAC.<clinit>(MAC.java:33)
	at org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism$1.hmac(SCRAMSHA1Mechanism.java:36)
	at org.jivesoftware.smack.sasl.core.ScramMechanism.hmac(ScramMechanism.java:367)
	at org.jivesoftware.smack.sasl.core.ScramMechanism.hi(ScramMechanism.java:397)
	at org.jivesoftware.smack.sasl.core.ScramMechanism.evaluateChallenge(ScramMechanism.java:182)
	at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:245)
	at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:253)
	at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:237)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1091)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:982)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:998)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)
	at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:52)
	at sun.nio.fs.LinuxFileSystem.<init>(LinuxFileSystem.java:39)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:46)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:39)
	at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:56)
	at sun.nio.fs.LinuxFileSystemProvider.<init>(LinuxFileSystemProvider.java:41)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at sun.nio.fs.DefaultFileSystemProvider.createProvider(DefaultFileSystemProvider.java:48)
	at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:63)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
	at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
	at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
	... 20 more
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 100000ms (~100s). While waiting for successful SASL authentication
	at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:93)
	at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:224)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:386)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:493)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:450)
	at ru.mir.xammpOpenVpnSwitcher.Connector.connect(Connector.java:60)
	at ru.mir.xammpOpenVpnSwitcher.Main.main(Main.java:32)

Process finished with exit code 1

There is an NPE here triggered when the class initialization for java.nio.file.FileSystems$DefaultFileSystemHolder runs. I’d use a debugger to get an better idea about what is going wrong.

Yes, it was in another class when read config proprieties. Thanks a lot !