powered by Jive Software

How to access a servlet from a plugin?

Hi all,

I’m developing a plugin to allow a fast registration by the usage of QR-Code and for that i need to use 2 servlets inside the plugin.

I followed the plugin tuturial and load my necessary servlets:

web-custom.xml

<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app>
    <servlet>
        <servlet-name>MainPage</servlet-name>
        <servlet-class>org.jivesoftware.openfire.plugin.qrserver.MainPage</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Register</servlet-name>
        <servlet-class>org.jivesoftware.openfire.plugin.qrserver.Register</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Logout</servlet-name>
        <servlet-class>org.jivesoftware.openfire.plugin.qrserver.Logout</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MainPage</servlet-name>
        <url-pattern>/MainPage</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Register</servlet-name>
        <url-pattern>/Register</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Logout</servlet-name>
        <url-pattern>/Logout</url-pattern>
    </servlet-mapping>
</web-app>

The plugin compile without erros and load on openfire without any problem, however i can not access this servlets… any help ? Should i init the servlet in a special way ? or should i make a special call on qregistrationplugin.java (plugin src file) about the servlets ?

Your servlets can only be accessed with the admin web console via plugin.xml

<item id=“my-plugin” name=“My Plugin Admin”

url=“my-plugin-admin.jsp”

description=“Click to administer settings for my plugin” />

If you want a web service, you should create one in your plugin using the http-bind port. See code from Jappix plugin

package com.ifsoft.jappix;

import org.jivesoftware.openfire.container.Plugin;

import org.jivesoftware.openfire.container.PluginManager;

import org.jivesoftware.util.*;

import org.jivesoftware.openfire.http.HttpBindManager;

import java.util.*;

import java.io.File;

// uncomment for openfire 3.6.4

//import org.mortbay.jetty.handler.ContextHandlerCollection;

//import org.mortbay.jetty.webapp.WebAppContext;

// uncomment for openfire 3.7.0

import org.eclipse.jetty.server.handler.ContextHandlerCollection;

import org.eclipse.jetty.webapp.WebAppContext;

public class JappixPlugin implements Plugin, JappixConstants {

private static final String NAME = “jappix”;

private static final String DESCRIPTION = “Jappix Plugin for Openfire”;

private PluginManager manager;

private File pluginDirectory;

//-------------------------------------------------------

//

//

//

//-------------------------------------------------------

public void initializePlugin(PluginManager manager, File pluginDirectory) {

Log.info( “[”+ NAME + “] initialize " + NAME + " plugin resources”);

try {

ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();

try {

** WebAppContext context = new WebAppContext(contexts, pluginDirectory.getPath(), “/” + JiveGlobals.getProperty(“jappix.webapp”, NAME));**

** context.setWelcomeFiles(new String[]{“index.php”});**

** }**

catch(Exception e) {

}

}

catch (Exception e) {

Log.error(“Error initializing Jappix Plugin”, e);

}

}

public void destroyPlugin() {

Log.info( “[”+ NAME + “] destroy " + NAME + " plugin resources”);

try {

}

catch (Exception e) {

Log.error("["+ NAME + "] destroyPlugin exception " + e);

}

}

public String getName() {

return NAME;

}

public String getDescription() {

return DESCRIPTION;

}

}

Thanks for the answer.

It’s strange i have been looking on presence plugin and register plugin and they allow the usage of servlets or jsp for non admin users. For example the register gives a registration page and the presence allows online user status verification.

Presence plugin configures the servlet on this web-custom.xml and later access it from a http link… this is exactly what i wish to do but i’m faling

The Presence plugin uses an exclusion to allow un-aunthenticated access

// Exclude this servlet from requering the user to login

AuthCheckFilter.addExclude(“presence/status”);

1 Like

i did that too but i still cant access my the servlet :confused:

You need to provide more information about " i still cant access my the servlet"

What error message? Any log messages? screenshot??

I compile the plugin without any error. After load it i can access the admin module and a sign-up jsp (qreg-up.jsp) page that i did for the registration however i cant access the servlet…

When i try to access the servlet nothing happens…

i dont know if i need to make any special call on the plugin file… or what are the necessary steps to make it accessable.

For now i have configured the web-custom.xml.

my structure is /openfire/src/plugins/qregistration/src/java/org/jivesoftware/openfire/plugin/q rserver/ with the servlet MainPage.java there.

On /openfire/src/plugins/qregistration/src/java/org/jivesoftware/openfire/plugin/ i have the servlet java file (qregistrationplugin.java) with this initialize:

public void initializePlugin(PluginManager manager, File pluginDirectory) {
        AuthCheckFilter.addExclude("qregistration/qreg-up.jsp");
        AuthCheckFilter.addExclude("qregistration/MainPage");
}

when deployed i can access the qreg-up.jsp via: http://server.com:9090/plugins/qregistration/qreg-up.jsp however i can’t access

http://server.com:9090/plugins/qregistration/MainPage.

I belive that i’m missing an essential step to enable the servlet.

I presume you know that JSP pages MUST be pre-compiled into Java classes and you should also create a servlet and servlet-mapping in your plugin web.xml.

Check the log files and the web.xml file again. There is a clue in there some where

1 Like