User: cgjung  
  Date: 02/02/04 01:38:58

  Modified:    jboss.net/src/main/org/jboss/net/axis
                        AxisInvocationHandler.java
  Log:
  Adapted to latest deployment changes. Compiles, but does not yet run yet.
  
  Revision  Changes    Path
  1.6       +221 -163  
contrib/jboss.net/src/main/org/jboss/net/axis/AxisInvocationHandler.java
  
  Index: AxisInvocationHandler.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/AxisInvocationHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AxisInvocationHandler.java        2001/10/16 15:52:48     1.5
  +++ AxisInvocationHandler.java        2002/02/04 09:38:58     1.6
  @@ -1,17 +1,18 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   
  -// $Id: AxisInvocationHandler.java,v 1.5 2001/10/16 15:52:48 cgjung Exp $
  +// $Id: AxisInvocationHandler.java,v 1.6 2002/02/04 09:38:58 cgjung Exp $
   
   package org.jboss.net.axis;
   
   import org.apache.axis.client.ServiceClient;
   import org.apache.axis.AxisEngine;
   import org.apache.axis.AxisFault;
  +import org.apache.axis.MessageContext;
   
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
  @@ -22,169 +23,226 @@
   import java.net.URL;
   
   /**
  - * An invocation handler that allows typed client access to
  + * An invocation handler that allows typed and persistent client access to
    * remote SOAP/Axis services. Adds method/interface to name resolution
  - * to the axis engine.
  + * to the axis client engine.
    *
    * @created  1. Oktober 2001, 09:29
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
  + *   Change notes:
  + *   <ul>
  + *     <li> 17.12.01: CGJ, Added overtaking of basic authentication data from
  + *          target url
  + *     <li>
  + *   </ul>
    */
  +
  +public class AxisInvocationHandler implements InvocationHandler
  +{
   
  -public class AxisInvocationHandler implements InvocationHandler {
  -    
  -    /** mapping of methods to interface names */
  -    final protected Map methodToInterface;
  -    /** mapping of methods to method names */
  -    final protected Map methodToName;
  -    /** the "session" management underneath */
  -    final protected ServiceClient serviceClient;
  -    
  -    /** Creates new AxisInvocationHandler */
  -    public AxisInvocationHandler(ServiceClient client, Map methodMap, Map 
interfaceMap) {
  -        this.serviceClient=client;
  -        this.methodToInterface=interfaceMap;
  -        this.methodToName=methodMap;
  -        // we set maintain session for this to true
  -        // probably we should make this a configurable
  -        // parameter and more probably we should
  -        // have a hook for finalizing the session
  -        // explicitely and implicitely by the gc!
  -        serviceClient.setMaintainSession(true);
  -    }
  -
  -    /** Creates new AxisInvocationHandler */
  -    public AxisInvocationHandler(ServiceClient client, Map methodMap) {
  -        this(client,methodMap,new DefaultInterfaceMap());
  -    }
  -    
  -    /** Creates new AxisInvocationHandler */
  -    public AxisInvocationHandler(ServiceClient client) {
  -        this(client,new DefaultMethodMap());
  -    }
  -    
  -    /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  -    public AxisInvocationHandler(URL endpoint, AxisEngine engine, Map methodMap, 
Map interfaceMap) throws AxisFault {
  -        this(new ServiceClient(endpoint.toString(),engine),methodMap,interfaceMap);
  -    }
  -
  -    /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  -    public AxisInvocationHandler(URL endpoint, AxisEngine engine, Map methodMap) 
throws AxisFault {
  -        this(endpoint,engine,methodMap, new DefaultInterfaceMap());
  -    }
  -
  -    /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  -    public AxisInvocationHandler(URL endpoint, AxisEngine engine) throws AxisFault {
  -        this(endpoint,engine,new DefaultMethodMap());
  -    }
  -
  -    /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  -    public AxisInvocationHandler(URL endpoint, Map methodMap, Map interfaceMap) 
throws AxisFault {
  -        this(new ServiceClient(endpoint.toString()),methodMap,interfaceMap);
  -    }
  -
  -    /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  -    public AxisInvocationHandler(URL endpoint, Map methodMap) throws AxisFault {
  -        this(endpoint,methodMap,new DefaultInterfaceMap());
  -    }
  -
  -    /** Creates new AxisInvocationHandler pointing to a given url */
  -    public AxisInvocationHandler(URL endpoint) throws AxisFault {
  -        this(endpoint,new DefaultMethodMap());
  -    }
  -   
  -    /** invoke given namespace+method+args */
  -    public Object invoke(String serviceName, String methodName, Object[] args) 
throws AxisFault {
  -        return serviceClient.invoke(serviceName,methodName,args);
  -    }
  -
  -    /** invoke with additional method parameter signature */
  -    public Object invoke(String serviceName, String methodName, Object[] args, 
Class[] parameters) throws AxisFault {
  -        // classes are normally ignored
  -        return invoke(serviceName,methodName,args);
  -    }
  -       
  -    /** generic invocation method */
  -    public java.lang.Object invoke(java.lang.Object target, 
  -            java.lang.reflect.Method method, java.lang.Object[] args) 
  -                throws java.lang.Throwable {
  -            return invoke((String) methodToInterface.get(method),
  -                (String) methodToName.get(method), args,method.getParameterTypes());
  -    }
  -    
  -    /** default creation of service */
  -    public static Object createAxisService(Class _interface, URL endpoint) throws 
AxisFault {
  -        return createAxisService(_interface,new AxisInvocationHandler(endpoint));
  -    }
  -
  -    /** default creation of service */
  -    public static Object createAxisService(Class _interface, URL endpoint, 
AxisEngine engine) throws AxisFault {
  -        return createAxisService(_interface,new 
AxisInvocationHandler(endpoint,engine));
  -    }
  -
  -    /** default creation of service */
  -    public static Object createAxisService(Class _interface, AxisInvocationHandler 
handler) throws AxisFault {
  -        return Proxy.newProxyInstance(_interface.getClassLoader(),new Class[] 
{_interface},handler);
  -    }
  -
  -    /** 
  -     * a tiny helper that does some default mapping of methods to interface names
  -     */
  -    
  -    public static class DefaultInterfaceMap extends HashMap {
  -       
  -        /** no entries is the default */
  -        public DefaultInterfaceMap() {
  -            super(0);
  -        }
  -        
  -        /** returns default interface if no mapping of method/interface is defined 
*/
  -        public Object get(Object key) {
  -    
  -            // first try a direct lookup
  -            Object result=super.get(key);
  -            
  -            if(result==null && key instanceof Method) {
  -                // if that is unsuccessful, we try to
  -                // lookup the class/interface itself
  -                result=super.get(((Method) key).getDeclaringClass());
  -                
  -                // if that is not specified, we simply extract the
  -                // un-qualified classname
  -                if(result==null) {
  -                    String sresult=((Method) key).getDeclaringClass().getName();
  -                    if(sresult.indexOf(".")!=-1)
  -                        sresult=sresult.substring(sresult.lastIndexOf(".")+1);
  -                    result=sresult;
  -                }
  +   /** mapping of methods to interface names */
  +   final protected Map methodToInterface;
  +   /** mapping of methods to method names */
  +   final protected Map methodToName;
  +   /** the "session" management underneath */
  +   final protected ServiceClient serviceClient;
  +
  +   /** Creates new AxisInvocationHandler */
  +   public AxisInvocationHandler(ServiceClient client, Map methodMap, Map 
interfaceMap)
  +   {
  +      this.serviceClient=client;
  +      this.methodToInterface=interfaceMap;
  +      this.methodToName=methodMap;
  +      // we set maintain session for this to true
  +      // probably we should make this a configurable
  +      // parameter and more probably we should
  +      // have a hook for finalizing the session
  +      // explicitely and implicitely by the gc!
  +      serviceClient.setMaintainSession(true);
  +   }
  +
  +   /** Creates new AxisInvocationHandler */
  +   public AxisInvocationHandler(ServiceClient client, Map methodMap)
  +   {
  +      this(client,methodMap,new DefaultInterfaceMap());
  +   }
  +
  +   /** Creates new AxisInvocationHandler */
  +   public AxisInvocationHandler(ServiceClient client)
  +   {
  +      this(client,new DefaultMethodMap());
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  +   public AxisInvocationHandler(URL endpoint, AxisEngine engine, Map methodMap, Map 
interfaceMap) throws AxisFault
  +   {
  +      this(new ServiceClient(endpoint.toString(),engine),methodMap,interfaceMap);
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  +   public AxisInvocationHandler(URL endpoint, AxisEngine engine, Map methodMap) 
throws AxisFault
  +   {
  +      this(endpoint,engine,methodMap, new DefaultInterfaceMap());
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  +   public AxisInvocationHandler(URL endpoint, AxisEngine engine) throws AxisFault
  +   {
  +      this(endpoint,engine,new DefaultMethodMap());
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  +   public AxisInvocationHandler(URL endpoint, Map methodMap, Map interfaceMap) 
throws AxisFault
  +   {
  +      this(new ServiceClient(endpoint.toString()),methodMap,interfaceMap);
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url, using the given 
engine */
  +   public AxisInvocationHandler(URL endpoint, Map methodMap) throws AxisFault
  +   {
  +      this(endpoint,methodMap,new DefaultInterfaceMap());
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** Creates new AxisInvocationHandler pointing to a given url */
  +   public AxisInvocationHandler(URL endpoint) throws AxisFault
  +   {
  +      this(endpoint,new DefaultMethodMap());
  +      setBasicAuthentication(endpoint);
  +   }
  +
  +   /** helper to transfer url authentication information into engine */
  +   protected void setBasicAuthentication(URL target)
  +   {
  +      String userInfo=target.getUserInfo();
  +
  +      if(userInfo!=null)
  +      {
  +         java.util.StringTokenizer tok=new java.util.StringTokenizer(userInfo,":");
  +         if(tok.hasMoreTokens())
  +         {
  +            serviceClient.set(MessageContext.USERID,tok.nextToken());
  +            if(tok.hasMoreTokens())
  +            {
  +               serviceClient.set(MessageContext.PASSWORD,tok.nextToken());
               }
  -            
  -            return result;
  -        }
  -    } 
  -     
  -    /** 
  -     * a tiny helper that does some default mapping of methods to method names
  -     */
  -    
  -    public static class DefaultMethodMap extends HashMap {
  -       
  -        /** no entries is the default */
  -        public DefaultMethodMap() {
  -            super(0);
  -        }
  -        
  -        /** returns default interface if no mapping is defined */
  -        public Object get(Object key) {
  -            
  -            Object result=super.get(key);
  -            
  -            if(result==null && key instanceof Method) {
  -                result=((Method) key).getName();
  +         }
  +      }
  +   }
  +
  +   /** invoke given namespace+method+args */
  +   public Object invoke(String serviceName, String methodName, Object[] args) 
throws AxisFault
  +   {
  +      return serviceClient.invoke(serviceName,methodName,args);
  +   }
  +
  +   /** invoke with additional method parameter signature */
  +   public Object invoke(String serviceName, String methodName, Object[] args, 
Class[] parameters) throws AxisFault
  +   {
  +      // classes are normally ignored
  +      return invoke(serviceName,methodName,args);
  +   }
  +
  +   /** generic invocation method */
  +   public java.lang.Object invoke(java.lang.Object target,
  +   java.lang.reflect.Method method, java.lang.Object[] args)
  +   throws java.lang.Throwable
  +   {
  +      return invoke((String) methodToInterface.get(method),
  +      (String) methodToName.get(method), args,method.getParameterTypes());
  +   }
  +
  +   /** default creation of service */
  +   public static Object createAxisService(Class _interface, URL endpoint) throws 
AxisFault
  +   {
  +      return createAxisService(_interface,new AxisInvocationHandler(endpoint));
  +   }
  +
  +   /** default creation of service */
  +   public static Object createAxisService(Class _interface, URL endpoint, 
AxisEngine engine) throws AxisFault
  +   {
  +      return createAxisService(_interface,new 
AxisInvocationHandler(endpoint,engine));
  +   }
  +
  +   /** default creation of service */
  +   public static Object createAxisService(Class _interface, AxisInvocationHandler 
handler) throws AxisFault
  +   {
  +      return Proxy.newProxyInstance(_interface.getClassLoader(),new Class[]
  +      {_interface},handler);
  +   }
  +
  +   /**
  +    * a tiny helper that does some default mapping of methods to interface names
  +    */
  +
  +   public static class DefaultInterfaceMap extends HashMap
  +   {
  +
  +      /** no entries is the default */
  +      public DefaultInterfaceMap()
  +      {
  +         super(0);
  +      }
  +
  +      /** returns default interface if no mapping of method/interface is defined */
  +      public Object get(Object key)
  +      {
  +
  +         // first try a direct lookup
  +         Object result=super.get(key);
  +
  +         if(result==null && key instanceof Method)
  +         {
  +            // if that is unsuccessful, we try to
  +            // lookup the class/interface itself
  +            result=super.get(((Method) key).getDeclaringClass());
  +
  +            // if that is not specified, we simply extract the
  +            // un-qualified classname
  +            if(result==null)
  +            {
  +               String sresult=((Method) key).getDeclaringClass().getName();
  +               if(sresult.indexOf(".")!=-1)
  +                  sresult=sresult.substring(sresult.lastIndexOf(".")+1);
  +               result=sresult;
               }
  -            
  -            return result;
  -        }
  -    } 
  -         
  +         }
  +
  +         return result;
  +      }
  +   }
  +
  +   /**
  +    * a tiny helper that does some default mapping of methods to method names
  +    */
  +
  +   public static class DefaultMethodMap extends HashMap
  +   {
  +
  +      /** no entries is the default */
  +      public DefaultMethodMap()
  +      {
  +         super(0);
  +      }
  +
  +      /** returns default interface if no mapping is defined */
  +      public Object get(Object key)
  +      {
  +
  +         Object result=super.get(key);
  +
  +         if(result==null && key instanceof Method)
  +         {
  +            result=((Method) key).getName();
  +         }
  +
  +         return result;
  +      }
  +   }
  +
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to