[ 
https://issues.apache.org/jira/browse/TUSCANY-3725?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12921660#action_12921660
 ] 

Simon Nash commented on TUSCANY-3725:
-------------------------------------

I think the problem is in this code in the JAXBContextCache.newJAXBContext() 
method:

                    // Try to set up TCCL so that JAXBContext service discovery 
works in OSGi
                    ClassLoader tccl =
                        
ClassLoaderContext.setContextClassLoader(JAXBContextCache.class.getClassLoader(),
                                                                 
registry.getServiceDiscovery(),
                                                                 // The service 
provider of JAXBContext doesn't extend JAXBContext
                                                                 // We should 
use the service name instead of the class
                                                                 
JAXBContext.class.getName(), 
                                                                 
DatatypeFactory.class.getName());
                    try {
                        JAXBContext context = 
JAXBContext.newInstance(classesToBeBound);

In the failing case I think you'll find that the jaxb-impl jar is on the 
classpath (perhaps as a result of another transitive dependency).  This jar 
contains a META-INF/services/javax.xml.bind.JAXBContext file that sets the JAXB 
context factory class to com.sun.xml.bind.v2.ContextFactory.

The JAXB API code built into JDK 6 finds this resource file on the classpath 
and attempts to load a class of this name using the thread context classloader. 
 Normally this would succeed because the jaxb-impl jar is on the classpath.  
However, the Tuscany code shown above has changed the thread context 
classloader to something Tuscany-specific and related to OSGi, and this isn't 
able to find and load the com.sun.xml.bind.v2.ContextFactory class.

The fix is to find out how jaxb-impl jar is getting onto the classpath and 
remove it.  This will cause the built-in JDK 6 JAXB implementation to be 
loaded.  However the ClassNotFoundException would still occur if a user were to 
put their own jaxb-impl jar on the classpath, which is possible if they wanted 
to use a different level of JAXB than that provided in the JDK.  To solve this, 
the Tuscany-specific OSGi-related classloader would need to be fixed to be able 
to find a jaxb-impl jar on the classpath.


> databinding-jaxb requires explicit dependency on jaxb-impl
> ----------------------------------------------------------
>
>                 Key: TUSCANY-3725
>                 URL: https://issues.apache.org/jira/browse/TUSCANY-3725
>             Project: Tuscany
>          Issue Type: Bug
>            Reporter: ant elder
>             Fix For: Java-SCA-2.0-Beta1
>
>
> The module databinding-jaxb requires explicit dependency on jaxb-impl which 
> it shouldn't as thats part of the Java 6 base. You can see the problem if you 
> remove the jaxb dependency:
> C:\Tuscany\SVN\trunk\modules\databinding-jaxb>svn diff
> Index: pom.xml
> ===================================================================
> --- pom.xml     (revision 1022443)
> +++ pom.xml     (working copy)
> @@ -62,13 +62,6 @@
>              <version>1.0.1</version>
>          </dependency>
> -        <dependency>
> -            <groupId>com.sun.xml.bind</groupId>
> -            <artifactId>jaxb-impl</artifactId>
> -            <version>2.1.12</version>
> -            <scope>runtime</scope>
> -        </dependency>
> -
>      </dependencies>
>      <repositories>
> and then build the module the tests fail with: 
> [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.getDefaultJAXBContext(JAXBContextCache.java:157)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.&lt;init&gt;(JAXBContextCache.java:122)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.&lt;init&gt;(JAXBContextCache.java:114)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCacheTestCase.testCache(JAXBContextCacheTestCase.java:46)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>       at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>       at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>       at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>       at 
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>       at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>       at 
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>       at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>       at 
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> Caused by: javax.xml.bind.JAXBException
>  - with linked exception:
> [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
>       at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:187)
>       at javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
>       at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
>       at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache$1.run(JAXBContextCache.java:138)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache$1.run(JAXBContextCache.java:127)
>       at java.security.AccessController.doPrivileged(Native Method)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.newJAXBContext(JAXBContextCache.java:127)
>       at 
> org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.getDefaultJAXBContext(JAXBContextCache.java:155)
>       ... 29 more
> Caused by: java.lang.ClassNotFoundException: 
> com.sun.xml.bind.v2.ContextFactory
>       at 
> org.apache.tuscany.sca.extensibility.impl.ClassLoaderDelegate.findClass(ClassLoaderDelegate.java:62)
>       at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>       at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>       at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:481)
>       at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:185)
>       ... 37 more
> The tests will still run fine when run within Eclipse, and also if the 
> surefire plugin is changed to have fork mode of never: 
> C:\Tuscany\SVN\trunk\modules\databinding-jaxb>svn diff
> Index: pom.xml
> ===================================================================
> --- pom.xml     (revision 1022443)
> +++ pom.xml     (working copy)
> @@ -62,13 +62,6 @@
>              <version>1.0.1</version>
>          </dependency>
> -        <dependency>
> -            <groupId>com.sun.xml.bind</groupId>
> -            <artifactId>jaxb-impl</artifactId>
> -            <version>2.1.12</version>
> -            <scope>runtime</scope>
> -        </dependency>
> -
>      </dependencies>
>      <repositories>
> @@ -169,6 +162,15 @@
>                  </configuration>
>              </plugin>
> +                    <plugin>
> +                        <groupId>org.apache.maven.plugins</groupId>
> +                        <artifactId>maven-surefire-plugin</artifactId>
> +                        <version>2.4.3</version>
> +                        <configuration>
> +                            <forkMode>never</forkMode>
> +                        </configuration>
> +                    </plugin>
> +
>          </plugins>
>      </build>
> so this is something funny with the way the JAXB ContextFactory is being 
> found or loaded by Tuscany, you can see from the above stacktrace that the 
> root of the problem is from:
> Caused by: java.lang.ClassNotFoundException: 
> com.sun.xml.bind.v2.ContextFactory
>       at 
> org.apache.tuscany.sca.extensibility.impl.ClassLoaderDelegate.findClass(ClassLoaderDelegate.java:62)
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to