1 25 package org.snipsnap.xmlrpc; 26 27 import org.apache.xmlrpc.AuthenticatedXmlRpcHandler; 28 import org.apache.xmlrpc.XmlRpcException; 29 30 import java.lang.reflect.Method ; 31 import java.lang.reflect.InvocationTargetException ; 32 import java.util.Vector ; 33 34 42 public abstract class AuthXmlRpcHandler implements AuthenticatedXmlRpcHandler { 43 44 protected Object target = null; 45 46 public AuthXmlRpcHandler() { 47 target = this; 48 } 49 50 public AuthXmlRpcHandler(Object target) { 51 this.target = target; 52 } 53 54 protected abstract boolean authenticate(String user, String password); 55 56 public Object execute(String method, Vector vector, String user, String password) throws Exception { 57 if (authenticate(user, password)) { 59 return execute(method, vector); 60 } else { 61 throw new XmlRpcException(0, "Username or password does not match"); 62 } 63 } 64 65 public Object execute(String methodName, Vector args) throws Exception { 66 Class argClasses[] = null; 67 if(args.size() > 0) { 68 argClasses = new Class [args.size()]; 69 for (int argNum = 0; argNum < args.size(); argNum++) { 70 argClasses[argNum] = args.get(argNum).getClass(); 71 } 72 } 73 if(methodName.indexOf('.') != -1) { 74 methodName = methodName.substring(methodName.indexOf(".")+1); 75 } 76 77 Method method = target.getClass().getMethod(methodName, argClasses); 78 try { 79 return method.invoke(target, (args.size() > 0 ? args.toArray() : null)); 80 } catch (InvocationTargetException e) { 81 throw (Exception )e.getTargetException(); 82 } 83 } 84 } 85 | Popular Tags |