smack登录openfire服务器失败

J2EE 码拜 9年前 (2015-11-12) 2857次浏览
哪位高手遇到过这个问题,请教育~

Builder builder = XMPPTCPConnectionConfiguration.builder();
		builder.setServiceName("testserver");
		builder.setUsernameAndPassword("sss", "111111");
		builder.setCompressionEnabled(false);
		builder.setResource("web");
		builder.setSecurityMode(SecurityMode.disabled);//不支持TLS验证
		builder.setSendPresence(true);// 登录后,不要自动发送出席消息(等初始化其他数据后,再发)
		builder.setDebuggerEnabled(true);
		SmackConfiguration.DEBUG = true;

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

		try {
			connection.connect();
			connection.login();
             }
...........

错误信息:

07:40:02 下午 RECV (0): <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09Im9mc2VydmVyIixub25jZT0iOXBnbjFHbmxoek5GM0k0Q282Wi9tOEZaMCs0VGxlb3R4T21OOUlGcSIscW9wPSJhdXRoIixjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==</challenge>
五月 27, 2015 7:40:07 下午 org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
警告: Connection closed with error
java.lang.NullPointerException
	at org.jivesoftware.smack.util.stringencoder.Base64.decode(Base64.java:86)
	at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:229)
	at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:328)
	at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:313)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1040)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
	at java.lang.Thread.run(Thread.java:745)
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.SASLAuthentication.authenticate(SASLAuthentication.java:250)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:365)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:452)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:410)
	at com.star.extInterface.impl.Testt.test(Testt.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
解决方案:20分
本人也遇到这个问题  少个JAVA7 囧。
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-java7</artifactId>
<version>4.1.1</version>
</dependency>
Smack for Java7 (or higher). This is a pseudo-artifact that pulls all the required dependencies to run Smack on Java 7 (or higher) JVMs. Usually you want to add additional dependencies to smack-tcp, smack-extensions and smack-experimental.

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明smack登录openfire服务器失败
喜欢 (0)
[1034331897@qq.com]
分享 (0)