powered by Jive Software

Strange behaviour of smack using java

Hi everyone,

I have noticed a strange behaviour on openfire server!!

Openfire version - 4.6.1
Smack library - 4.4.0
JDK - adoptToOpenJDK 11

Goal - To create a user, log in and get session-id and store it in my DB.

Approach - I wrote a code(REST API) that creates a user in the XMPP server, then it tries to connect it to the server and then tries to log in! Create user(using username and password) works fine, the problem is with the connect and login, sometimes it just connects fine and create a session and in the next API request it just gives below error!!!

org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). While waiting for establishing TLS [XMPPTCPConnection[not-authenticated] (1)]
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:99)
at org.jivesoftware.smack.AbstractXMPPConnection.waitForConditionOrConnectionException(AbstractXMPPConnection.java:732)
at org.jivesoftware.smack.AbstractXMPPConnection.waitForConditionOrThrowConnectionException(AbstractXMPPConnection.java:737)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:854)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:529)
at com.wowtech.system.MMXMPPConnection.connect(MMXMPPConnection.java:327)
at com.wowtech.system.MMXMPPConnection.start(MMXMPPConnection.java:205)
at com.wowtech.system.MMXMPPConnection.start(MMXMPPConnection.java:161)
at com.wowtech.service.AccountServiceImpl.sendCreateUserApiCall(AccountServiceImpl.java:74)
at com.wowtech.service.AccountServiceImpl.saveAccount(AccountServiceImpl.java:46)
at com.wowtech.controller.RegistrationController.addAccount(RegistrationController.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)

Can any one of you please help me here and explain what could be the issue?

I suspect could be fine, since sometimes it works perfectly fine.

Thanks in advance
Heena Manglani

This is the issue, your connection gets timed out. Set time outs that are reasonable according to your network speed when configuring the connection before call to connect.
See: https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smack/AbstractXMPPConnection.html#setReplyTimeout(long)

Hi thanks for helping, however I tried adding time but no luck!! seems like network related issues!!

you can refer to this one too