paho.mqtt.java icon indicating copy to clipboard operation
paho.mqtt.java copied to clipboard

OSGi - org.eclipse.paho.mqttv5.client does not export sub packages

Open davsclaus opened this issue 4 years ago • 3 comments
trafficstars

Please fill out the form below before submitting, thank you!

  • [x] Bug exists Release Version 1.2.5 ( Master Branch)

We are having a new paho mqtt v5 camel component and for our OSGi support then we noticed that the bundle JAR only exports

Export-Package: org.eclipse.paho.mqttv5.client;version="1.2.5"

As we use the memory persistence in the persist sub package then OSGi imports fails.

missing requirement [org.apache.camel.camel-paho-mqtt5/3.8.0.SNAPSHOT] osgi.wiring.package; filter:="(osgi.wiring.package=org.eclipse.paho.mqttv5.client.persist)"]]

I wonder if you can make the bundle JAR export its sub packages - or if they are really not for end users, then mark them as private packages in the bundle JAR manifest, then its more obvious to know.

davsclaus avatar Jan 15 '21 12:01 davsclaus

Here is the OSGi export for the v3 bundle JAR with version 1.2.5

Export-Package: org.eclipse.paho.client.mqttv3;version="1.2.5",org.ecl
 ipse.paho.client.mqttv3.logging;version="1.2.5",org.eclipse.paho.clie
 nt.mqttv3.persist;version="1.2.5",org.eclipse.paho.client.mqttv3.util
 ;version="1.2.5"

davsclaus avatar Jan 15 '21 12:01 davsclaus

I would also like this to be addressed. We are using the org.eclipse.paho.mqttv5.common.MqttException, which seems like a common use case.

Ideally the jar would list all the public packages. Something like this?

Export-Package: org.eclipse.paho.mqttv5.client;version="1.2.5",org.ecl
 ipse.paho.mqttv5.common;version="1.2.5",org.eclipse.paho.mqttv5.commo
 n.util;version="1.2.5",org.eclipse.paho.mqttv5.client.logging;version
 ="1.2.5",org.eclipse.paho.mqttv5.client.persist;version="1.2.5",org.e
 clipse.paho.mqttv5.client.spi;version="1.2.5",org.eclipse.paho.mqttv5
 .client.util;version="1.2.5"

JurriaanHeuberger avatar Jan 19 '22 23:01 JurriaanHeuberger

A temporary workaround

  • If anyone expects to use paho-mqttv5 in Apache-Karaf and Apache-Camel, here's a temporary workaround to help you deal with the error. I hope this helps.
  • The steps are as follows:
    1. Find apache-camel-xxx-features.xml in your local maven-repository. For example: ~/.m2/repository/org/apache/camel/karaf/apache-camel/3.9.0/apache-camel-3.9.0-features.xml
    2. Comment out the content identified by camel-paho-mqtt5 in the xml file, just like this:
    <!-- paho v5 does not work in OSGi: https://github.com/eclipse/paho.mqtt.java/issues/857 -->
    <feature name='camel-paho-mqtt5' version='3.9.0' start-level='50'>
      <feature version='3.9.0'>camel-core</feature>
      <bundle>mvn:org.eclipse.paho/org.eclipse.paho.mqttv5.client/1.2.5</bundle>
      <bundle>mvn:org.apache.camel/camel-paho-mqtt5/3.9.0</bundle>
    </feature>
    
    1. Now, you can see camel-paho-mqtt5 by using this command feature:list | grep camel-paho-mqtt5 in Apache-Karaf.
    2. Find org.eclipse.paho.mqttv5.client-1.2.5.jar in your local maven-repository. For example: ~/.m2/repository/org/eclipse/paho/org.eclipse.paho.mqttv5.client/1.2.5. You need to modify this file ./META-INF/MANIFEST.MF in that jar as stated in the comments above. For example: Download Fixed Jar
    Manifest-Version: 1.0
    Bundle-SymbolicName: org.eclipse.paho.mqttv5.client
    Bundle-ManifestVersion: 2
    Bundle-RequiredExecutionEnvironment: JavaSE-1.8
    Bundle-ActivationPolicy: lazy
    Bundle-Vendor: Paho
    Import-Package: javax.net;resolution:=optional,javax.net.ssl;resolutio
     n:=optional
    Export-Package: org.eclipse.paho.mqttv5.client;version="1.2.5",
     org.eclipse.paho.mqttv5.common;version="1.2.5",
     org.eclipse.paho.mqttv5.common.nls;version="1.2.5",
     org.eclipse.paho.mqttv5.common.packet;version="1.2.5",
     org.eclipse.paho.mqttv5.common.packet.util;version="1.2.5",
     org.eclipse.paho.mqttv5.common.util;version="1.2.5",
     org.eclipse.paho.mqttv5.client.internal;version="1.2.5",
     org.eclipse.paho.mqttv5.client.internal.nls;version="1.2.5",
     org.eclipse.paho.mqttv5.client.logging;version="1.2.5",
     org.eclipse.paho.mqttv5.client.persist;version="1.2.5",
     org.eclipse.paho.mqttv5.client.security;version="1.2.5",
     org.eclipse.paho.mqttv5.client.spi;version="1.2.5",
     org.eclipse.paho.mqttv5.client.util;version="1.2.5",
     org.eclipse.paho.mqttv5.client.websocket;version="1.2.5",
     org.eclipse.paho.mqttv5.client.wire;version="1.2.5"
    Bundle-Name: Paho Mqtt Client
    Bundle-Version: 1.2.5
    Bundle-Localization: bundle
    Build-Jdk-Spec: 1.8
    Created-By: Maven Archiver 3.5.0
    
    1. Finally, move the fixed jar to your local maven-repository(override the old jar).
    2. Now you can install camel-paho-mqtt5 normally. feature:install camel-paho-mqtt5
    3. I've tested the producer mode and the consumer mode. It is OK.

  • Here is an example for OSGi Blueprint
    • Consumer
    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint
        xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
          http://www.osgi.org/xmlns/blueprint/v1.0.0
          http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    
        <camelContext xmlns="http://camel.apache.org/schema/blueprint">
          <route>
            <from uri="paho-mqtt5:topic_demo?brokerUrl=tcp://<your_ip>:1883&amp;clientId=xxxId&amp;qos=2"/>
    
            <log message="[Consumer] Receive message from MQTT Server:"/>
            <log message="    HEADERS = ${headers}"/>
            <log message="    MESSAGE = ${body}"/>
          </route>
        </camelContext>
    
    </blueprint>
    
    • Producer
    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint
       xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
         http://www.osgi.org/xmlns/blueprint/v1.0.0
         http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    
       <camelContext xmlns="http://camel.apache.org/schema/blueprint">
           <route>
               <!-- Start Jetty HTTP Server -->
               <from uri="jetty:http://0.0.0.0:8080/produce"/>
               <convertBodyTo type="java.lang.String"/>
               <setProperty name="jsonObj">
                   <jsonpath>$</jsonpath>
               </setProperty>
               <log message="[Producer] Send message to MQTT Server: "/>
               <log message="    MESSAGE = ${exchangeProperty.jsonObj}"/>
    
               <!-- Remove HTTP header information -->
               <removeHeaders pattern="*"/>
    
               <to uri="paho-mqtt5:topic_demo?brokerUrl=tcp://<your_ip>:1883&amp;clientId=xxxId&amp;qos=2"/>
           </route>
       </camelContext>
    </blueprint>
    

AlionSSS avatar Jul 25 '23 08:07 AlionSSS