[
https://issues.apache.org/jira/browse/TUSCANY-1487?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12516093
]
Mark Combellack commented on TUSCANY-1487:
------------------------------------------
Looking through the code, the flow of events is:
1) My "container" code sets the Thread Context Class Loader to be the
application class loader by calling:
Thread.currentThread().setContextClassLoader(applicationClassLoader)
2) Deploy the Composite by calling:
SCADomain.newInstance("MyApplication.composite");
3) The SCADomain.newInstance() method obtains the runtime and application class
loaders using the following code:
final ClassLoader runtimeClassLoader = SCADomain.class.getClassLoader();
final ClassLoader applicationClassLoader =
Thread.currentThread().getContextClassLoader();
Then, a default SCA Domain is created:
// Create a default SCA domain implementation
domain =new DefaultSCADomain(runtimeClassLoader,
applicationClassLoader,
domainURI,
contributionLocation,
composites);
4) The Constructor of the DefaultSCADomain does some setup work and then has
the following code:
//ModelResolverImpl modelResolver = new
ModelResolverImpl(applicationClassLoader);
String contributionURI = FileHelper.getName(contributionURL.getPath());
contribution = contributionService.contribute(contributionURI,
contributionURL/*, modelResolver*/, false);
****Note:****
The creation of the ModelResolverImpl with the Application Class Loader has
been commented out and is no longer passed to the contribute() method.
This change happened in SVN commit 558587
(http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java?r1=556897&r2=558587&diff_format=h)
5) The ContributionServiceImpl.contribute() method calls
ContributionServiceImpl.addContribution()
6) The ContributionServiceImpl.addContribution() method contains the following
code:
//create contribution model resolver
if (modelResolver == null) {
modelResolver = new ExtensibleModelResolver(this.modelResolverExtensionPoint,
getClass().getClassLoader(), contribution);
}
Since we no longer pass in a ModelResolver in step 4, a new
ExtensibleModelResolver is created using the class loader of the
ContributionServiceImpl class. This will use the **Runtime Class Loader** and
not the application class loader since the ContributionServiceImpl class was
loaded by the Runtime Class Loader.
7) Some time later, the JavaImplementationProcessor.resolve() method is called
to resolve the class name for the Java implementation of the SCA pojo. This is
done using the ModelResolver created in step 6.
ClassReference classReference = new
ClassReference(javaImplementation.getName());
classReference = resolver.resolveModel(ClassReference.class, classReference);
8) The ExtensibleModelResolver.resolveModel() will call the
super.resolveModel() method on the DefaultModelResolver. This will then do:
clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
classLoader.get() will return the class loader set on the ModelResolver. This
will be the **Runtime Class Loader** as set in step 6 and not the application
class loader.
At this point, the class loading fails since we are not using the application
class loader.
> Unable to use different application and runtime class loaders for a
> contribution
> --------------------------------------------------------------------------------
>
> Key: TUSCANY-1487
> URL: https://issues.apache.org/jira/browse/TUSCANY-1487
> Project: Tuscany
> Issue Type: Bug
> Components: Java SCA Core Runtime
> Affects Versions: Java-SCA-Next
> Reporter: Mark Combellack
> Priority: Minor
> Fix For: Java-SCA-Next
>
>
> I have the scenario where I am attempting to deploy an application where:
> Runtime Class Loader -> Contains all Tuscany classes
> Application Class Loader -> Contains SCA application classes and has
> Runtime Class Loader as parent
> I am currently getting the following exception:
> Note: I've cut company releated information from the stack trace.
> Caused by: org.osoa.sca.ServiceRuntimeException:
> org.osoa.sca.ServiceRuntimeException:
> org.apache.tuscany.sca.contribution.service.ContributionResolveException:
> java.lang.ClassNotFoundException:
> net.******.sca.sample.appname.impl.******Impl
> at
> org.apache.tuscany.sca.host.embedded.SCADomain.createNewInstance(SCADomain.java:264)
> at
> org.apache.tuscany.sca.host.embedded.SCADomain.newInstance(SCADomain.java:69)
> at ******
> ... 18 more
> Caused by: org.osoa.sca.ServiceRuntimeException:
> org.apache.tuscany.sca.contribution.service.ContributionResolveException:
> java.lang.ClassNotFoundException:
> net.******.sca.sample.appname.impl.******Impl
> at
> org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain.<init>(DefaultSCADomain.java:115)
> at
> org.apache.tuscany.sca.host.embedded.SCADomain.createNewInstance(SCADomain.java:230)
> ... 20 more
> Caused by:
> org.apache.tuscany.sca.contribution.service.ContributionResolveException:
> java.lang.ClassNotFoundException:
> net.******.sca.sample.appname.impl.******Impl
> at
> org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor.resolve(JavaImplementationProcessor.java:113)
> at
> org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor.resolve(JavaImplementationProcessor.java:49)
> at
> org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor.resolve(ExtensibleStAXArtifactProcessor.java:102)
> at
> org.apache.tuscany.sca.assembly.xml.BaseArtifactProcessor.resolveImplementation(BaseArtifactProcessor.java:387)
> at
> org.apache.tuscany.sca.assembly.xml.CompositeProcessor.resolve(CompositeProcessor.java:565)
> at
> org.apache.tuscany.sca.assembly.xml.CompositeProcessor.resolve(CompositeProcessor.java:66)
> at
> org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor.resolve(ExtensibleStAXArtifactProcessor.java:102)
> at
> org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.resolve(CompositeDocumentProcessor.java:86)
> at
> org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.resolve(CompositeDocumentProcessor.java:43)
> at
> org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor.resolve(ExtensibleURLArtifactProcessor.java:73)
> at
> org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.processResolvePhase(ContributionServiceImpl.java:412)
> at
> org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.addContribution(ContributionServiceImpl.java:339)
> at
> org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.contribute(ContributionServiceImpl.java:154)
> at
> org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain.<init>(DefaultSCADomain.java:113)
> ... 21 more
> Caused by: java.lang.ClassNotFoundException:
> net.******.sca.sample.appname.impl.******Impl
> ... 35 more
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]