powered by Jive Software

Java library hell

I’ve got an Openfire plugin which has some JAXB/WS libraries to communicate with a web service via SOAP.

If the jars are in Openfire\plugins\myplugin\lib then I get the following error:

com.sun.xml.wss.XWSSecurityException: java.lang.ClassNotFoundException: com.etrali.sdk.jwsdp.security.SecurityEnvironmentHandler
at com.sun.xml.xwss.SecurityConfiguration.(SecurityConfiguration.java:85)
at com.sun.xml.xwss.SecurityConfigurationFactory.newXWSSecurityConfiguration(Secur ityConfigurationFactory.java:65)
at com.etrali.sdk.jwsdp.directories.client.EtradealSettingsClient.connect(Etradeal SettingsClient.java:140)
at net.gltd.gtms.telephony.etrali.websvc.services.etradealsettings.EtradealSetting sWebService.connect(EtradealSettingsWebService.java:70)
at net.gltd.gtms.telephony.etrali.websvc.services.etradealsettings.EtradealSetting sWebService.getConfigs(EtradealSettingsWebService.java:94)
at net.gltd.gtms.plugin.etrali.web.EtradealWebConfig.getWebConfigs(EtradealWebConf ig.java:140)
at net.gltd.gtms.plugin.etrali.web.EtradealWebConfig.webConfigsToString(EtradealWe bConfig.java:119)
at net.gltd.gtms.plugin.etrali.web.EtradealWebConfig.doGet(EtradealWebConfig.java: 98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.jivesoftware.openfire.container.PluginServlet.handleServlet(PluginServlet.j ava:251)
at org.jivesoftware.openfire.container.PluginServlet.service(PluginServlet.java:91 )
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.ja va:1093)
at org.jivesoftware.admin.PluginFilter.doFilter(PluginFilter.java:70)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.ja va:1084)
at org.jivesoftware.admin.AuthCheckFilter.doFilter(AuthCheckFilter.java:146)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.ja va:1084)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:11 8)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.ja va:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollect ion.java:206)
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:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.j ava:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.ClassNotFoundException: com.etrali.sdk.jwsdp.security.SecurityEnvironmentHandler
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:375 )
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337 )
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.xml.xwss.SecurityConfiguration.(SecurityConfiguration.java:79)
… 37 more

If however I stick the jars in Openfire\lib everything works fine.

Am I missing some kind of obvious way to get this working with the jars inside the plugin lib rather than inside the Openfire lib?

Figured it out. Basically two issues.

  1. Openfire by default uses JVM 1.6 u3 which predates JAX 2.1 (uses JAX 2.0) so two choices stick javaee.jar in jre/lib/endorsed (fun) or use standalone Openfire with a newer JVM.

  2. ClassLoader fun. The thread class loader for my servlet has the following in its classpath:

ClassLoader loader = Thread.currentThread().getContextClassLoader();

loader url: ‘file:/C:/Program%20Files/openfire/plugins/admin/webapp/WEB-INF/lib/admin-jsp.j ar’

loader url: ‘file:/C:/Program%20Files/openfire/plugins/admin/webapp/WEB-INF/lib/commons-fil eupload.jar’

loader url: ‘file:/C:/Program%20Files/openfire/plugins/admin/webapp/WEB-INF/lib/commons-io. jar’

loader url: ‘file:/C:/Program%20Files/openfire/plugins/admin/webapp/WEB-INF/lib/dwr.jar’

However the plugin classloader has the libraries I want:

ClassLoader loader2 = EtradealWebConfig.class.getClassLoader();

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/classes/’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/web/’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/activation-1.1.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/etrali-websvc-1.0.5a.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/gtmsutil-1.0.8a.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/jms-1.1.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/jmxri-1.2.1.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/jmxtools-1.2.1.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/log4j-1.2.15.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/mail-1.4.jar’

loader2 url: ‘file:/C:/Program Files/openfire/plugins/etrali/lib/webservices-rt-1.0.jar’

So using the solution provided at the link below (thanks Martin) I simply changed the class loader for the thread to the plugin class loader, called my method and then changed it back.

http://www.igniterealtime.org/community/thread/32772