powered by Jive Software

ServiceConfigurationError: Xpp3XmlPullParserFactory not a subtype

When trying to run smack 4.4.4 in an OSGi environment, I receive the following exception:

java.util.ServiceConfigurationError: org.jivesoftware.smack.xml.XmlPullParserFactory: org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory not a subtype
        at java.util.ServiceLoader.fail(ServiceLoader.java:589) ~[?:?]
        at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1237) ~[?:?]
        at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265) ~[?:?]
        at java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300) ~[?:?]
        at java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385) ~[?:?]
        at org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory(SmackXmlParser.java:33) ~[?:?]
        at org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser(SmackXmlParser.java:54) ~[?:?]
        at org.jivesoftware.smack.util.PacketParserUtils.getParserFor(PacketParserUtils.java:80) ~[?:?]
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:159) ~[?:?]
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:154) ~[?:?]
        at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:103) ~[?:?]
        at org.jivesoftware.smack.Smack.getVersion(Smack.java:36) ~[?:?]
        at org.jivesoftware.smack.Smack.ensureInitialized(Smack.java:50) ~[?:?]
        at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:115) ~[?:?]
        at org.openhab.binding.xmppclient.internal.XMPPClient.connect(XMPPClient.java:73) ~[?:?]
        at org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler.doConnect(XMPPClientHandler.java:91) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]

I need to add all transitive dependencies manually, so I added the following:

  <properties>
    <smack.version>4.4.4</smack.version>
    <bnd.importpackage>
      !android.*,!sun.security.*
    </bnd.importpackage>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-core</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-xmlparser</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-xmlparser-xpp3</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>xpp3</groupId>
      <artifactId>xpp3_min</artifactId>
      <version>1.1.4c</version>
    </dependency>
    <dependency>
      <groupId>org.jxmpp</groupId>
      <artifactId>jxmpp-core</artifactId>
      <version>1.0.3</version>
    </dependency>
    <dependency>
      <groupId>org.jxmpp</groupId>
      <artifactId>jxmpp-util-cache</artifactId>
      <version>1.0.3</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.jxmpp</groupId>
      <artifactId>jxmpp-jid</artifactId>
      <version>1.0.2</version>
    </dependency>

    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-extensions</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-im</artifactId>
      <version>${smack.version}</version>
    </dependency>

    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-tcp</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-streammanagement</artifactId>
      <version>${smack.version}</version>
    </dependency>

    <dependency>
      <groupId>org.igniterealtime.smack</groupId>
      <artifactId>smack-experimental</artifactId>
      <version>${smack.version}</version>
    </dependency>
    <dependency>
      <groupId>org.hsluv</groupId>
      <artifactId>hsluv</artifactId>
      <version>0.2</version>
    </dependency>
    <dependency>
      <groupId>org.minidns</groupId>
      <artifactId>minidns-core</artifactId>
      <version>1.0.2</version>
    </dependency>
  </dependencies>

Has anybody an idea?

cc’ing @Ingo_Bauersachs as I believe that he is using Smack in an OSGi environment too.

The ServiceLoader mechanism is not native to OSGi, you need an extension to wire that into OSGi services. I use the one from Apache Aries:

    <dependency>
      <groupId>org.apache.aries.spifly</groupId>
      <artifactId>org.apache.aries.spifly.dynamic.framework.extension</artifactId>
      <version>1.3.4</version>
    </dependency>

You need to make sure the SpiFly extension loads at an earlier/lower run-level than Smack, and smack-xmlparser-xpp3 before smack-xmlparser.

Here’s a link that explains everything: SPI Fly :: Apache Aries

@Flow if you start using the ServiceLoader at other places, it needs to be declared in the OSGi manifests with Provide-Capability / Require-Capability, like I did for the XPP subprojects (https://github.com/igniterealtime/Smack/blob/4.4.4/smack-xmlparser/build.gradle#L13 and https://github.com/igniterealtime/Smack/blob/4.4.4/smack-xmlparser-xpp3/build.gradle#L25).

1 Like

Related OpenHAB issue for cross reference:

That did the trick, thank you very much!

1 Like

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