问题描述
我正在尝试从应用服务器(TOMCAT)创建多用户聊天组,我在 servlet 中创建了一个 XMPP 机器人.
I am trying to create Multi user chat group from App Server(TOMCAT),I have created a XMPP bot in a servlet.
根据我的要求,我必须从应用服务器创建一个多用户聊天组(在应用服务器上使用 xmpp 机器人),并从安卓应用加入用户.
As per my requirement i have to create a Multiuser Chat group from App server(using xmpp bot on app server),and join user from android app.
创建多用户聊天组并从 Android 加入用户(使用 aSmack)工作正常,当我尝试在 appServer(TOMCAT)上做同样的事情时,我收到错误,
Creation of Multi user chat group and joining user from Android(using aSmack)works just fine,when i try to do same thing on appServer(TOMCAT),i am getting error,
起初,当我尝试创建 MUC 时,我收到无法使用 Android 的 aSmack 库创建多用户聊天 (MUC) 房间:packet.DefaultPacketExtension 无法转换为 packet.MUCUser",
At first when I try to create MUC i was getting "Can't create a multi user chat (MUC) room with aSmack library for Android: "packet.DefaultPacketExtension cannot be cast to packet.MUCUser",
当我搜索 SO 我发现 POST 其中@FLOW 提到了这个错误的原因,即
When i searched on SO i found POST in which @FLOW has mention reson for this error which is
org.jivesoftware.smack.packet.DefaultPacketExtension 不能转换为org.jivesoftware.smackx.packet.MUCUser 通常是一个指标你没有初始化负责处理的 aSmack 的静态代码为各种数据包(和数据包)注册 Smack 提供者扩展)类 Smack.对于大多数 aSmack 版本,只需调用
SmackAndroid.init(Context ctx)
SmackAndroid.init(Context ctx)
会解决问题.
核心 Smack 包中没有这样的方法来负责为 Smack 的各种数据包(和数据包扩展)类注册 Smack 提供程序.
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.
所以我在这个 link
现在配置提供程序后一切正常,但我仍然无法创建 MUC 组
Now after configuring provider everything should be working fine but still i am unable to create MUC group
我的代码如下
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, "[email protected]");
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)
对上述问题的任何帮助都会非常有帮助
Any help with above problem will be really helpful
提前致谢!!!
推荐答案
是的(虽然不在 smack-core 中).
Yes there is (although not in smack-core).
所以我使用 configure(ProviderManagerpm) 这个链接上的方法
从不手动配置提供程序(至少不会,如果您不知道自己在做什么).
Never manually configure the provider (at least not, if you are don't know what you are doing).
线程Smack Packet Reader (0)"中的异常java.lang.NoSuchMethodError:org.jivesoftware.smack.util.StringUtils.parseDate(Ljava/lang/String;)Ljava/util/Date;在 org.jivesoftware.smackx.provider.DelayInformationProvider.parseExtension(DelayInformationProvider.java:45)
您看到了 NoSuchmethodError
.出于某种原因,StringUtils 中的 parseDate
方法不存在,除了 DelayInformationProvider
.会不会是你混合了不同主要版本的 Smack 组件?您使用哪个 Smack 版本?
You are seeing a NoSuchmethodError
. For some reason, the parseDate
method in StringUtils does not exists as excepted by DelayInformationProvider
. Could it be that you are mixing Smack components of different major versions? Which Smack version do you use?
这篇关于Smack 在线程“Smack Packet Reader (0)"中抛出“异常"java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!