Fork me on GitHub


Deploy Jersey in the Openfire plugin

Let's say, the original method to access the openfire service by http is by HttpServlet (ex. presence plugin). So, how to replace it with Jersey for convenient development? In this post, I will detail the steps and the problems I met during achieving this.

The main reference is here. Assuming that you have successfully run a self-made plugin.

Step1. Modify the web-custom.xml

The web-custom.xml tells the container where to search for resource class. From that reference. There is some tricks in the web-custom.xml processing in openfire. So we need a wrapper, and finding the true resource class package there. As below. The class in the <servlet-class> tag is your wrapper class, the path in <url-pattern> is the base url you want.

<!-- Servlets -->

<!-- Servlet mappings -->

Step2. Tell Wrapper where to find resource class

The trick in the wrapper class is to find resouce class by PackagesResourceConfig. Below sample is referenced from that link.

The resouce class should be under the same package (or inner) as the wrapper class.

AuthCheckFilter.addExclude(SERVLET_URL); is used for avoiding the need of login to access the api.

public class BrownyServletWrapper extends ServletContainer {

    private static final long serialVersionUID = 1L;
    private static final String SERVLET_URL = "browny/test/*";
    private static final String SCAN_PACKAGE_KEY = "";
    private static final String SCAN_PACKAGE_DEFAULT = BrownyServletWrapper.class

    private static final String RESOURCE_CONFIG_CLASS_KEY = "";
    private static final String RESOURCE_CONFIG_CLASS = "com.sun.jersey.api.core.PackagesResourceConfig";

    private static Map<String, Object> config;
    private static PackagesResourceConfig prc;

    static {
        config = new HashMap<String, Object>();
        prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT);

    public BrownyServletWrapper() {

    public void init(ServletConfig servletConfig) throws ServletException {

        // Exclude this servlet from requering the user to login

    public void destroy() {
        // Release the excluded URL

Step3. The Jersey dependent jar library

They are asm-3.3.1.jar, jersey-bundle-1.10-b01.jar, jersey-servlet-1.17.1.jar, jsr311-api-1.1.1.jar. If wrong dependency, the ClassNotFoundException, ClassNotDefException will happen (you could find the error from openfire_src/target/openfire/logs/error.log)

Step4. The Resource class

The trick here is the @Path() should starts from plugin name, later servlet url-pattern and at the end - path of the your resouce. So that is @Path("browny/test/hello")

package com.brownylin.openfire.plugin.browny;


public class BrownyResources {

    public Response getMsg() {

        String output = "Jersey say Hello";
        return Response.status(200).entity(output).build();


Step5. Don't want result shown in openfire admin console

As this thread said. The default configuration is to capture all text/html content from the server and force it into the admin page.

You could add the url pattern you want to exclude in openfire_src/src/web/WEB-INF/decorators.xml as below

<decorators defaultdir="/decorators">
    <decorator name="setup" page="setup.jsp">
    <decorator name="main" page="main.jsp">
    <decorator name="none"/>

Step6. Test the resource url

Last, test the url localhost:9090/plugins/browny/test/hello. It's done. Hope this will be useful to someone :)

-- EOF --

1 comment:

  1. This comment has been removed by the author.