users@glassfish.java.net

Re: JAXBContext ClassCastException from osgi bundle with full gl

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Sat, 22 Oct 2011 01:59:26 +0530

I think I know what's happening. The bundle
snippet.osgi.jaxb_2.0.0.201110211514 which is emnedded inside the war
does not import jaxb packages, yet it uses jaxb. It has been working,
because the defaut equinox settings allow a bundle to boot delegate to
parent for all not found classes. Try setting
osgi.compatibility.bootdelegation=false in your launch.ini file and you
shall see the bundle failing to load the activator class due to missing
jaxb dependencies.

With no such changes made, this bundle loads jaxb interfaces from parent
class loader of the bundle. The parent class loader is set to system
class loader by default. As a result, your bundles sees jaxb classes
from file:.../modules/endorsed/jaxb-api-osgi.jar.
When this bundle uses jaxb, jaxb uses Thread's context class loader to
look up service providers. Now the thread's context class loader is set
to "ccl" which is nothing but the webapp's class loader. The webapp's
class loader eventually delegates to Felix to load jaxb classes and we
have configured Felix such that Felix loads classes jaxb classes from
jaxb bundles instead of endorsed directory. As a result, you see the
classcastexception.

Instead of solving this unreal problem, it will be far more productive
to convert the app to a WAB and deploy it to GlassFish. Find attached a
working WAB with its manifest given below:

[MANIFEST snippet.osgi.jaxb_2.0.0.201110211514.jar]
Bundle-ActivationPolicy lazy
Bundle-Activator snippet.osgi.Activator
Bundle-ManifestVersion 2
Bundle-Name Jaxb
Bundle-RequiredExecutionEnvironment JavaSE-1.6
Bundle-SymbolicName snippet.osgi.jaxb;singleton:=true
Bundle-Version 2.0.0.201110211514
*DynamicImport-Package javax.xml.bind, javax.xml.bind.* *
Import-Package
javax.servlet;version="2.5.0",javax.servlet.http;version="2.5.0",org.osgi.framework
Manifest-Version 1.0
*Web-ContextPath /hellojaxb *

Thanks,
Sahoo

On Friday 21 October 2011 07:56 PM, forums_at_java.net wrote:
> Hello Sahoo and thanks for you reply,
>
> After more investigations I am quite sure now the issue is not related to
> glassfish but the application itself. The application I tried to
> deploy is
> OSGI, but packaged as a legacy war file using equinox servlet bridge, so
> there is some side effects with the servlet briges that cause this issue.
>
> If you are interested, I can provide some explainations.
>
> Equinox Servlet Bridges allow to package osgi application as a legacy WAR
> file so it allows to run osgi application in non osgi application
> server like
> Tomcat or Weblogic Server, by starting equinox inside a legacy web
> application.
>
> I manage to reproduce the issue with a simpler application (I will attach
> here). After deploying the war you can access to
> http://localhost:8080/hellojaxb/hello/jaxb so you can see the exception.
>
> By updating equinox configuration, I manage to have the issue gone.
>
> In provided sample in *WEB-INF/launch.ini
> *replacing *osgi.contextClassLoaderParent* from *ccl* to *app*, then
> sample
> application works.
>
> This parameter manage parent classloader type of the context classloader
> used by the Equinox Framework. When *ccl* the original context
> classloader
> that was set when the framework launched is used, *app* the application
> class loader is used. With ccl jaxb classes are seen twice.
>
> Unfortunately for me *app* works for the simple application, but for the
> original application I had the issue with it has to be *ccl*, so in
> conclusion, the best way for me to have this issue solve is to be able to
> re-package the application as a true *Web Application Bundle.*
>
> Regards,
>
> Arnaud
>
>
> --
>
> [Message sent by forum member 'amergey']
>
> View Post: http://forums.java.net/node/855100
>
>
>