ws-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Danny Yoo <d...@acoma.Stanford.EDU>
Subject Re: Access Response object in Handler?
Date Wed, 20 Nov 2002 18:24:55 GMT
On Wed, 20 Nov 2002, Twan Kogels wrote:

> I've got a problem and can't seem to find the answer. I've made a
> midp(j2me) client which communicates with a xml-rpc server (in java, as
> servlet). No problem here.
>
> A clients wants to login, easy peasy, check the username en password in a
> methode "doLogin" in class "Login". Add a handler and ready. Works perfect,
> doLogin() gets executed when a xml-rpc message comes in.
>
> But now i want to return the url of the servlet in the doLogin() methode.
> When i'm in the servlet doPost methode it's easy:
> String sessionURL = response.encodeURL(request.getRequestURL().toString());
> But now i'm in the handler in the "doLogin()" method. I can't see how i can
> access the Response object.
>
> I can't pass it in the constructor when i add the handlers, cause the
> Response object is not available in the init() methode of servlet. I also
> can't seem to pass a extra parameter to the execute() methode.
>
> I'm quite stuck. Can anybody offer me a helping hand?

I'm run into a similar problem, where the AuthenticatedXmlRpcHandler
interface just isn't rich enough; it only allows us to pass String names
and passwords to our handlers.  I often want to pass in a session object
so that I can take advantage of the session state mechanisms in my
servlets.



The main problem is that the AuthenticatedXmlRpcHandler has too weak of an
interface: it takes in a String for the username and a String for the
password.  I've refactored AuthenticatedXmlRpcHandler, and created a
parameter object called "AuthenticationObject" to bundle the 'user' and
'password' strings into a single object:


//////
// AuthenticationObject.java
package org.apache.xmlrpc;

public interface AuthenticationObject {
    String getUser();
    String getPassword();
}
//////


I then munged up org.apache.xmlrpc.XmlRpcServer so that it passes
AuthenticationObject instances rather than those plain strings:



// Within XmlRpcServer
    /**
     * Parse the request and execute the handler method, if one is
     * found. If the invoked handler is AuthenticatedXmlRpcHandler,
     * use the credentials to authenticate the user.
     */
    public byte[] execute(InputStream is,
			  final String user, final String password)
    {
	return execute(is, new AuthenticationObject() {
		public String getUser() { return user; }
		public String getPassword() { return password; }
	    });
    }


    /**
     * Parse the request and execute the handler method, if one is
     * found. If the invoked handler is AuthenticatedXmlRpcHandler,
     * use the credentials to authenticate the user.
     */
    public byte[] execute(InputStream is, AuthenticationObject obj) {
        Worker worker = getWorker();
        byte[] retval = worker.execute(is, obj);
        pool.push(worker);
        return retval;
    }



// ... later in the code...


		if (handler instanceof AuthenticationObjectXmlRpcHandler)
{
                    outParam =((AuthenticationObjectXmlRpcHandler)
handler).
			execute(methodName, inParams, auth);
		}
		else if (handler instanceof AuthenticatedXmlRpcHandler)
                {
                    outParam =((AuthenticatedXmlRpcHandler) handler).
                            execute(methodName, inParams,
				    auth.getUser(), auth.getPassword());
                }
                else
                {
                    outParam =((XmlRpcHandler) handler).execute(
                            methodName, inParams);
                }





There are a few more source code changes I've had to make to maintain
compatibility with the old interface.  I'd love to send this as a diff,
but don't know who to submit my patches to.  Does anyone have suggestions?



Thanks again!


Mime
View raw message