powered by Jive Software

When I restart Openfire my plugin's output is the contents of Admin console login page

Hello all,

I have created a roster plugin that will return a users roster in xml format.

I make a call to the servlet passing a jid and the servlet makes a call to the Roster_Plugin that will return a XML String.

I have the plugin itself, a servlet and a class file.

If I restart Openfire, my plugin breaks and will return the openfire login page.

I cannot get my plugin to run again unless I uninstall and reinstall plugin.

Here is the code of my Plugin:

//imports removed for brevity /** * Roster plugin for Openfire. */
public class Roster_Plugin implements Plugin
{     private static String AVAILABLE = "icon-im_available";
    private static String OFFLINE   = "icon-im_unavailable";
    private static String AWAY      = "icon-im_away";
    private static String DND       = "icon-im_dnd";
    private static String XA        = "icon-im_xa";
       XMPPServer server;
    UserManager userManager;
    PresenceManager presenceManager;
       public void initializePlugin(PluginManager manager, File pluginDirectory)
    {
        server          = XMPPServer.getInstance();
        userManager     = server.getUserManager();
        presenceManager = server.getPresenceManager();
        Log.info("Creating RosterPlugin");
    }     public void destroyPlugin()
    {
        server          = null;
        userManager     = null;
        presenceManager = null;
        Log.info("Destroying Rosterplugin");
    }     //Returns an XML string of a users roster called from servlet.
    public String getRoster(String _userName) {
        Roster roster = null;
        HashMap<String, ArrayList> hashMap = new HashMap<String, ArrayList>();
        ArrayList<User> arrayList = new ArrayList<User>();
        String userName = _userName;//We want this persons roster
        StringBuffer rosterBuffer = new StringBuffer();//StringBuffer to hold the roster string.
        try {
            User u            = userManager.getUser(userName);
            roster            = u.getRoster();
            User user         = null;//User object needed to attain Presence.
            List<RosterItem> rosterItems = new ArrayList<RosterItem>(roster.getRosterItems());
            Collections.sort(rosterItems, new RosterItemComparator());
            for (RosterItem rosterItem : rosterItems) {
                List<String> group = rosterItem.getGroups();
                user = userManager.getUser(rosterItem.getJid().toString());
                for(String groupString : group) {
                   if(groupString != null) {
                        if(!hashMap.containsKey(groupString)) {
                            arrayList = new ArrayList<User>();
                            arrayList.add(user);
                            hashMap.put(groupString, arrayList);
                        }
                        else if(hashMap.containsKey(groupString)) {
                            arrayList = hashMap.get(groupString);
                            arrayList.add(user);
                            hashMap.put(groupString, arrayList);
                        }
                        else {
                        }
                   }
                   else {//TODO;                                         }
                }
            }
            rosterBuffer.append(this.parseHashList(hashMap, user).toString());
        }
        catch(UserNotFoundException unfe){Log.error("USER NOT FOUND:" + unfe.getMessage());}
        return rosterBuffer.toString();
    }

Here is my servlet code:

public class RosterServlet extends HttpServlet {
        private Roster_Plugin plugin;
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
                plugin = (Roster_Plugin) XMPPServer.getInstance().getPluginManager().getPlugin("rosterplugin");
        AuthCheckFilter.addExclude("rosterplugin");
        String userName = request.getParameter("username");
        String roster   = plugin.getRoster(userName.trim());
        response.setContentType("text/xml;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println(roster);
        out.close();
    }
}

It seems like the plugin loses the AuthCheckFilter on restart and never gets it back.

I get no error messages in admin log and I have it on debug.

Any Ideas?

My jar file directory structure is as follows:

classes --> com --> myorg --> Roster_Plugin.class and RosterServlet.class

META-INF --> Manifest.mf

web> WEB-INF> web-custom.xml

plugin.xml

OK,

I dont need to redeploy the plugin on restart.

If I access my servlet using http://localhost:9090/plugins/rosterplugin/roster?username=gforty

I get prompted to login to the admin console.

If I login, I get the expected roster XML string for username gforty.

Now if I access the servlet again with a different username, I also get the expected roster XML string.

Now if I go to a different machine or browser and access the servlet, I am once again prompted to login if I just restarted Openfire.

It is almost like the AuthCheckFilter is not initialized until I access the servlet 1 time through the login page.

Well I fixed this problem…dont know that this fix is good coding practices but here is what I did.

In the initializePlugin method, I added the Filter exclude.

In the destroyPlugin method I removed Filter exclude.

Dont know why this fixed my problem since the AuthCheckFilter implements Servlet Filter.

If anyone wants to shed some light on this please do.

public void initializePlugin(PluginManager manager, File pluginDirectory)

{

server = XMPPServer.getInstance();

userManager = server.getUserManager();

presenceManager = server.getPresenceManager();

//This resolved the problem with the redirect to login page.

AuthCheckFilter.addExclude("/roster");

Log.info(“Creating RosterPlugin”);

}

public void destroyPlugin()

{

server = null;

userManager = null;

presenceManager = null;

AuthCheckFilter.removeExclude("/roster");

Log.info(“Destroying Rosterplugin”);

}

/code

Thanks for looking.

.