Smack Mam.queryArchive with mamQueryArgs error

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)

smack 4.3.4
Sample Code:
MamQuery mamQuery = null;
MamManager mam = MamManager.getInstanceFor( connection );
mamQueryArgs = MamQueryArgs.builder().limitResultsToJid( JidCreate.from( withUserJID ) ).setResultPageSizeTo( 10 ).queryLastPage().build();
mamQuery = mam.queryArchive( mamQueryArgs );

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]

Could you verify that your version of Smack and Openfire support the same version of MAM?
Also, sharing a stanza log would be appreciated.

Thanks Paul

My instance of MamManager returns true for support:

isSupported = mam.isSupported();
log.info( "mam is supported = " + isSupported );

2020-08-26 14:48:22.848 [ main] INFO IQHelper - mam is supported = true

Stanzas:
IQ Sent:

<iq xmlns="jabber:client" id="5eLZ3-323" type="set">
  <query xmlns="urn:xmpp:mam:1" queryid="c7f9452d-3cff-4f6c-8357-41518f730e15">
    <x xmlns="jabber:x:data" type="submit">
      <field var="FORM_TYPE" type="hidden">
        <value>urn:xmpp:mam:1</value>
      </field>
      <field var="with">
        <value>myuser1@domain</value>
      </field>
    </x>
    <set xmlns="http://jabber.org/protocol/rsm">
      <before/>
      <max>10</max>
    </set>
  </query>
</iq>

Message Received:

<message xmlns="jabber:client" to="myuser2@domain/Server">
  <result xmlns="urn:xmpp:mam:1" xmlns:stream="http://etherx.jabber.org/streams" queryid="c7f9452d-3cff-4f6c-8357-41518f730e15" id="53">
    <forwarded xmlns="urn:xmpp:forward:0" xmlns:stream="http://etherx.jabber.org/streams">
      <delay xmlns="urn:xmpp:delay" xmlns:stream="http://etherx.jabber.org/streams" stamp="2020-08-26T14:46:22.930Z"/>
      <message xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" to="myuser2@domain" id="MuOV3-2595" type="chat" from="myuser@domain/244">
        <thread xmlns:stream="http://etherx.jabber.org/streams">9Orvs8</thread>
        <body xmlns:stream="http://etherx.jabber.org/streams">asdf</body>
      </message>
    </forwarded>
  </result>
</message>

On receive of this message the error above is logged and smack client closes the connection.

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!

That is correct. Something in your setup prevents this from happening.

Tell us a little bit how you included Smack in your project. Anything unusual?

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.

Are you not using a build system like gradle or maven?
Maybe you are missing some dependency, which would otherwise be loaded automatically.

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.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.