radioAe6rt

Init hooks into Apache XML-RPC3 user handlers

leave a comment »

Here are some lite mods to the Apache XML-RPC v3 code that allow you to take explicit control of initializing your user handlers when used inside a Java servlet.

In this new scheme, a handler artifact declared in XmlRpcServlet.properties

artifact=mypackage.Handler

must implement the (new, proposed) UserHandler interface

package org.apache.xmlrpc.server;

import javax.servlet.http.HttpServlet;

public interface UserHandler {
   public void init(HttpServlet s);
}

In your servlet init() method, we acquire the reference to the handler and allow it to do whatever configuration it should do before requests are made of it.

public class MyServlet extends XmlRpcServlet {
   ...
   public void init() {
      // put useful stuff in ServletContext here...
      // then init the handler
      getUserHandler("artifact").init(this);
      ...
   }
   ...
}
 

Without the init hooks, and because the Handler is instantiated within the parent class servlet constructor, you have no way of preparing the handler in a special way before the servlet begins taking requests.

The model I’ve hinted at here suggests that prior to calling init() on the user handler, you have put useful things in the servlet context for handler.init()’s consumption and use. Acquiring inherited Log4J logger instances and DataSource instances come to mind.

There may be a good way to do what my mods do — without the mods — but I couldn’t immediately see it.

[tags]xmlrpc,xmlrpcservlet,servlet[/tags]

Written by radioae6rt

April 30, 2006 at 6:37 am

Posted in Internet

Leave a Reply