Connection Failure (Oracle Beehive)

Hello everyone,

I am trying to create xmpp connection using below code:

public static void main(String args[]) throws SmackException, IOException, XMPPException, KeyManagementException, NoSuchAlgorithmException {   // Create the configuration for this new connection
  XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
  //configBuilder.setDebuggerEnabled(true);
  configBuilder.setSendPresence(true);
  configBuilder.setUsernameAndPassword("username", "password");
  configBuilder.setResource("Piyushs-MacBook-Pro");
  configBuilder.setServiceName("abc.com");
  //configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
  configBuilder.setHost("stbeehive.abc.com");
  //TLSUtils.acceptAllCertificates(configBuilder);
  configBuilder.setPort(5223);
  AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
  // Connect to the server
  connection.connect();
  // Log into the server
  connection.login();
  connection.disconnect();
  }

However, getting below error:

Exception in thread "main" org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
  at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:106)
  at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:85)
  at org.jivesoftware.smack.SynchronizationPoint.checkForResponse(SynchronizationPoint.java:253)
  at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWait(SynchronizationPoint.java:146)
  at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWaitOrThrow(SynchronizationPoint.java:125)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:854)
  at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:364)
  at JabberSmackAPI.main(JabberSmackAPI.java:56) May 22, 2016 12:54:03 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
org.jivesoftware.smack.SmackException: Parser got END_DOCUMENT event. This could happen e.g. if the server closed the connection without sending a closing stream element
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1170)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:952)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:967)
  at java.lang.Thread.run(Thread.java:745)

Can anybody help me to figure out the cause of error. Thanks in advance.

Fixed the syntax highlighting and font size.

I’m not a developer and don’t know much about Smack. But you are using 5223 port. Is there a reason for that? 5222 is the port which should be used for simple and SSL connections.

Is there any particular reason why you’re using port 5223 and not the more default 5222?

Hey Guus/Wroot,

I am using the same configuration defined in the pidgin which is I am using to connect XMPP and there port is 5223. However, I have tried with 5222 as well and getting below error:

Exception in thread "main" org.jivesoftware.smack.SmackException: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1025)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:952)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:967)
  at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
  at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:765)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java:140)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1018)
  ... 3 more
May 22, 2016 1:42:03 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
  at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:765)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java:140)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1018)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:952)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:967)
  at java.lang.Thread.run(Thread.java:745)

It appears that Oracle Beehive is only supporting XMPP via legacy SSL over port 5233. At least as far as a quick online research yielded.

For Smack 4 this means you have to provide a custom socket factory in the configuration, which does TLS right away.

I tried providing socket factory in following way:

configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
configBuilder.setSocketFactory(SSLSocketFactory.getDefault());

however, now I am getting error as follows:

2016 2:58:46 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
org.jivesoftware.smack.SmackException$SecurityRequiredByClientException: SSL/TLS required by client but not supported by server
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterFeaturesReceived(XMPPTCPConnection.java:913)
  at org.jivesoftware.smack.AbstractXMPPConnection.parseFeatures(AbstractXMPPConnection.java:1376)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$900(XMPPTCPConnection.java:140)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1013)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:952)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:967)
  at java.lang.Thread.run(Thread.java:745) Exception in thread "main" org.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected.
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible(XMPPTCPConnection.java:1248)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate(XMPPTCPConnection.java:345)
  at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:451)
  at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:414)
  at JabberSmackAPI.main(JabberSmackAPI.java:59)

Set the security mode to disabled in the connection configuration.

cool :slight_smile: Working now.

Thanks a lot.

You are welcome.