我正在尝试从App Server(TOMCAT)创建多用户聊天组,我在servlet中创建了一个XMPP bot。
根据我的要求,我必须从App服务器创建一个多用户聊天组(在app服务器上使用xmpp bot),并从android app加入用户。
创建多用户聊天组并从Android加入用户(使用aSmack)工作正常,当我尝试在appServer(TOMCAT)上做同样的事情时,我收到错误,
首先,当我尝试创建MUC时,我得到“无法创建一个带有Android的思科库的多用户聊天(MUC)房间:”packet.DefaultPacketExtension无法转换为packet.MUCUser“,
当我搜索SO时,我找到了POST,其中@FLOW提到了这个错误的共鸣
org.jivesoftware.smack.packet.DefaultPacketExtension无法转换为 org.jivesoftware.smackx.packet.MUCUser通常是一个指标 你没有初始化aSmack的静态代码 为各种数据包(和数据包)注册Smack提供程序 扩展)Smack类。 对于大多数aSmack版本,只需调用
即可SmackAndroid.init(Context ctx)
会做到这一点。
在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());
}
}
}
);
这里是Stack Trace ::
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)
对上述问题的任何帮助都会非常有用
提前致谢!!!
答案 0 :(得分:1)
在核心Smack包中没有这样的方法来处理 为各种数据包(和数据包)注册Smack提供程序 扩展)Smack的类。
是的(虽然没有在smack-core中)。
所以我手动配置使用configure(ProviderManager) pm)此链接上的方法
从不手动配置提供商(至少不是,如果您不知道自己在做什么)。
线程中的异常“Smack Packet Reader(0)” java.lang.NoSuchMethodError: org.jivesoftware.smack.util.StringUtils.parseDate(Ljava /郎/字符串;)Ljava / util的/日期; 在org.jivesoftware.smackx.provider.DelayInformationProvider.parseExtension(DelayInformationProvider.java:45)
您看到的是NoSuchmethodError
。出于某种原因,StringUtils中的parseDate
方法不存在DelayInformationProvider
除外。难道你是在混合不同主要版本的Smack组件吗?您使用哪个Smack版本?