GenericServlet support

Hi devs,

do you mind changing the references in PluginServlet.java from HttpServlet to GenericServlet?

It’'s a 5min change and all HttpServlets should be fine with this change but in addition you can also use servlets which allows arbitrary protocols. E.g. webservices which are based on the hessianservlet from caucho.

Thanks,

Markus

OK, not much response. Maybe my initial post was misleading. I don’'t want the PluginServlet to be a GenericServlet but the servlets map of type GenericServlet. See the advantages in the earlier post. This is a patch against version 2700

Markus

Index: PluginServlet.java

===================================================================

— PluginServlet.java (revision 2718)

+++ PluginServlet.java (working copy)

@@ -21,6 +21,7 @@

import org.jivesoftware.util.StringUtils;

import org.xml.sax.SAXException;

+import javax.servlet.GenericServlet;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletOutputStream;

@@ -54,12 +55,12 @@

*/

public class PluginServlet extends HttpServlet {

  • private static Map<String, HttpServlet> servlets;
  • private static Map<String, GenericServlet> servlets;

private static PluginManager pluginManager;

private static ServletConfig servletConfig;

static {

  •    servlets = new ConcurrentHashMap<String, HttpServlet>();
    
  •    servlets = new ConcurrentHashMap<String, GenericServlet>();
    

}

public void init(ServletConfig config) throws ServletException {

@@ -156,10 +157,10 @@

// Register the servlet for the URL.

Class servletClass = classMap.get(name);

Object instance = servletClass.newInstance();

  •            if (instance instanceof HttpServlet) {
    
  •            if (instance instanceof GenericServlet) {
    

// Initialize the servlet then add it to the map…

  •                ((HttpServlet)instance).init(servletConfig);
    
  •                servlets.put(pluginName + url, (HttpServlet)instance);
    
  •                ((GenericServlet)instance).init(servletConfig);
    
  •                servlets.put(pluginName + url, (GenericServlet)instance);
    

}

else {

Log.warn("Could not load " + (pluginName + url) + “: not a servlet.”);

@@ -197,7 +198,7 @@

Element nameElement = (Element)names.get(i);

String url = nameElement.element(“url-pattern”).getTextTrim();

// Destroy the servlet than remove from servlets map.

  •            HttpServlet servlet = servlets.get(pluginName + url);
    
  •            GenericServlet servlet = servlets.get(pluginName + url);
    

servlet.destroy();

servlets.remove(pluginName + url);

servlet = null;

@@ -226,8 +227,8 @@

String jspURL = pathInfo.substring(1);

  •    HttpServlet servlet = servlets.get(jspURL);
    
  •    if (servlet != null) {
    
  •    GenericServlet servlet = servlets.get(jspURL);
    
  •    if (servlet != null && servlet instanceof HttpServlet) {
    

servlet.service(request, response);

return;

}

@@ -250,7 +251,7 @@

private void handleServlet(String pathInfo, HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

// Strip the starting “/” from the path to find the JSP URL.

  •    HttpServlet servlet = getServlet(pathInfo);
    
  •    GenericServlet servlet = getServlet(pathInfo);
    

if (servlet != null) {

servlet.service(request, response);

return;

@@ -267,10 +268,10 @@

  • @param pathInfo the pathinfo to map to the servlet.

  • @return the mapped servlet, or null if no servlet was found.

*/

  • private HttpServlet getServlet(String pathInfo) {
  • private GenericServlet getServlet(String pathInfo) {

pathInfo = pathInfo.substring(1).toLowerCase();

  •    HttpServlet servlet = servlets.get(pathInfo);
    
  •    GenericServlet servlet = servlets.get(pathInfo);
    

if (servlet == null) {

for (String key : servlets.keySet()) {

int index = key.indexOf("/*");

@@ -471,4 +472,4 @@

return builder.toString();

}

-}

\ No newline at end of file

+}

Sorry for the late reply. That makes sense to me, I think. Do you have a specific use case in mind already? That would help me wrap my head around the problem.

Thanks,

-Matt

There are dozens of use cases where people want to integrate jive messenger into their existing application. E.g the online presence plugin. At the moment you get a http/html response from the plugin. Nice for webpages. But if you like to process the result in your application it would be very helpful to have a servlet which acts as a webservice and allows to call a plugin via a java api. See the hessian tutorial http://www.caucho.com/resin-3.0/protocols/tutorial/hessian-add/index.xtp#A-Hessi an-Example

for an example.

It is as easy as having a servlet extending HessianServlet which itself extends GenericServlet.

This allows a plugin to be exposed as a webservice. Very cool and powerful.

Hope it is clearer now,

Markus Joschko

had the time to make an update on trunk and noticed that there is still the HTTPServlet version.

Do you plan to apply the patch?

Thanks,

Markus

hm, still not in the 2.2 head or am I missing it? Did you descide to reject this change?

I think I can’'t do more than submitting a patch … ?

Markus,

Thanks for your persistence. I filed this as JM-459 and will make sure it gets in the codebase.

Regards,

Matt

thanks matt.

I’'m looking forward to these days where I can use an unpatched jive distribution

markus

Markus,

The code is now checked in. Let me know when you get a chance to test it.

-Matt

hey thanks matt. That forced me to switch to the 2.3 branch

Yes it seems to work superb.

Thanks again,

Markus