users@glassfish.java.net

Reading manifest from OSGi bundle

From: <glassfish_at_javadesktop.org>
Date: Tue, 10 Nov 2009 07:21:36 PST

There seems to be a problem when trying to read the manifest from an OSGi bundle. The following code returns "manifest is null"

private String getAttribute(String attrName)
{
        Class<?> clazz = javax.faces.application.Application.class;
        String classResource = "/" + clazz.getCanonicalName().replace(".", "/") + ".class";
        InputStream is = clazz.getResourceAsStream(classResource);
        if(is == null)
                return "InputStream null";

        try{
                JarInputStream jis = new JarInputStream(is);
                if(jis == null)
                        return "JarInputStream null";
                
                final Manifest manifest = jis.getManifest();
                if(manifest == null)
                        return "manifest is null";
                
                final Attributes attr = manifest.getMainAttributes();
                return attr.getValue(attrName);
        }catch(IOException e){
                return "Error reading JAR file.";
        }
}

I'm running this on the latest GlassFish v3 promoted build, glassfish-v3-b71. This code used to work on GlassFish v2, I guess the problem might be something OSGi related.

I have made a little test:

Class<?> clazz = javax.faces.application.Application.class;
String classResource = "/" + clazz.getCanonicalName().replace(".", "/") + ".class";
String res = clazz.getResource(classResource).toString();

This will put "bundle://40.0:1/javax/faces/application/Application.class" in res. In previous versions I would get a jar file. Do you know what I'm doing wrong, or what is the proper way of doing this on GlassFish v3?
[Message sent by forum member 'bluewing' (blue5wing_at_yahoo.com)]

http://forums.java.net/jive/thread.jspa?messageID=371282