Thrift
  1. Thrift
  2. THRIFT-184

Add OSGi Manifest headers to the libthrift java library to be able to use Thrift in the OSGi runtime

    Details

    • Type: New Feature New Feature
    • Status: Reopened
    • Priority: Trivial Trivial
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: Java - Library
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      To be able to use Thrift in the OSGi runtime (see http://en.wikipedia.org/wiki/OSGi), some additional Manifest entries are needed. The bnd-tool (see http://www.aqute.biz/Code/Bnd) creates this entries automatically.

      1. bnd-0.0.249.jar
        250 kB
        Siamak Haschemi
      2. libthrift.bnd
        0.0 kB
        Siamak Haschemi
      3. osgi.patch
        0.5 kB
        Siamak Haschemi
      4. thrift-184.patch
        13 kB
        Jake Farrell

        Issue Links

          Activity

          Hide
          Shuva Jyoti Kar added a comment -

          Thanks Jake, Any pointers to the fact that this has been implemented by anyone ?

          Show
          Shuva Jyoti Kar added a comment - Thanks Jake, Any pointers to the fact that this has been implemented by anyone ?
          Hide
          Jake Farrell added a comment -

          The current Apache Thrift java versions do not come with OSGI headers. If you need this in your project I would look at using the wrap goal in the maven-bundle-plugin from Apache Felix

          Show
          Jake Farrell added a comment - The current Apache Thrift java versions do not come with OSGI headers. If you need this in your project I would look at using the wrap goal in the maven-bundle-plugin from Apache Felix
          Hide
          Shuva Jyoti Kar added a comment -

          Thanks Jakes for the clarification. So I am of the understanding that integrating Thrift 0.9.0. a bundle in OSGI will still be blocked due to this ? Am I correct

          Show
          Shuva Jyoti Kar added a comment - Thanks Jakes for the clarification. So I am of the understanding that integrating Thrift 0.9.0. a bundle in OSGI will still be blocked due to this ? Am I correct
          Hide
          Jake Farrell added a comment -

          This is still an open item and will be looked at as we start progress towards the 1.0 release

          Show
          Jake Farrell added a comment - This is still an open item and will be looked at as we start progress towards the 1.0 release
          Hide
          Shuva Jyoti Kar added a comment -

          Hi Jakes,

          I was trying to integrate Thrift as a bundle in OSGI, when I came across this as an issue. Could you let me know as to whether this is still an issue, as I find it has been reopened. i am using libthrift-0.9.0.jar, so in case u have a workaround it would be great if you could let me apprise of it ..

          Show
          Shuva Jyoti Kar added a comment - Hi Jakes, I was trying to integrate Thrift as a bundle in OSGI, when I came across this as an issue. Could you let me know as to whether this is still an issue, as I find it has been reopened. i am using libthrift-0.9.0.jar, so in case u have a workaround it would be great if you could let me apprise of it ..
          Hide
          Ioannis Canellos added a comment -

          Good work!

          A proper manifest is the first step required in order to enjoy thrift inside OSGi.
          However, I can see issues with the extensive use of Class.forName() in thrift, which is an approach that don't actually promotes modularity.

          Ideally, a way for the user to specify the class loader that will be used for loading classes would solve this.
          An alternative would be to add a fallback to the thread context class loader.

          Show
          Ioannis Canellos added a comment - Good work! A proper manifest is the first step required in order to enjoy thrift inside OSGi. However, I can see issues with the extensive use of Class.forName() in thrift, which is an approach that don't actually promotes modularity. Ideally, a way for the user to specify the class loader that will be used for loading classes would solve this. An alternative would be to add a fallback to the thread context class loader.
          Hide
          Jake Farrell added a comment -

          The attached patch generates the following manifest with osgi headers using the maven bundle plugin. This causes changes to the build files for fb303, as3 and the js tests. I ran into some issues with the bundle plugin which I am looking into and I do not want to commit this until they are addressed

          Manifest-Version: 1.0
          Export-Package: org.apache.thrift.async;uses:="org.apache.thrift.proto
          col,org.apache.thrift.transport,org.slf4j,org.apache.thrift";version=
          "0.8.0.snapshot",org.apache.thrift;uses:="org.apache.thrift.protocol,
          org.apache.thrift.transport,org.apache.thrift.scheme";version="0.8.0.
          snapshot",org.apache.thrift.meta_data;uses:="org.apache.thrift";versi
          on="0.8.0.snapshot",org.apache.thrift.protocol;uses:="org.apache.thri
          ft.transport,org.apache.thrift,org.apache.thrift.scheme";version="0.8
          .0.snapshot",org.apache.thrift.scheme;uses:="org.apache.thrift.protoc
          ol,org.apache.thrift";version="0.8.0.snapshot",org.apache.thrift.serv
          er;uses:="org.apache.thrift.transport,org.apache.thrift.protocol,org.
          slf4j,org.apache.thrift,javax.servlet,javax.servlet.http";version="0.
          8.0.snapshot",org.apache.thrift.transport;uses:="org.apache.commons.l
          ang,org.apache.thrift.protocol,org.apache.thrift,org.apache.http.clie
          nt,org.apache.http.params,org.apache.http.entity,org.apache.http.util
          ,org.apache.http.client.methods,org.apache.http,org.slf4j,javax.net.s
          sl,javax.net,javax.security.sasl,javax.security.auth.callback";versio
          n="0.8.0.snapshot"
          Built-By: jake
          Tool: Bnd-1.43.0
          Bundle-Name: Apache Thrift
          Created-By: Apache Maven Bundle Plugin
          Build-Jdk: 1.6.0_29
          Bundle-Version: 0.8.0.snapshot
          Bnd-LastModified: 1320985455994
          Bundle-ManifestVersion: 2
          Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
          Bundle-Description: Thrift is a software framework for scalable cross-
          language services development.
          Import-Package: javax.net,javax.net.ssl,javax.security.auth.callback,j
          avax.security.sasl,javax.servlet,javax.servlet.http,org.apache.common
          s.lang;version="[2.5,3)",org.apache.http,org.apache.http.client,org.a
          pache.http.client.methods,org.apache.http.entity,org.apache.http.para
          ms,org.apache.http.util,org.slf4j;version="[1.5,2)"
          Bundle-SymbolicName: org.apache.thrift.libthrift

          Show
          Jake Farrell added a comment - The attached patch generates the following manifest with osgi headers using the maven bundle plugin. This causes changes to the build files for fb303, as3 and the js tests. I ran into some issues with the bundle plugin which I am looking into and I do not want to commit this until they are addressed Manifest-Version: 1.0 Export-Package: org.apache.thrift.async;uses:="org.apache.thrift.proto col,org.apache.thrift.transport,org.slf4j,org.apache.thrift";version= "0.8.0.snapshot",org.apache.thrift;uses:="org.apache.thrift.protocol, org.apache.thrift.transport,org.apache.thrift.scheme";version="0.8.0. snapshot",org.apache.thrift.meta_data;uses:="org.apache.thrift";versi on="0.8.0.snapshot",org.apache.thrift.protocol;uses:="org.apache.thri ft.transport,org.apache.thrift,org.apache.thrift.scheme";version="0.8 .0.snapshot",org.apache.thrift.scheme;uses:="org.apache.thrift.protoc ol,org.apache.thrift";version="0.8.0.snapshot",org.apache.thrift.serv er;uses:="org.apache.thrift.transport,org.apache.thrift.protocol,org. slf4j,org.apache.thrift,javax.servlet,javax.servlet.http";version="0. 8.0.snapshot",org.apache.thrift.transport;uses:="org.apache.commons.l ang,org.apache.thrift.protocol,org.apache.thrift,org.apache.http.clie nt,org.apache.http.params,org.apache.http.entity,org.apache.http.util ,org.apache.http.client.methods,org.apache.http,org.slf4j,javax.net.s sl,javax.net,javax.security.sasl,javax.security.auth.callback";versio n="0.8.0.snapshot" Built-By: jake Tool: Bnd-1.43.0 Bundle-Name: Apache Thrift Created-By: Apache Maven Bundle Plugin Build-Jdk: 1.6.0_29 Bundle-Version: 0.8.0.snapshot Bnd-LastModified: 1320985455994 Bundle-ManifestVersion: 2 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-Description: Thrift is a software framework for scalable cross- language services development. Import-Package: javax.net,javax.net.ssl,javax.security.auth.callback,j avax.security.sasl,javax.servlet,javax.servlet.http,org.apache.common s.lang;version="[2.5,3)",org.apache.http,org.apache.http.client,org.a pache.http.client.methods,org.apache.http.entity,org.apache.http.para ms,org.apache.http.util,org.slf4j;version="[1.5,2)" Bundle-SymbolicName: org.apache.thrift.libthrift
          Hide
          Jake Farrell added a comment -

          Its not problematic, it was the way that bnd was presented for inclusion. I'm working on adding in the maven bundle plugin via an ant task which will automatically download bnd as a build dependency and generate the desired headers based on the auto generated pom we all ready have in place. Hoping to have it all working for libthrift and libfb303 shortly

          Show
          Jake Farrell added a comment - Its not problematic, it was the way that bnd was presented for inclusion. I'm working on adding in the maven bundle plugin via an ant task which will automatically download bnd as a build dependency and generate the desired headers based on the auto generated pom we all ready have in place. Hoping to have it all working for libthrift and libfb303 shortly
          Hide
          Siamak Haschemi added a comment -

          The list of imported and exported package will evolve over time. So you will have to maintain these imports and exports for every single release!

          The BND-tool automates this process:
          1) You build your non-OSGi JAR (with missing OSGi headers)
          2) You provide that JAR to BND. BND looks at any *.class within the JAR and calculates the imported packages. The exported packages are your choice (its the public API). But again BND can help you, because it supports wildcards.
          3) BND produces an OSGi-compatible JAR

          Note: Your distributed thrift-JAR will have no runtime-dependencies to BND or OSGi. It is just enhanced with some metadata. I don't see why a build-time depdency on BND is problematic.

          Show
          Siamak Haschemi added a comment - The list of imported and exported package will evolve over time. So you will have to maintain these imports and exports for every single release! The BND-tool automates this process: 1) You build your non-OSGi JAR (with missing OSGi headers) 2) You provide that JAR to BND. BND looks at any *.class within the JAR and calculates the imported packages. The exported packages are your choice (its the public API). But again BND can help you, because it supports wildcards. 3) BND produces an OSGi-compatible JAR Note: Your distributed thrift-JAR will have no runtime-dependencies to BND or OSGi. It is just enhanced with some metadata. I don't see why a build-time depdency on BND is problematic.
          Hide
          Jake Farrell added a comment -

          1. It does not export other packages, such as org.apache.thrift.transport,
          org.apache.thrift.server, etc (for instance, I need
          org.apache.thrift.transport exported to implement my own transport).

          2. It does not import packages on which it depends. For instance,
          javax.servlet or various org.apache.http.* packages. Therefore I presume it
          will fail to work properly in OSGi runtime as well.

          3. The version 0.8.0-snapshot appearing in the manifest is invalid.
          According to OSGi spec the version should be in form:

          version ::=
          major( '.' minor ( '.' micro ( '.' qualifier )? )? )?
          major ::= number // See 1.3.2
          minor ::= number
          micro ::= number
          qualifier ::= ( alphanum | '_' | '-' )+

          Show
          Jake Farrell added a comment - 1. It does not export other packages, such as org.apache.thrift.transport, org.apache.thrift.server, etc (for instance, I need org.apache.thrift.transport exported to implement my own transport). 2. It does not import packages on which it depends. For instance, javax.servlet or various org.apache.http.* packages. Therefore I presume it will fail to work properly in OSGi runtime as well. 3. The version 0.8.0-snapshot appearing in the manifest is invalid. According to OSGi spec the version should be in form: version ::= major( '.' minor ( '.' micro ( '.' qualifier )? )? )? major ::= number // See 1.3.2 minor ::= number micro ::= number qualifier ::= ( alphanum | '_' | '-' )+
          Hide
          Hudson added a comment -

          Integrated in Thrift #328 (See https://builds.apache.org/job/Thrift/328/)
          Thrift-184: Add OSGi Manifest headers to the libthrift java library to be able to use Thrift in the OSGi runtime
          Client: java
          Patch: Jake Farrell

          Updated manifest to add OSGI support.

          Show
          Hudson added a comment - Integrated in Thrift #328 (See https://builds.apache.org/job/Thrift/328/ ) Thrift-184: Add OSGi Manifest headers to the libthrift java library to be able to use Thrift in the OSGi runtime Client: java Patch: Jake Farrell Updated manifest to add OSGI support.
          Hide
          Jake Farrell added a comment -

          Updated Manifest to now add osgi support. Example below shows active jar in eclipse osgi container

          jake:java jake$ java -jar eclipse/plugins/org.eclipse.osgi_3.6.0.v20100517.jar -console

          osgi> ss

          Framework is launched.

          id State Bundle
          0 ACTIVE org.eclipse.osgi_3.6.0.v20100517

          osgi> install file:///apache/thrift/trunk/lib/java/build/libthrift-0.8.0.jar
          Bundle id is 5

          osgi> ss

          Framework is launched.

          id State Bundle
          0 ACTIVE org.eclipse.osgi_3.6.0.v20100517
          5 INSTALLED org.apache.thrift_0.8.0

          osgi> start 5

          osgi> ss

          Framework is launched.

          id State Bundle
          0 ACTIVE org.eclipse.osgi_3.6.0.v20100517
          5 ACTIVE org.apache.thrift_0.8.0

          osgi>

          Show
          Jake Farrell added a comment - Updated Manifest to now add osgi support. Example below shows active jar in eclipse osgi container jake:java jake$ java -jar eclipse/plugins/org.eclipse.osgi_3.6.0.v20100517.jar -console osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.6.0.v20100517 osgi> install file:///apache/thrift/trunk/lib/java/build/libthrift-0.8.0.jar Bundle id is 5 osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.6.0.v20100517 5 INSTALLED org.apache.thrift_0.8.0 osgi> start 5 osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.6.0.v20100517 5 ACTIVE org.apache.thrift_0.8.0 osgi>
          Hide
          JCF added a comment -

          Is bnd necessary here since there is no activator and the goal is to make org.apache.thrift available to other bundles. Putting the following in the manifest when generating the libthrift.jar in the dist goal should solve this problem.

           
          <manifest>
            <attribute name="Implementation-Version" value="${version}"/>
            <!-- Added for OSGI support -->
            <attribute name="Bundle-Name" value="Apache Thrift"/>
            <attribute name="Bundle-Description" value="Apache Thrift library"/>    
            <attribute name="Bundle-SymbolicName" value="${thrift.groupid}"/>	
            <attribute name="Bundle-ManifestVersion" value="2"/>
            <attribute name="Bundle-Version" value="${version}"/>
            <attribute name="Export-Package" value="${thrift.groupid}"/>
            <attribute name="Import-Package" value="*"/>
          </manifest>
          

          Simple test showed this modified manifest jar loaded in felix.
          START LEVEL 1
          ID|State |Level|Name
          30|Installed | 1|Apache Thrift (0.7.0)

          Siamak, if you could please test this in your setup to verify it works for what you are trying to accomplish i'll generate a patch and attach it.

          Show
          JCF added a comment - Is bnd necessary here since there is no activator and the goal is to make org.apache.thrift available to other bundles. Putting the following in the manifest when generating the libthrift.jar in the dist goal should solve this problem. <manifest> <attribute name= "Implementation-Version" value= "${version}" /> <!-- Added for OSGI support --> <attribute name= "Bundle-Name" value= "Apache Thrift" /> <attribute name= "Bundle-Description" value= "Apache Thrift library" /> <attribute name= "Bundle-SymbolicName" value= "${thrift.groupid}" /> <attribute name= "Bundle-ManifestVersion" value= "2" /> <attribute name= "Bundle-Version" value= "${version}" /> <attribute name= "Export-Package" value= "${thrift.groupid}" /> <attribute name= "Import-Package" value= "*" /> </manifest> Simple test showed this modified manifest jar loaded in felix. START LEVEL 1 ID|State |Level|Name 30|Installed | 1|Apache Thrift (0.7.0) Siamak, if you could please test this in your setup to verify it works for what you are trying to accomplish i'll generate a patch and attach it.
          Hide
          Siamak Haschemi added a comment -

          Hello,

          sorry. I've missed the mentioned user-specified classpath entries. Could you give me a link, so I can check out.

          Show
          Siamak Haschemi added a comment - Hello, sorry. I've missed the mentioned user-specified classpath entries. Could you give me a link, so I can check out.
          Hide
          Bryan Duxbury added a comment -

          Now that user-specified classpath entries can be taken into account, we shouldn't need to have a jar bundled with Thrift. Siamak, is the rest of the patch still relevant?

          Show
          Bryan Duxbury added a comment - Now that user-specified classpath entries can be taken into account, we shouldn't need to have a jar bundled with Thrift. Siamak, is the rest of the patch still relevant?
          Hide
          Siamak Haschemi added a comment -

          Hello David,

          we have to options here:

          1) I will change the build instructions and add a new target in which the current bnd file will be diwnloaded. The standard build will not use bnd. However, calling the new task will result in a wget-call to download the current bnd-package.

          2) I will create a MANIFEST file for the libthrift.jar compatible to OSGi by hand and include it in the build. So no bnd dependency will exists.

          I think it's up to you to decide.

          Kind regards,

          Siamak

          Show
          Siamak Haschemi added a comment - Hello David, we have to options here: 1) I will change the build instructions and add a new target in which the current bnd file will be diwnloaded. The standard build will not use bnd. However, calling the new task will result in a wget-call to download the current bnd-package. 2) I will create a MANIFEST file for the libthrift.jar compatible to OSGi by hand and include it in the build. So no bnd dependency will exists. I think it's up to you to decide. Kind regards, Siamak
          Hide
          Siamak Haschemi added a comment -

          The current bnd package

          Show
          Siamak Haschemi added a comment - The current bnd package
          Hide
          Siamak Haschemi added a comment -

          The patch for the lib/java/build.xml file to support creating the manifest using bnd

          Show
          Siamak Haschemi added a comment - The patch for the lib/java/build.xml file to support creating the manifest using bnd
          Hide
          Siamak Haschemi added a comment -

          The decription file for bnd

          Show
          Siamak Haschemi added a comment - The decription file for bnd
          Hide
          David Reiss added a comment -

          Please attach individual files instead of a big zip.

          I don't really understand this, so I'd like feedback from others.

          However, I don't think we can put a 200k JAR file in the Thrift distribution nor make it a dependency. Is there any way we could make this an optional part of the build process and expect users to install BND if they want to use it?

          Show
          David Reiss added a comment - Please attach individual files instead of a big zip. I don't really understand this, so I'd like feedback from others. However, I don't think we can put a 200k JAR file in the Thrift distribution nor make it a dependency. Is there any way we could make this an optional part of the build process and expect users to install BND if they want to use it?
          Hide
          Siamak Haschemi added a comment -

          I forget to say that the Manifest entries does not affect the usage of the JAR-file outside of the OSGi runtime. They are simply some metadata for OSGi to know which packages are available to other components (since this dependencies are handled in OSGi explicit).

          Show
          Siamak Haschemi added a comment - I forget to say that the Manifest entries does not affect the usage of the JAR-file outside of the OSGi runtime. They are simply some metadata for OSGi to know which packages are available to other components (since this dependencies are handled in OSGi explicit).
          Hide
          Siamak Haschemi added a comment - - edited

          The attached zip-file contains:

          • osgi.patch which patches the lib/java/build.xml to call the BND-Library to create the extra manifest headers
          • The libthrift.bnd defnition file for BND (has to be placed under lib/java)
          • The current BND Jar-file (has to be placed under lib/java)
          Show
          Siamak Haschemi added a comment - - edited The attached zip-file contains: osgi.patch which patches the lib/java/build.xml to call the BND-Library to create the extra manifest headers The libthrift.bnd defnition file for BND (has to be placed under lib/java) The current BND Jar-file (has to be placed under lib/java)

            People

            • Assignee:
              Jake Farrell
              Reporter:
              Siamak Haschemi
            • Votes:
              3 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 10m
                10m
                Remaining:
                Remaining Estimate - 10m
                10m
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development