interface nl.aj.jw.dao.impl.ISellableDao is not visible from class loader

96 views
Skip to first unread message

aj

unread,
Sep 28, 2010, 2:23:20 PM9/28/10
to impala-users
Hello,

I'm trying to build a webapp with Impala, using two modules, one for
the database logic and one for the weblogic. I'm using the
webframework wicket.

When using spring and wicket, wicket uses proxying to communicate with
the springbeans. When using this I'm getting the following error:

- interface nl.aj.jw.dao.impl.ISellableDao is not visible from class
loader

The interface is declared in the parent module of the webmodule. And
ofcourse the interface that wicket is trying to proxy is loaded by a
different class loader (because of Impala). Is there any solution for
this problem?

Regards,
AJ

Phil Zoio

unread,
Sep 29, 2010, 4:30:14 PM9/29/10
to impala...@googlegroups.com
Hi AJ

I can't comment about the specifics of your problem because I don't know enough about how your application is structured.
However, the Webframeworks sample includes an example which uses Wicket, and injects an class loaded from Impala using
the wicket-spring library.

See http://impala.googlecode.com/svn/trunk/webframeworks-sample
and http://code.google.com/p/impala/wiki/SamplesWebframework

Try comparing the structuring of your project with the sample and see if you can identify any obvious differences.

Good luck.

Phil

aj

unread,
Oct 4, 2010, 3:54:01 PM10/4/10
to impala-users
Hi Phil,

Thanks for your reply. The problem I'm having isn't a wicket problem,
but more a proxy problem. Watching Impala I see you're familiar with
proxies :-)

When generating a proxy based on a interface in Java, the interface
must be loaded with the same classloader where the proxy is generated.
My problem is that I created an interface in the database module and
that the proxy is created in the webmodule.

Do you have solution for this problem?

Regard,
AJ

On Sep 29, 10:30 pm, Phil Zoio <philz...@realsolve.co.uk> wrote:
>  Hi AJ
>
> I can't comment about the specifics of your problem because I don't know enough about how your application is structured.
> However, the Webframeworks sample includes an example which uses Wicket, and injects an class loaded from Impala using
> the wicket-spring library.
>
> Seehttp://impala.googlecode.com/svn/trunk/webframeworks-sample
> andhttp://code.google.com/p/impala/wiki/SamplesWebframework

Phil Zoio

unread,
Oct 5, 2010, 4:01:05 AM10/5/10
to impala...@googlegroups.com
AJ

You will need to make the interface visible to the web module, either in two ways:

a) by moving it up into a module which is visible to both the web and the database module
b) making the web module depend on the database module directly, through in the module.properties file of the web module

depends-on=database-module

(and also making the database module a required project in Eclipse for the web module).

I'd normally do a), but there are some situations where b) might be a good idea too.

Phil


--

Phil Zoio
Director and CTO
Realtime Despatch Software Limited
Web: http://www.realtimedespatch.co.uk
Email: ph...@realtimedespatch.co.uk
Mobile: 07595 524200
Office: 01394 384181

aj

unread,
Oct 8, 2010, 4:50:58 PM10/8/10
to impala-users
Hi Phil,

I tried both options but neither of them worked... I've created the
following structure:

- main module
--> contains the interface (ISellableDao)
--> module.properties
type=root
- web module
--> module.properties
parent=jw-main
type=web
- db module
--> module.properties
parent=jw-main

Now I try to create a proxy in the web module from the ISellableDao
interface declared in the main module. Then I get the following
stacktrace:

java.lang.IllegalArgumentException: interface
nl.aj.jw.dao.ISellableDao is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)

It's obvious because the different modules have different
classloaders. Do you have any other suggestions?

Regards,
AJ
> Email: p...@realtimedespatch.co.uk

Phil Zoio

unread,
Oct 8, 2010, 5:29:44 PM10/8/10
to impala...@googlegroups.com
AJ

What code or configuration are you using to create the proxy?

Phil

aj

unread,
Oct 8, 2010, 5:41:45 PM10/8/10
to impala-users
Hi Phil,

The code that is creating the proxy is inside wicket, the
fullstacktrace is here. I'm only getting this problem when running the
application as a server, not in my unittests.

java.lang.IllegalArgumentException: interface
nl.aj.jw.dao.ISellableDao is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at
org.apache.wicket.proxy.LazyInitProxyFactory.createProxy(LazyInitProxyFactory.java:
149)
at
org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:
125)
at org.apache.wicket.injection.Injector.inject(Injector.java:121)
at
org.apache.wicket.injection.ConfigurableInjector.inject(ConfigurableInjector.java:
39)
at
org.apache.wicket.injection.ComponentInjector.onInstantiation(ComponentInjector.java:
52)
at
org.apache.wicket.Application.notifyComponentInstantiationListeners(Application.java:
1039)
at org.apache.wicket.Component.<init>(Component.java:920)
at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:
113)
at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:
105)
at org.apache.wicket.Page.<init>(Page.java:237)
at org.apache.wicket.markup.html.WebPage.<init>(WebPage.java:185)
at nl.aj.jw.web.BasePage.<init>(BasePage.java:15)
at java.lang.reflect.Constructor.newInstance(Constructor.java:
513)
at
org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:
192)
at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:
57)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:
298)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:
320)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:
234)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:
92)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:
1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:
479)
at
org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:
138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.impalaframework.web.servlet.invocation.InvocationChain.invoke(InvocationChain.java:
88)
at
org.impalaframework.web.servlet.invocation.ModuleHttpServiceInvoker.invoke(ModuleHttpServiceInvoker.java:
115)
at
org.impalaframework.web.integration.ModuleProxyFilter.processMapping(ModuleProxyFilter.java:
70)
at
org.impalaframework.web.integration.BaseModuleProxyFilter.doFilter(BaseModuleProxyFilter.java:
72)
at
org.impalaframework.web.integration.BaseLockingProxyFilter.doFilter(BaseLockingProxyFilter.java:
77)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1153)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:
230)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:
114)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
536)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:913)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:
212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:
405)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)

Another question is, is it possible to serve static files and map the
moduleproxyfilter to /* ?

Phil Zoio

unread,
Oct 9, 2010, 4:04:15 AM10/9/10
to impala...@googlegroups.com
AJ

Take a look http://grepcode.com/file/repository.jboss.com/maven2/org.apache.wicket/wicket-ioc/1.3.5.jboss1/org/apache/wicket/proxy/LazyInitProxyFactory.java:
It looks like java.lang.reflect.Proxy.newProxyInstance that you are calling is probably taking the LazyInitProxyFactory.class.getClassLoader() as the class loader.
The ISellableDao interface will not be visible to this class loader. Only to the Impala class loader, which is also the class loader returned from 
Thread.currentThread().getContextClassLoader() (see line 137 in that class)

So I would recommend you do the following:

- set a breakpoint at line 137
- check that the context class loader is indeed the Impala class loader (specifically, it should be the one which loaded your web module)
- make sure it is not throwing an IllegalArgumentException on line 137, causing it to fall back into the code on line 149. 
If that is the case, the solution will be figuring out why this is happening. It certainly won't be possible to make it work with 
LazyInitProxyFactory.class.getClassLoader() as the class loader attempting to locate the ISellableDAO interface.

Regarding your other question, yes it is possible to serve static images. In your web module application context XML, you would set up a servlet such as this:

    <web:servlet id = "rtd2-web-resources" 
        servletClass = "org.impalaframework.web.servlet.ResourceServlet"
        initParameters = "cacheTimeout=300"/> 

and then add mapping entries such as

	<web:mapping>
	     <web:to-module prefix = "/despatch" setServletPath="true"/>
             <web:to-handler extension="css" servletName="rtd2-web-resources"/>
             <web:to-handler extension="png" servletName="rtd2-web-resources"/>
             web:to-handler extension="js" servletName="rtd2-web-resources"/>
	</web:mapping>

Hope this helps.

Phil

--

Phil Zoio
Director and CTO
Realtime Despatch Software Limited
Web: http://www.realtimedespatch.co.uk

aj

unread,
Oct 11, 2010, 4:04:55 PM10/11/10
to impala-users
Hi Phil,

Thanks for your extended reply. I'm getting closer to the problem.
When setting a breakpoint at line 137 in LazyInitProxyFactory, I see
in the debugger that:
Thread.currentThread().getContextClassLoader() returns the
WebAppClassLoader (from jetty) and not the Impala classloader.

I'm starting the server with the StartServer main class, used in the
maven example. Any suggestion why I'm not seeing the Impala class
loader?

Regards, AJ

On Oct 9, 10:04 am, Phil Zoio <p...@realtimedespatch.co.uk> wrote:
>  AJ
>
> Take a lookhttp://grepcode.com/file/repository.jboss.com/maven2/org.apache.wicke...
>
> It looks like java.lang.reflect.Proxy.newProxyInstance that you are calling is probably taking the LazyInitProxyFactory <http://grepcode.com/file/repository.jboss.com/maven2/org.apache.wicke...>.class.getClassLoader <http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjd...>() as the class loader.
> The ISellableDao interface will not be visible to this class loader. Only to the Impala class loader, which is also the class loader returned from
> Thread.currentThread <http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjd...>().getContextClassLoader <http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjd...>() (see line 137 in that class)
>
> So I would recommend you do the following:
>
> - set a breakpoint at line 137
> - check that the context class loader is indeed the Impala class loader (specifically, it should be the one which loaded your web module)
> - make sure it is not throwing an IllegalArgumentException on line 137, causing it to fall back into the code on line 149.
> If that is the case, the solution will be figuring out why this is happening. It certainly won't be possible to make it work with
> LazyInitProxyFactory <http://grepcode.com/file/repository.jboss.com/maven2/org.apache.wicke...>.class.getClassLoader <http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjd...>() as the class loader attempting to locate the ISellableDAO interface.
> ...
>
> read more »

Phil Zoio

unread,
Oct 11, 2010, 4:43:53 PM10/11/10
to impala...@googlegroups.com
Try putting a breakpoint in org.impalaframework.web.servlet.invoker.ThreadContextClassLoaderHttpServiceInvoker

Here you can see where Impala is calling Thread.currentThread().setContextClassLoader().

Ideally, at this point the class loader passed in should be the Impala web module class loader, although in your case it
might not be.

This should help narrow down the cause of the problem ...

Phil

>> read more �

aj

unread,
Oct 11, 2010, 5:12:02 PM10/11/10
to impala-users
Hi Phil,

Yoehoe, finally found it, I forgot: delegatorServletName = "jw-web" in
the web:servlet tag. So the wicket servlet was directly loaded via the
WebAppClassLoader!

Thank your very much, I can now develop on a reloading web
application!!

Regards,
AJ
> ...
>
> read more »

Phil Zoio

unread,
Oct 12, 2010, 7:01:41 AM10/12/10
to impala...@googlegroups.com
Good stuff!

>> read more �

Reply all
Reply to author
Forward
0 new messages