powered by Jive Software

Smack is unable to connect Openfire Server

I am trying to connect with OpenFire server using smack. Here is my code

public static void main(String[] args) throws SmackException, IOException, XMPPException, InterruptedException {
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
        .setUsernameAndPassword("admin", "admin").setXmppDomain("XYZ")
        .setHost("localhost").build();

    AbstractXMPPConnection connection = new XMPPTCPConnection(config);
    connection.connect(); // Establishes a connection to the server
    connection.login(); // Logs in

  }

pom.xml

<dependency>
    <groupId>org.igniterealtime.smack</groupId>
    <artifactId>smack-extensions</artifactId>
    <version>4.3.5</version>
</dependency>
<dependency>
    <groupId>org.igniterealtime.smack</groupId>
    <artifactId>smack-core</artifactId>
    <version>4.3.5</version>
</dependency>
<dependency>
    <groupId>org.igniterealtime.smack</groupId>
    <artifactId>smack-tcp</artifactId>
    <version>4.3.5</version>
</dependency>
<dependency>
    <groupId>org.igniterealtime.smack</groupId>
    <artifactId>smack-im</artifactId>
    <version>4.3.5</version>
</dependency> 

I am getting following error

Exception in thread "main" java.lang.NullPointerException
	at org.jivesoftware.smack.util.stringencoder.Base64.encode(Base64.java:64)
	at org.jivesoftware.smack.util.stringencoder.Base64.encode(Base64.java:60)
	at org.jivesoftware.smack.util.stringencoder.Base64.encodeToString(Base64.java:42)
	at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(EntityCapsManager.java:763)
	at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(EntityCapsManager.java:630)
	at org.jivesoftware.smackx.caps.EntityCapsManager.updateLocalEntityCaps(EntityCapsManager.java:526)
	at org.jivesoftware.smackx.caps.EntityCapsManager.<init>(EntityCapsManager.java:347)
	at org.jivesoftware.smackx.caps.EntityCapsManager.getInstanceFor(EntityCapsManager.java:419)
	at org.jivesoftware.smackx.caps.EntityCapsManager$1.connectionCreated(EntityCapsManager.java:123)
	at org.jivesoftware.smack.AbstractXMPPConnection.<init>(AbstractXMPPConnection.java:363)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.<init>(XMPPTCPConnection.java:324)

You are missing a dependency on smack-java7.

1 Like