Thursday, July 31, 2008

Use Plugin Classpath with Openfire Plugin

When creating an Openfire plugin, some classes cannot be found by the default classpath. This is a result of the way that Openfire loads plugins and their jars into the classpath. For me, specifically, I got a ClassNotFoundException when trying to create an IntialContext with WLIntialContextFactory, even though the weblogic.jar was in my plugin lib folder. One solution is to move everything from the plugin/lib folder into openfire/lib. But this is messy at best.

Luckily, I found a solution from someone trying to use
GWT in an Openfire Plugin.

First, set a PluginClassLoader on your Plugin class. Here is my trimmed example:

...
private PluginClassLoader pluginClassLoader = null;
...
public void initializePlugin(PluginManager pManager, File pluginDirectory) {
pluginClassLoader = pManager.getPluginClassloader(this);
}
...
public PluginClassLoader getPluginClassLoader() {
return pluginClassLoader;
}


Then, in my class that attempts to load a Context, before loading it I do this:

MyPlugin myPlugin = (MyPlugin) XMPPServer.getInstance()
.getPluginManager().getPlugin("myplugin");
if (myPlugin != null && myPlugin.getPluginClassLoader() != null) {
Thread.currentThread().setContextClassLoader(
myPlugin.getPluginClassLoader().getClassLoader());
}

Wednesday, July 30, 2008

Enum Serialization with Weblogic EJB Client

I was trying to setup an ejb client to connect to an ejb running on a Weblogic 9 app server. I could connect fine, but kept getting a Mismatched serialization uids error on a Java 5 Enum class. After some digging I found
a fix on JavaRanch. For whatever reason using the wlclient.jar will not work when serializing enums, but using the full blown weblogic.jar is fine. I'm going to ignore the details on this one and just move along, but maybe someone else understands the problem/workaround/fix better?

Tuesday, July 22, 2008

Custom servlet in Openfire plugin

I've been working on creating a plugin for our Openfire server, which is currently on version 3.3.3. The Plugin developer guide is a little help, and so are the message boards, but there is still some detail missing.

Situation: I want to have a custom servlet that is available on the same url:port as our admin server. I don't want to have to login to the admin server to reach this url, and the output from this servlet should not be wrapped by the openfire sitemesh template.

First, I registered the servlet in a web-custom.xml, but I could not get my servlet to appear. I had a url like http://localhost:9090/plugins/myplugin/CustomServlet. I couldn't find an answer on the message boards so I pulled down the source and started debugging. Turns out that the PluginServlet class does a toLower on the servlet url. So changing the url pattern from /CustomServlet to /customservlet in the web-custom.xml fixed the problem.

Next, to remove the security for hitting the servlet, I used the information from this post. Adding AuthCheckFilter.addExclude("CustomServlet") to the initializePlugin method fixed it up.

Lastly, as mentioned here and here, adding <meta name='decorator' content='none'/> tells sitemesh to not use the normal openfire template.

Hopefully this info will help me remember this stuff down the line...