axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/client AxisClientProxy.java Service.java
Date Mon, 10 Dec 2001 04:16:52 GMT
gdaniels    01/12/09 20:16:52

  Modified:    java/src/org/apache/axis/client Service.java
  Added:       java/src/org/apache/axis/client AxisClientProxy.java
  Log:
  Simple support for dynamic proxies.  This enables the user to write an
  interface like:
  
    public interface IStockQuote extends Remote {
      public float getQuote(String symbol);
    }
  
  and then do the following:
  
    IStockQuote proxy = (IStockQuote)service.getPort(endpointURL,
                                                             IStockQuote.class);
    System.out.println(proxy.getQuote("MACR"));
  
  Haven't added support for the "full" JAX-RPC version yet.
  
  Revision  Changes    Path
  1.29      +37 -0     xml-axis/java/src/org/apache/axis/client/Service.java
  
  Index: Service.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Service.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- Service.java	2001/12/07 23:39:21	1.28
  +++ Service.java	2001/12/10 04:16:51	1.29
  @@ -63,6 +63,7 @@
   import org.apache.axis.configuration.FileProvider;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.AxisClassLoader;
   import org.w3c.dom.Document;
   
   import javax.wsdl.Binding;
  @@ -82,6 +83,7 @@
   import java.util.List;
   import java.util.Map;
   import java.util.Set;
  +import java.lang.reflect.Proxy;
   
   /**
    * Axis' JAXRPC Dynamic Invoation Interface implementation of the Service
  @@ -240,6 +242,41 @@
       public java.rmi.Remote getPort(QName portName, Class proxyInterface)
                              throws JAXRPCException {
           return( null );
  +    }
  +
  +    /**
  +     * Return an object which acts as a dynamic proxy for the passed
  +     * interface class.  This is a more "dynamic" version in that it
  +     * doesn't actually require WSDL, simply an endpoint address.
  +     *
  +     * Note: Not part of the JAX-RPC spec.
  +     *
  +     * @param endpoint the URL which will be used as the SOAP endpoint
  +     * @param proxyInterface the interface class which we wish to mimic
  +     *                       via a dynamic proxy
  +     * @throws JAXRPCException
  +     */
  +    public java.rmi.Remote getPort(String endpoint, Class proxyInterface)
  +        throws JAXRPCException
  +    {
  +        if (!proxyInterface.isInterface()) {
  +            throw new JAXRPCException(JavaUtils.getMessage("mustBeIface00"));
  +        }
  +
  +        if (!(java.rmi.Remote.class.isAssignableFrom(proxyInterface))) {
  +            throw new JAXRPCException(
  +                            JavaUtils.getMessage("mustExtendRemote00"));
  +        }
  +
  +        try {
  +            Call call = new Call(endpoint);
  +            ClassLoader classLoader = AxisClassLoader.getClassLoader();
  +            return (java.rmi.Remote)Proxy.newProxyInstance(classLoader,
  +                                                new Class[] { proxyInterface },
  +                                                new AxisClientProxy(call));
  +        } catch (Exception e) {
  +            throw new JAXRPCException(e.toString());
  +        }
       }
   
       /**
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/client/AxisClientProxy.java
  
  Index: AxisClientProxy.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Axis" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache",
  *    nor may "Apache" appear in their name, without prior written
  *    permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
  
  package org.apache.axis.client;
  
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.Method;
  
  /**
   * Very simple dynamic proxy InvocationHandler class.  This class is
   * constructed with a Call object, and then each time a method is invoked
   * on a dynamic proxy using this invocation handler, we simply turn it into
   * a SOAP request.
   *
   * @author Glen Daniels (gdaniels@macromedia.com)
   */
  public class AxisClientProxy implements InvocationHandler {
      Call call;
  
      /**
       * Constructor - package access only (should only really get used
       * in Service.getPort(endpoint, proxyClass).
       */
      AxisClientProxy(Call call)
      {
          this.call = call;
      }
  
      /**
       * Handle a method invocation.
       */
      public Object invoke(Object o, Method method, Object[] objects)
              throws Throwable {
          return call.invoke(method.getName(), objects);
      }
  }
  
  
  

Mime
View raw message