BOSH conn.login() giving null pointer exception

Hi,

I am using smack 4.20 libraries with ejabberd 17.04.

The ejabberd server http-bind is enabled and works fine with converse.js.

But when i try to login using smack, it gives the below error:

Jun 02, 2017 9:40:24 PM org.igniterealtime.jbosh.BOSHClient init

INFO: Starting with 1 request processors

21:40:25 RECV (0):

Jun 02, 2017 9:40:25 PM org.jivesoftware.smack.SASLAuthentication selectMechanism

WARNING: Server did not report any SASL mechanisms

Exception in thread “main” java.lang.NullPointerException

at java.util.Collections$UnmodifiableCollection.(Collections.java:1051)

at java.util.Collections$UnmodifiableSet.(Collections.java:1122)

at java.util.Collections.unmodifiableSet(Collections.java:1112)

at org.jivesoftware.smack.ConnectionConfiguration.getEnabledSaslMechanisms(Connect ionConfiguration.java:476)

at org.jivesoftware.smack.SASLAuthentication.selectMechanism(SASLAuthentication.ja va:359)

at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 191)

at org.jivesoftware.smack.bosh.XMPPBOSHConnection.loginInternal(XMPPBOSHConnection .java:223)

at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :491)

at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :465)

at com.huawei.universalcrm.server.service.JabberSmackAPI.main(JabberSmackAPI.java: 128)

21:40:25 RECV (0): stream:featuresPLAINDIGEST-MD5X-OAUTH2SCRAM-SHA-1</me chanism>ANONYMOUS</stream:features>

Jun 02, 2017 9:40:55 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener

WARNING: Connection XMPPBOSHConnection[not-authenticated] (0) closed with error

java.lang.NullPointerException

at org.jivesoftware.smack.packet.XMPPError$Type.fromString(XMPPError.java:369)

at org.jivesoftware.smack.util.PacketParserUtils.parseError(PacketParserUtils.java :857)

at org.jivesoftware.smack.bosh.XMPPBOSHConnection$BOSHPacketReader.responseReceive d(XMPPBOSHConnection.java:537)

at org.igniterealtime.jbosh.BOSHClient.fireResponseReceived(BOSHClient.java:1601)

at org.igniterealtime.jbosh.BOSHClient.processExchange(BOSHClient.java:1136)

at org.igniterealtime.jbosh.BOSHClient.processMessages(BOSHClient.java:990)

at org.igniterealtime.jbosh.BOSHClient.access$300(BOSHClient.java:100)

at org.igniterealtime.jbosh.BOSHClient$RequestProcessor.run(BOSHClient.java:1719)

at java.lang.Thread.run(Thread.java:745)

Jun 02, 2017 9:40:55 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener

WARNING: Connection XMPPBOSHConnection[not-authenticated] (0) closed with error

org.igniterealtime.jbosh.BOSHException: Terminal binding condition encountered: remote-stream-error (Encapsulated transport protocol error.)

at org.igniterealtime.jbosh.BOSHClient.checkForTerminalBindingConditions(BOSHClien t.java:1385)

at org.igniterealtime.jbosh.BOSHClient.processExchange(BOSHClient.java:1161)

at org.igniterealtime.jbosh.BOSHClient.processMessages(BOSHClient.java:990)

at org.igniterealtime.jbosh.BOSHClient.access$300(BOSHClient.java:100)

at org.igniterealtime.jbosh.BOSHClient$RequestProcessor.run(BOSHClient.java:1719)

at java.lang.Thread.run(Thread.java:745)

The following is the code which i have written for the same:

BOSHConfiguration config = BOSHConfiguration.builder().setHost(“10.18.246.229”).setXmppDomain(“huaweicrm”)

.setPort(Integer.parseInt(“5280”)).setFile("/http-bind/").setSecurityMode(Connec tionConfiguration.SecurityMode.disabled)

.setDebuggerEnabled(true).build();

AbstractXMPPConnection con = new XMPPBOSHConnection(config);

con.connect();

con.login(“admin”, “admin”);

Please let me know what am i doing wrong.

Thanks!

try to login using below code

private String ChatServer = “domainname”;

XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();

builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

builder.setUsernameAndPassword(“user1@” + ChatServer, “000”);

builder.setServiceName(ChatServer);

builder.setHost(ChatServer);

builder.setDebuggerEnabled(true);

//this is also error

//SASLPlainMechanism saslPlainMechanism = new SASLPlainMechanism();

//SASLAuthentication.registerSASLMechanism(saslPlainMechanism);

AbstractXMPPConnection connection = new XMPPTCPConnection(builder.build());

//saslPlainMechanism.instanceForAuthentication(connection);

connection.connect();

connection.login();

hope this will help you