Where is the JAR file that contains IExternalSystem?
Quoting Nicolas De Loof <[EMAIL PROTECTED]>:
> the webapp hasn't trouble to load ExternalSystemMockImpl. It uses reflexion
> to do it from some configuration data that
> is use to set implementation (production | mock).
>
> The problem is that the resulting object has to be casted to an interface
> from the API : IExternalSystem:
>
> (1) Class clazz = Class.forName(className);
> (2) return (IExternalSystem) clazz.newInstance();
>
> from webapp, I think IExternalSystem is loaded by webapp ClassLoader. As
> ExternalSystemMockImpl is loaded from tomcat
> "commons" ClassLoader, it doesn implements the IExternalSystem loaded by this
> commons-ClassLoader, that cannot be casted
> in IExternalSystem loaded by webapp-ClassLoader.
>
> I get a ClassCastException on line 2.
>
> Nico.
>
>
>
> > If ExternalSystemMockImpl is contained in a JAR file that's in
> > $CATALINA_HOME/common/lib, I don't see why the app wouldn't be able to load
> it.
> > For example, I've got a JAR file for the Oracle JDBC driver in common/lib
> and I
> > can do the following just fine in a JSP:
> >
> > <%
> > ClassLoader cl = getClass().getClassLoader();
> > Class clazz = cl.loadClass("oracle.jdbc.OracleDriver");
> > Object obj = clazz.newInstance();
> > %>
> >
> > If there's code in the external JAR file that needs to make use of a
> class
> > loader, it should probably use the result of
> > Thread.currentThread().getContextClassLoader(). Can you provide a little
> more
> > detail on how the app is using reflection to locate
> ExternalSystemMockImpl?
> >
> > Quoting Nicolas De Loof <[EMAIL PROTECTED]>:
> >
> > > Hi all,
> > >
> > > I'm posting on Struts list because I know they're is lot's of J2EE
> experts
> > > here.
> > >
> > > I want to test my webapp on Tomcat, but it depends on some external
> system.
> > > I've got a jar that emulates it. When I
> > > package it with the webapp (WEB-INF/lib) it works fine.
> > >
> > > I would like to test the webapp packaged without this emulator jar. I
> tried
> > > putting it in $TOMCAT/common/lib. I get a
> > > ClassCastException. I think it comes from this :
> > >
> > > webapp requires the external API, let's say a class named
> "ExternalSystem".
> > > It is configured to search for an
> > > implementation class named "ExternalSystemMockImpl" (using reflexion
> API).
> > >
> > > Webapp classloader doesn't find it, and delegate class searh to it's
> parent
> > > classloader (tomcat ones). Parent
> > > classloader finds the class from my emulator jar, run it and return
> some
> > > "MockResult" object, that implements
> > > "ExternalResult" from the external API
> > >
> > > Calling webapp tries to cast resulting object to "ExternalResult", class
> that
> > > is visible to webapp classloader.
> > >
> > > Then my code is doing :
> > >
> > > ExternalResult result = (ExternalResult) obj;
> > >
> > > where obj is my MockResult instance, that implements ExternalResult
> from
> > > parent-Classloader, and casting it to a
> > > webapp-Classloader ExternalResult fails !
> > >
> > >
> > > How can I solve this ClasLoader conflict ?
> > >
> > > Nico.
> >
> > --
> > Kris Schneider <mailto:[EMAIL PROTECTED]>
> > D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]