Hi, I’m trying to do a very basic Mam Query to get messages for a User JID. This is straight out of the box smack4.3.4 and OpenFire 4.5.3. (Although the issues exists with as far back as OpenFire 4.2.3)
results in:
2020-08-26 14:48:22.958 [ErrorListener()] ERROR ChatInstantMessaging - Open fire connection closed on error.
java.lang.ClassCastException: org.jivesoftware.smack.packet.StandardExtensionElement cannot be cast to org.jivesoftware.smackx.mam.element.MamElements$MamResultExtension
at org.jivesoftware.smackx.mam.element.MamElements$MamResultExtension.from(MamElements.java:144) ~[?:?]
at org.jivesoftware.smackx.mam.filter.MamResultFilter.acceptSpecific(MamResultFilter.java:44) ~[?:?]
at org.jivesoftware.smackx.mam.filter.MamResultFilter.acceptSpecific(MamResultFilter.java:33) ~[?:?]
at org.jivesoftware.smack.filter.FlexibleStanzaTypeFilter.accept(FlexibleStanzaTypeFilter.java:47) ~[?:?]
at org.jivesoftware.smack.StanzaCollector.processStanza(StanzaCollector.java:311) ~[?:?]
at org.jivesoftware.smack.AbstractXMPPConnection.invokeStanzaCollectorsAndNotifyRecvListeners(AbstractXMPPConnection.java:1251) ~[?:?]
at org.jivesoftware.smack.AbstractXMPPConnection.processStanza(AbstractXMPPConnection.java:1119) ~[?:?]
at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:1097) ~[?:?]
at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1300(XMPPTCPConnection.java:155) ~[?:?]
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1144) ~[?:?]
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$1000(XMPPTCPConnection.java:1092) ~[?:?]
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1112) ~[?:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
It appears that there is no Smack ExtensionElement provider for {urn:xmpp:mam:1}result installed. Could you check with the ProviderManager if this is the case?
I don’t see a MamResultProvider in my list of providers in ProviderManager.getExtensionProviders()
should I add something like this:
ProviderManager.addExtensionProvider( MamResultExtension.ELEMENT, “urn:xmpp:mam:1”, new MamResultProvider() );
ProviderManager.addIQProvider( MamFinIQ.ELEMENT, MamFinIQ.NAMESPACE, new MamFinIQProvider() );
Also I read that this should not be necessary as smack should add all necessary providers by default. This doesn’t seem to be well documented. the MamManager docs do not suggest anything like this is necessary. Thanks again for the help!
Since you marked this as “Solution” I am argued to stress that this is not the solution but merely a workaround. If you need to explicitly register Smack built-in providers, then something went wrong during Smack’s initialization phase and you will very probably run into further similar issues.
I agree! It’s a Workaround. This issue appeared after upgrading our Smack libs from 4.2 to 4.3. I thought is was initially an issue or incompatibility with openfire. All we did was add the new jars to our project for 4.3.
What Paul said. Dropping jar files in your project feels antiquated. And, what’s worse, can easily lead to you missing dependencies causing all sorts of issues.