gpt4 book ai didi

java - Smack 抛出 "Exception in thread "Smack 数据包读取器(0 )"java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate"

转载 作者:行者123 更新时间:2023-12-01 12:34:25 28 4
gpt4 key购买 nike

我正在尝试从应用程序服务器(TOMCAT)创建多用户聊天组,我已经在servlet中创建了一个XMPP机器人。

根据我的要求,我必须从应用程序服务器创建一个多用户聊天组(在应用程序服务器上使用 xmpp 机器人),并从 Android 应用程序加入用户。

创建多用户聊天组并从 Android 加入用户(使用 aSmack)工作得很好,当我尝试在 appServer(TOMCAT)上做同样的事情时,我收到错误,

首先,当我尝试创建 MUC 时,我收到“无法使用适用于 Android 的 aSmack 库创建多用户聊天 (MUC) 房间:“packet.DefaultPacketExtension 无法转换为 packet.MUCUser”,

当我搜索 SO 时,我发现 POST 其中 @FLOW 提到了此错误的原因,即

org.jivesoftware.smack.packet.DefaultPacketExtension cannot be cast to org.jivesoftware.smackx.packet.MUCUser is usually an indicator that you didn't initialized the static code of aSmack that takes care of registering the Smack providers for the various packet (and packet extension) classes of Smack. For most aSmack versions, simply calling

SmackAndroid.init(Context ctx)

will do the trick.

核心 Smack 包中没有这样的方法来负责为 Smack 的各种数据包(和数据包扩展)类注册 Smack 提供程序。

所以我在这个link上使用configure(ProviderManager pm)方法手动配置提供

现在,配置提供程序后,一切都应该正常工作,但我仍然无法创建 MUC 组

我的代码如下

    SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);

if(service != null)
config = new ConnectionConfiguration(server, port, service);
else
config = new ConnectionConfiguration(server, port);

config.setSASLAuthenticationEnabled(true);
config.setSecurityMode(SecurityMode.disabled);
config.setDebuggerEnabled(true);
connection = new XMPPConnection(config);
connection.connect();

System.out.println("Connected: " + connection.isConnected());
chatManager = connection.getChatManager();
messageListener = new MyMessageListener();

if (connection!=null && connection.isConnected()) {
configure(ProviderManager.getInstance());
connection.login(username, password);
}
MultiUserChat muc = new MultiUserChat(connection, "1234567@conference.localhost");

muc.create("Jonny");

Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();

for (Iterator<FormField> fields = form.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
// show("field: " + field.getVariable());
// Sets the default value as the answer
submitForm.setDefaultAnswer(field.getVariable());
}
}

List<String> owners = new ArrayList<String>();

owners.add(xmppManager.getXmppConnection().getUser());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
//submitForm.setAnswer("muc#roomconfig_roomname", );
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(submitForm);
muc.join(MucNick);
muc.sendMessage("hello everybody");
muc.addMessageListener(
new PacketListener() {
@Override
public void processPacket(Packet packet) {
message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message
.getFrom());
System.out.println("andro xmpp client"+ "Text Recieved--" + message.getBody()
+ " from " + fromName );
//messages.add(fromName + ":");
//messages.add(message.getBody());
//infobox.append("message arrieved "+" from::"+message.getFrom()+"__"+message.getBody());

// Add the incoming message to the list view
//Log.i("andro xmpp client","group messages__"+ messages.toString());

}
}
}

);

这是堆栈跟踪::

Exception in thread "Smack Packet Reader (0)" java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate(Ljava/lang/String;)Ljava/util/Date;
at org.jivesoftware.smackx.provider.DelayInformationProvider.parseExtension(DelayInformationProvider.java:45)
at org.jivesoftware.smack.util.PacketParserUtils.parsePacketExtension(PacketParserUtils.java:768)
at org.jivesoftware.smack.util.PacketParserUtils.parsePresence(PacketParserUtils.java:248)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:232)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
No response from server.:
at org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:367)
at com.sentiinel.egovern.testcase1.testing2.createMUC(testing2.java:510)
at com.sentiinel.egovern.testcase1.testing2.insertRequest(testing2.java:303)
at com.sentiinel.egovern.testcase1.testing2.doPost(testing2.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.sentiinel.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:115)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

任何有关上述问题的帮助都会非常有帮助

先谢谢了!!!

最佳答案

There is no such method in core Smack package which takes care of registering the Smack providers for the various packet (and packet extension) classes of Smack.

是的,有(尽管不在 smack-core 中)。

So i have manually configure provide using configure(ProviderManager pm) method on this link

永远不要手动配置提供程序(至少不要,如果您不知道自己在做什么的话)。

Exception in thread "Smack Packet Reader (0)" java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate(Ljava/lang/String;)Ljava/util/Date; at org.jivesoftware.smackx.provider.DelayInformationProvider.parseExtension(DelayInformationProvider.java:45)

您看到NoSuchmethodError。由于某种原因,StringUtils 中的 parseDate 方法不存在,DelayInformationProvider 除外。难道你们混合了不同主要版本的 Smack 组件?您使用哪个 Smack 版本?

关于java - Smack 抛出 "Exception in thread "Smack 数据包读取器(0 )"java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25701308/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com