powered by Jive Software

Socket closed

ConnectionConfiguration config = new ConnectionConfiguration("127.0.0.1",5222);
                    
                    config.setCompressionEnabled(true);
                    
                    XMPPConnection connection = new XMPPTCPConnection(config);
                    
                    connection.connect();

When it is running “connection.connect();”, it throws some exceptions.

: Exception writing closing stream element
java.net.SocketException: Socket closed
          at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:121)
          at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
          at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
          at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
          at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
          at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
          at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
          at java.io.BufferedWriter.flush(BufferedWriter.java:254)
          at org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)
          at org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)
          at org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)
六月 12, 2014 4:11:52 下午 org.jivesoftware.smack.XMPPConnection callConnectionClosedOnErrorListener
警告: Connection closed with error
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
          at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
          at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
          at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
          at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
          at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
          at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
          at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
          at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:652)
          at org.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)
          at org.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)
          at org.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
          at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
          at sun.security.validator.Validator.validate(Validator.java:260)
          at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
          at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
          at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
          at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
          ... 11 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
          at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
          at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
          ... 17 more
六月 12, 2014 4:11:52 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [spring] in context with path [/s] threw exception
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
          at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
          at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
          at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
          at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
          at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
          at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
          at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
          at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
          at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:652)
          at org.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:223)
          at org.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:48)
          at org.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:82)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
          at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
          at sun.security.validator.Validator.validate(Validator.java:260)
          at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
          at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
          at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
          at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
          ... 11 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
          at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
          at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
          at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
          ... 17 more

Why the Socket closed? What should I do?

See https://community.igniterealtime.org/message/239649#239649

if you set :

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

probem will be solved

And you will use unencrypted connections.