You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2001/06/14 23:30:25 UTC

cvs commit: xml-axis/java/src/org/apache/axis/client/http AdminClient.java

gdaniels    01/06/14 14:30:25

  Modified:    java/src/org/apache/axis AxisEngine.java
               java/src/org/apache/axis/client ServiceClient.java
                        Transport.java
               java/src/org/apache/axis/client/http AdminClient.java
  Log:
  First cut at a Transport registry.
  
  We can now say:
  
       client = new ServiceClient(url);
  
  and the engine will figure out the right Transport objects to use based
  on the protocol portion of the URL.
  
  This is a proof-of-concept at the moment.  It should be given some more
  thought and cleaned up.  For one thing, there should be an easy way
  for us (and others) to add new transports without touching AxisEngine.
  
  Revision  Changes    Path
  1.7       +44 -0     xml-axis/java/src/org/apache/axis/AxisEngine.java
  
  Index: AxisEngine.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisEngine.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AxisEngine.java	2001/06/14 12:39:00	1.6
  +++ AxisEngine.java	2001/06/14 21:30:18	1.7
  @@ -56,8 +56,10 @@
   package org.apache.axis;
   
   import java.io.*;
  +import java.net.URL;
   import java.util.* ;
   import org.apache.axis.* ;
  +import org.apache.axis.client.Transport;
   import org.apache.axis.utils.* ;
   import org.apache.axis.handlers.* ;
   import org.apache.axis.handlers.soap.* ;
  @@ -66,6 +68,11 @@
   import org.apache.axis.session.SimpleSession;
   import org.apache.axis.encoding.*;
   
  +/** Temporary - this will be replaced by deployment
  + */
  +import org.apache.axis.client.http.HTTPTransport;
  +import org.apache.axis.client.tcp.TCPTransport;
  +
   /**
    * An <code>AxisEngine</code> is the base class for AxisClient and
    * AxisServer.  Handles common functionality like dealing with the
  @@ -89,6 +96,10 @@
       
       protected Properties props = new Properties();
       
  +    /** A map of protocol names to "client" (sender) transports
  +     */
  +    protected Hashtable protocolSenders = new Hashtable();
  +    
       /**
        * This engine's Session.  This Session supports "application scope"
        * in the Apache SOAP sense... if you have a service with "application
  @@ -96,6 +107,15 @@
        */
       private Session session = new SimpleSession();
       
  +    /**
  +     * Initialize static stuff - this is kind of kludgey here.  Probably
  +     * wants to live somewhere more reasonable. ???
  +     * 
  +     */
  +    public static void staticInit() {
  +        // System.out.println("Registering URL stream handler factory.");
  +        URL.setURLStreamHandlerFactory(Transport.getURLStreamHandlerFactory());
  +    }
       
       /**
        * No-arg constructor.  Loads properties from the "axis.properties"
  @@ -115,6 +135,20 @@
           } catch (Exception e) {
               e.printStackTrace();
           }
  +        
  +        /** Load default transports
  +         * 
  +         * (these will be shared - really should be a factory, but
  +         *  we need to go over the architecture / patterns here
  +         *  anyway, so this is a quick P.O.C. for now)
  +         */
  +        protocolSenders.put("http", new HTTPTransport());
  +        protocolSenders.put("tcp", new TCPTransport());
  +        
  +        // Once we've got a LocalTransport class...
  +        //
  +        //protocolSenders.put("local", new LocalTransport());
  +        
           Debug.Print( 1, "Exit: AxisEngine no-arg constructor");
       }
       
  @@ -213,6 +247,16 @@
       public TypeMappingRegistry getTypeMappingRegistry()
       {
           return _typeMappingRegistry;
  +    }
  +    
  +    public Transport getTransportForProtocol(String protocol)
  +        throws Exception
  +    {
  +        Transport transport = (Transport)protocolSenders.get(protocol);
  +        if (transport == null)
  +            throw new Exception("Couldn't find Transport for protocol '" +
  +                                    protocol + "'");
  +        return transport;
       }
       
       /*********************************************************************
  
  
  
  1.13      +24 -1     xml-axis/java/src/org/apache/axis/client/ServiceClient.java
  
  Index: ServiceClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/ServiceClient.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ServiceClient.java	2001/06/14 07:04:02	1.12
  +++ ServiceClient.java	2001/06/14 21:30:21	1.13
  @@ -56,6 +56,7 @@
   package org.apache.axis.client ;
   
   import java.util.* ;
  +import java.net.*;
   import org.apache.axis.encoding.ServiceDescription;
   import org.apache.axis.message.*;
   import org.apache.axis.handlers.* ;
  @@ -111,7 +112,6 @@
       // Our Transport, if any
       private Transport transport;
       
  -    
       /**
        * Construct a ServiceClient with no properties.
        * Set it up yourself!
  @@ -123,10 +123,33 @@
       }
       
       /**
  +     * Construct a ServiceClient with a given endpoint URL
  +     */
  +    public ServiceClient(String endpointURL)
  +    {
  +        this();
  +        
  +        try {
  +            URL url = new URL(endpointURL);          
  +            String protocol = url.getProtocol();
  +            setTransport(engine.getTransportForProtocol(protocol));
  +            set(MessageContext.TRANS_URL, endpointURL);
  +        } catch (MalformedURLException e) {
  +            e.printStackTrace();
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +        }
  +    }
  +    
  +    /**
        * Construct a ServiceClient with the given Transport.
        */
       public ServiceClient (Transport transport) {
           this();
  +        setTransport(transport);
  +    }
  +    
  +    public void setTransport(Transport transport) {
           this.transport = transport;
           
           // set up the message context with the transport
  
  
  
  1.4       +27 -0     xml-axis/java/src/org/apache/axis/client/Transport.java
  
  Index: Transport.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Transport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Transport.java	2001/06/13 17:53:25	1.3
  +++ Transport.java	2001/06/14 21:30:22	1.4
  @@ -56,12 +56,39 @@
   package org.apache.axis.client;
   
   import java.util.* ;
  +import java.net.*;
  +import java.io.IOException;
   import org.apache.axis.MessageContext;
   import org.apache.axis.AxisFault;
   import org.apache.axis.AxisEngine;
   import org.apache.axis.Handler;
   
   public abstract class Transport {
  +    static class AxisURLHandler extends URLStreamHandler {
  +        /** This is just for parsing purposes, so don't really open any
  +         * connections.  At some point we may actually want to do something
  +         * here...
  +         */
  +        public URLConnection openConnection(URL url) throws IOException
  +        {
  +            return null;
  +        }
  +    }
  +    
  +    static class AxisURLStreamHandlerFactory implements URLStreamHandlerFactory {
  +        public URLStreamHandler createURLStreamHandler(String protocol)
  +        {
  +            // For now, just accept anything.  Later we might want to
  +            // generate MalformedURLExceptions for non-supported protocols.
  +            return new AxisURLHandler();
  +        }
  +    }
  +    
  +    public static URLStreamHandlerFactory getURLStreamHandlerFactory()
  +    {
  +        return new AxisURLStreamHandlerFactory();
  +    }
  +    
       /**
        * Synonyms for MessageContext userid / password.
        */
  
  
  
  1.3       +17 -10    xml-axis/java/src/org/apache/axis/client/http/AdminClient.java
  
  Index: AdminClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/http/AdminClient.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AdminClient.java	2001/06/12 15:43:05	1.2
  +++ AdminClient.java	2001/06/14 21:30:24	1.3
  @@ -69,6 +69,7 @@
   import org.apache.axis.MessageContext ;
   import org.apache.axis.utils.Debug ;
   import org.apache.axis.encoding.ServiceDescription;
  +import org.apache.axis.transport.http.HTTPConstants;
   
   /**
    * An admin client object, specific to HTTP.
  @@ -93,6 +94,8 @@
       public void doAdmin (String[] args)
           throws Exception
       {
  +        org.apache.axis.AxisEngine.staticInit();
  +        
           Options opts = new Options( args );
           
           Debug.setDebugLevel( opts.isFlagSet('d') );
  @@ -120,26 +123,30 @@
                   System.out.println( "Processing file: " + args[i] );
                   input = new FileInputStream( args[i] );
               }
  +            
  +            ServiceClient     client       =
  +                new ServiceClient(opts.getURL());
               
  -            ServiceClient     hMsg       =
  -                new ServiceClient(new HTTPTransport(opts.getURL(), "AdminService"));
  +            /** Set the action in case it's HTTP
  +             */
  +            client.set(HTTPConstants.MC_HTTP_SOAPACTION, "AdminService");
               
               Message         inMsg      = new Message( input, true );
  -            hMsg.setRequestMessage( inMsg );
  +            client.setRequestMessage( inMsg );
               
  -            if ( opts.isFlagSet('t') > 0 ) hMsg.doLocal = true ;
  -            hMsg.set( Transport.USER, opts.getUser() );
  -            hMsg.set( Transport.PASSWORD, opts.getPassword() );
  +            if ( opts.isFlagSet('t') > 0 ) client.doLocal = true ;
  +            client.set( Transport.USER, opts.getUser() );
  +            client.set( Transport.PASSWORD, opts.getPassword() );
               
  -            hMsg.invoke();
  +            client.invoke();
               
  -            Message outMsg = hMsg.getMessageContext().getResponseMessage();
  -            hMsg.getMessageContext().setServiceDescription(new ServiceDescription("Admin", false));
  +            Message outMsg = client.getMessageContext().getResponseMessage();
  +            client.getMessageContext().setServiceDescription(new ServiceDescription("Admin", false));
               input.close();
               SOAPEnvelope envelope = (SOAPEnvelope) outMsg.getAsSOAPEnvelope();
               SOAPBodyElement body = envelope.getFirstBody();
               StringWriter writer = new StringWriter();
  -            SerializationContext ctx = new SerializationContext(writer, hMsg.getMessageContext());
  +            SerializationContext ctx = new SerializationContext(writer, client.getMessageContext());
               body.output(ctx);
               System.out.println(writer.toString());
           }