OK, thanks. So I had a look and now I changed my code to use it. The result
is

      XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
      PropertyHandlerMapping phm = new PropertyHandlerMapping();
      phm.setRequestProcessorFactoryFactory(new
FooRequestProcessFactoryFactory(new Foo()));
      phm.addHandler(Foo.class.getName(), FooImpl.class);
      xmlRpcServer.setHandlerMapping(phm);

and

public class FooRequestProcessFactoryFactory implements
RequestProcessorFactoryFactory {
  private final RequestProcessorFactory factory = new
FooRequestProcessorFactory();
  private final Foo foo;

  public FooRequestProcessFactoryFactory(Foo foo) {
    this.foo = foo;
  }

  public RequestProcessorFactory getRequestProcessorFactory(Class aClass)
throws XmlRpcException {
    return factory;
  }

  private class FooRequestProcessorFactory implements
RequestProcessorFactory {
    public Object getRequestProcessor(XmlRpcRequest xmlRpcRequest) throws
XmlRpcException {
      return foo;
    }
  }
}

So it really simplified my implementation a lot, and handles reflection over
more complex parameter types with the default implementation better etc. I
guess I will still add some better handling of different classes into that
but that is quite simple. Thanks.

Maybe it could be useful to include this option in the documentation? or is
it somewhere in there already?


2010/2/12 Jochen Wiedmann <jochen.wiedm...@gmail.com>

> Have a look at the
>
>    RequestProcessorFactoryFactory
>
>
>
> On Fri, Feb 12, 2010 at 4:08 PM, teemu kanstren <tkanst...@gmail.com>
> wrote:
> > Hello all,
> >
> >  As I understand, each time a server receives an xmlrpc invocation a new
> > object is created for the class registered to handle this. I do not wish
> to
> > have this happen as it produces problems for me to map the invocations to
> > any non-static objects especially if I have more than one xml-rpc server.
> > From browsing some discussion earlier this month on the mailing list I
> > gather that there is not much control provided in apache xmlrpc over this
> > behaviour. In any case, I managed to hack something that seems to work
> and
> > this is how I managed to address the issue, maybe it is of some help to
> > anyone else who needs something similar..
> >
> > when starting the xmlrpc server I need to register a handler mapping that
> is
> > used to find the classes to create and the methods to invoke:
> >
> > xmlRpcServer.setHandlerMapping(mapping);
> >
> > to have some control over object creation I then use my own handler
> mapping
> > like this
> >
> > public class XmlRpcFooHandlerMapping implements XmlRpcHandlerMapping {
> >  //this is set in the constructor and gets as a parameter the non-static
> > object I wish to use..
> >  private final XmlRpcFooHandler handler;
> >
> >  public XmlRpcFooHandlerMapping(XmlRpcFooHandler handler) {
> >    this.handler = handler;
> >  }
> >
> >  public XmlRpcHandler getHandler(String name) throws
> > XmlRpcNoSuchHandlerException, XmlRpcException {
> >    //.. here some simple checks on the name like it contains "Foo"..
> >    return handler;
> >  }
> > }
> >
> > and the handler..
> >
> > public class XmlRpcFooHandler implements XmlRpcHandler {
> >  //set this in the constructor and use in any way you like, it should be
> > the same obejct for all invocations..
> >  private final Foo foo;
> >
> >  public XmlRpcFooHandler(Foo foo) {
> >    this.foo = foo;
> >  }
> >
> > //here I inspire from the default implementation and use the
> TypeConverter
> > class to conver the parameters..
> > //since I know exactly the class (Foo.class) I wish to use, I can do lots
> of
> > shortcuts such as expect method matching with just method names to be
> > enough...
> > }
> >
> > So thats it.. I hope it helps someone.
> >
> >  If someone can suggest something more elegant, point out some flaws in
> it
> > or whatever I am happy to hear..
> >
> > Teemu
> >
>
>
>
> --
> Germanys national anthem is the most boring in the world - how telling!
>

Reply via email to