aSmack connecting to openfire. Cannot connect, openfire error log shows "Unrecognized SSL message, plaintext connection?"

asmack连接开火。无法连接,openfire错误日志显示“无法识别的SSL消息,明文连接吗?”

问题 (Question)

Hi I am trying to connect to an openfire server. Using the following code:

        ConnectionConfiguration config = new ConnectionConfiguration(hostName, 5222);
        XMPPConnection connection = new XMPPConnection(config);

        try {
            connection.connect();
        } catch (XMPPException e) {
            if (e != null){
                Log.d(",myapp", Log.getStackTraceString(e));
            }
        }
        try {
            connection.login(userName, "password");
        } catch (XMPPException e) {
            if (e != null){
                Log.d("XMPPConnection", "Authentication Failure");
            }
        }

It fails on the connection.connect(); and the stack trace is:

06-04 15:23:51.961: D/,myapp(20261): Connection failed. No response from server.: 
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:115)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:655)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:615)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1034)
06-04 15:23:51.961: D/,myapp(20261):    at com.coffeeenterprise.resources.ConnectToXMPPTask.doInBackground(ConnectToXMPPTask.java:30)
06-04 15:23:51.961: D/,myapp(20261):    at com.coffeeenterprise.resources.ConnectToXMPPTask.doInBackground(ConnectToXMPPTask.java:1)
06-04 15:23:51.961: D/,myapp(20261):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-04 15:23:51.961: D/,myapp(20261):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-04 15:23:51.961: D/,myapp(20261):    at java.lang.Thread.run(Thread.java:856)

and on the server side the message is:

at org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:499) 
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299) 
at org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:293) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:228) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485) 
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:679) 
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 
at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:171) 
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:814) 
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:727) 
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) 
at org.apache.mina.filter.support.SSLHandler.unwrap0(SSLHandler.java:658) 
at org.apache.mina.filter.support.SSLHandler.unwrapHandshake(SSLHandler.java:614) 
at org.apache.mina.filter.support.SSLHandler.handshake(SSLHandler.java:493) 
at org.apache.mina.filter.support.SSLHandler.messageReceived(SSLHandler.java:306) 
at org.apache.mina.filter.SSLFilter.messageReceived(SSLFilter.java:392) 
... 14 more 
2013.06.04 14:16:32 org.jivesoftware.openfire.nio.ConnectionHandler - ConnectionHandler reports IOException for session: (SOCKET, R: /184.151.127.182:33096, L: /66.228.58.218:5223, S: 0.0.0.0/0.0.0.0:5223)

I have tried using different settings on the connectionconfiguration such as playing with the security mode. I have also tried giving it a callbackhandler, but that was never called.

Edit: After enabling debug I got this:

06-05 09:22:20.044: D/SMACK(7597): 09:22:20 AM SENT (1106505464): <stream:stream to="coffeemobile.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
06-05 09:22:20.084: D/SMACK(7597): 09:22:20 AM SENT (1106505464): </stream:stream>

我试图连接到openfire服务器。使用下面的代码:

        ConnectionConfiguration config = new ConnectionConfiguration(hostName, 5222);
        XMPPConnection connection = new XMPPConnection(config);

        try {
            connection.connect();
        } catch (XMPPException e) {
            if (e != null){
                Log.d(",myapp", Log.getStackTraceString(e));
            }
        }
        try {
            connection.login(userName, "password");
        } catch (XMPPException e) {
            if (e != null){
                Log.d("XMPPConnection", "Authentication Failure");
            }
        }

它没有连接上。connect();和堆栈跟踪:

06-04 15:23:51.961: D/,myapp(20261): Connection failed. No response from server.: 
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:115)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:655)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:615)
06-04 15:23:51.961: D/,myapp(20261):    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1034)
06-04 15:23:51.961: D/,myapp(20261):    at com.coffeeenterprise.resources.ConnectToXMPPTask.doInBackground(ConnectToXMPPTask.java:30)
06-04 15:23:51.961: D/,myapp(20261):    at com.coffeeenterprise.resources.ConnectToXMPPTask.doInBackground(ConnectToXMPPTask.java:1)
06-04 15:23:51.961: D/,myapp(20261):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-04 15:23:51.961: D/,myapp(20261):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-04 15:23:51.961: D/,myapp(20261):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-04 15:23:51.961: D/,myapp(20261):    at java.lang.Thread.run(Thread.java:856)

在服务器端的消息:

at org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:499) 
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299) 
at org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:293) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:228) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45) 
at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485) 
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:679) 
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 
at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:171) 
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:814) 
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:727) 
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) 
at org.apache.mina.filter.support.SSLHandler.unwrap0(SSLHandler.java:658) 
at org.apache.mina.filter.support.SSLHandler.unwrapHandshake(SSLHandler.java:614) 
at org.apache.mina.filter.support.SSLHandler.handshake(SSLHandler.java:493) 
at org.apache.mina.filter.support.SSLHandler.messageReceived(SSLHandler.java:306) 
at org.apache.mina.filter.SSLFilter.messageReceived(SSLFilter.java:392) 
... 14 more 
2013.06.04 14:16:32 org.jivesoftware.openfire.nio.ConnectionHandler - ConnectionHandler reports IOException for session: (SOCKET, R: /184.151.127.182:33096, L: /66.228.58.218:5223, S: 0.0.0.0/0.0.0.0:5223)

我已经尝试使用不同的设置在connectionconfiguration如玩安全模式。我也试着给它一个callbackhandler,但从来没有被称为。

编辑:启用调试我之后:

06-05 09:22:20.044: D/SMACK(7597): 09:22:20 AM SENT (1106505464): <stream:stream to="coffeemobile.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
06-05 09:22:20.084: D/SMACK(7597): 09:22:20 AM SENT (1106505464): </stream:stream>

最佳答案 (Best Answer)

This problem was solved by removing the port number from the ConnectionConfiguration.

这个问题是由connectionconfiguration删除端口号了。

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/16925957