Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Custom webapp classloader in jetty 7.4.5

Hi all,

I'm writing a spring based web application for our company and I received
orders that I should encrypt classes of our app (it's not my idea, I just
have to do it :) )

I found a simple implementation of classloader that might do the trick
here:
http://community.decisci.com/content/encrypting-your-java-application.
It's basically a URLClassLoader that implements its own loadClass and
findClass methods.

I followed instructions from
http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading#Using_a_Custom_WebAppClassLoader,
I created my own classloader by extending WebAppClassLoader. I've
implemented findClass and loadClass methods as suggested in the first link
(almost copy & paste - for class files that end with ".class" I use
super.findClass, for classes ending with ".classx" ("encrypted classes") I
use the mechanism described in the 1st link).

I've set the classloader using context in jetty.

    <Set name="contextPath">/server</Set>
    <Set name="war">
/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT.war</Set>
    <Set name="classLoader">
        <New class="org.eclipse.jetty.webapp.WebAppClassLoaderEncrypted">
            <Arg><Ref id="clsLdrCtx"/></Arg>
        </New>
    </Set>
</Configure>

When I run jetty, I run into problems with dependency injection. I got
this exception (RestUtils class is the enctrypted class):

#17:34:27.841 o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'playerResource': Autowiring of fields failed; nested
exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private cz.company.api.rest.RestUtils
cz.company.server.api.rest.PlayerResource.restUtils; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique
bean of type [cz.company.server.api.rest.RestUtils] is defined:
Unsatisfied dependency of type [class
cz.company.server.api.rest.RestUtils]: expected at least 1 matching bean
          at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at java.security.AccessController.doPrivileged(Native Method)
~[na:1.6.0_22]
          at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
~[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
[spring-2.5.6.SEC02.jar:2.5.6.SEC02]
          at
org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44)
[resteasy-spring-2.2.1.GA.jar:na]
          at
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:640)
[jetty-server-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:229)
[jetty-servlet-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208)
[jetty-webapp-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
[jetty-server-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449)
[jetty-webapp-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
[jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:180)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:482)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileChanged(ScanningAppProvider.java:154)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileChanged(ScanningAppProvider.java:55)
[jetty-deploy-7.4.5.v20110725.jar:7.4.5.v20110725]
          at org.eclipse.jetty.util.Scanner.reportChange(Scanner.java:655)
[jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
          at
org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:534)
[jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
          at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394)
[jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
          at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:345)
[jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
          at java.util.TimerThread.mainLoop(Timer.java:534) [na:1.6.0_22]
          at java.util.TimerThread.run(Timer.java:484) [na:1.6.0_22]

If I don't override findClass method, I just runs fine (without encrypted
classes).
(I took a look at findClass implementation in URLClassLoader.java -- it
does almost the same as my implementation, BUT the class resolving
operation is performed within AccessController.doPrivileged() method. Do
you think this might be the problem?)

Also when I tested it with webapp without spring (no DI), it worked ok.

Maybe this is more question about spring classloading, but still - there
can be someone who implemented their own classloader with spring app. Any
help is appreciated!
Thanks!
Frank

--
Using Opera's revolutionary email client: http://www.opera.com/mail/


Back to the top