[prev in list] [next in list] [prev in thread] [next in thread] 

List:       axis-dev
Subject:    cvs commit: xml-axis/java/src/org/apache/axis/message RPCArg.java RPCBody.java
From:       dug () apache ! org
Date:       2001-01-31 19:49:56
[Download RAW message or body]

dug         01/01/31 11:49:56

  Modified:    java     build.xml
               java/samples/stock GetQuote.java
               java/src/org/apache/axis Message.java MessageContext.java
               java/src/org/apache/axis/message RPCArg.java RPCBody.java
  Added:       java/src/org/apache/axis/client HTTPCall.java
               java/src/org/apache/axis/handlers HTTPDispatchHandler.java
  Log:
  Added nicer client support.
  And if cvs works right - changed stock sample.
  
  Revision  Changes    Path
  1.4       +1 -0      xml-axis/java/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml	2001/01/28 05:58:28	1.3
  +++ build.xml	2001/01/31 19:49:45	1.4
  @@ -176,6 +176,7 @@
              classpath="${build.lib}/${name}.jar" debug="${debug}">
         <include name="samples/**/*.java" />
         <exclude name="samples/**/*SMTP*.java" unless="smtp.present" />
  +      <exclude name="**/old/**/*.java" />
       </javac>
       <copy todir="${build.samples}">
         <fileset dir="${samples.dir}"/>
  
  
  
  1.4       +28 -40    xml-axis/java/samples/stock/GetQuote.java
  
  Index: GetQuote.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/stock/GetQuote.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GetQuote.java	2001/01/27 20:52:41	1.3
  +++ GetQuote.java	2001/01/31 19:49:47	1.4
  @@ -61,6 +61,8 @@
   import java.io.*;
   import java.util.*;
   
  +import org.apache.axis.client.HTTPCall ;
  +
   /** 
    *
    * @author Doug Davis (dug@us.ibm.com.com)
  @@ -69,32 +71,17 @@
   
     public static void main(String args[]) {
   
  -    String hdr = "POST /axis/servlet/AxisServlet HTTP/1.0\n" +
  -                 "Host: localhost:8080\n" +
  -                 "Content-Type: text/xml;charset=utf-8\n" +
  -                 "SOAPAction: urn:xmltoday-delayed-quotes\n";
  -
  -    String msg ;
  -    String msg1 = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"" +
  -                  "http://schemas.xmlsoap.org/soap/envelope/\" " +
  -                  "xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\"" + 
  -                  " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">\n" +
  -                  "<SOAP-ENV:Body>\n" ;
  -    String head = "<m:getQuote xmlns:m=\"urn:xmltoday-delayed-quotes\">\n" +
  -                  "<symbol>" ;
  -    String tail = "</symbol>\n</m:getQuote>\n" ;
  -    String msg2 = "</SOAP-ENV:Body>\n" +
  -                  "</SOAP-ENV:Envelope>" ;
  -
       try {
  -      String  host   = "localhost" ;
  -      int     port   = 8080 ;
  -      boolean atLeastOne = false ;
  +      String  symbol = null ;
   
  -      msg = msg1 ;
  +      /* Parse the command line  */
  +      /***************************/
  +      String  host    = "localhost" ;
  +      String  servlet = "/axis/servlet/AxisServlet" ;
  +      int     port    = 8080 ;
   
         for ( int i = 0 ; i < args.length ; i++ ) {
  -        if ( args[i].charAt(0) == '-' ) {
  +        if ( args[i].charAt(0) == '-' ) 
             switch( args[i].toLowerCase().charAt(1) ) {
               case 'h': if ( args[i].length() > 2 )
                           host = args[i].substring(2);
  @@ -102,35 +89,36 @@
               case 'p': if ( args[i].length() > 2 )
                           port = Integer.parseInt(args[i].substring(2));
                         break ;
  +            case 's': if ( args[i].length() > 2 )
  +                        servlet = args[i].substring(2);
  +                      if ( servlet != null && servlet.charAt(0) != '/' )
  +                        servlet = "/" + servlet ;
  +                      break ;
  +            case 'u': if ( args[i].length() > 2 ) {
  +                        URL tmpurl = new URL(args[i].substring(2));
  +                        host = tmpurl.getHost();
  +                        port = tmpurl.getPort();
  +                        servlet = tmpurl.getPath() ;
  +                      }
  +                      break ;
               default: System.err.println( "Unknown option '" + 
                                            args[i].charAt(1) + "'" );
                        System.exit(1);
             }
  -        }
  -        else {
  -          atLeastOne = true ;
  -          msg += head + args[i] + tail ;
  -        }
  +        else 
  +          symbol = args[i] ;
         }
  -      msg += msg2 ;
   
  -      if ( !atLeastOne ) {
  +      if ( symbol == null ) {
           System.err.println( "Usage: GetQuote <symbol>" );
           System.exit(1);
         }
   
  -      String         cl = "Content-Length: " + msg.length() + "\n\n" ;
  -      Socket         sock = new Socket( host, port );
  -      InputStream    inp = sock.getInputStream();
  -      OutputStream   out = sock.getOutputStream();
  -      byte           b ;
  -
  -      out.write( hdr.getBytes() );
  -      out.write( cl.getBytes() );
  -      out.write( msg.getBytes() );
  +      String url = "http://" + host + ":" + port + servlet ;
  +      HTTPCall call = new HTTPCall( url, "urn:xmltoday-delayed-quotes" );
  +      String res = (String) call.invoke( "getQuote", new Object[] {symbol} );
   
  -      while ( (b = (byte) inp.read()) != -1 ) 
  -        System.out.write( b );
  +      System.out.println( symbol + ": " + res );
       }
       catch( Exception e ) {
         System.err.println( e );
  
  
  
  1.8       +5 -5      xml-axis/java/src/org/apache/axis/Message.java
  
  Index: Message.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Message.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Message.java	2001/01/28 18:05:34	1.7
  +++ Message.java	2001/01/31 19:49:48	1.8
  @@ -113,7 +113,7 @@
       if ( currentForm.equals( desiredType ) ) return( currentMessage );
   
       if ( desiredType.equals( "Bytes" )) return( getAsBytes() );
  -    if ( desiredType.equals( "Document" )) return( getAsDOMDocument() );
  +    if ( desiredType.equals( "Document" )) return( getAsDocument() );
       if ( desiredType.equals( "String" )) return( getAsString() );
       if ( desiredType.equals( "SOAPEnvelope" )) return( getAsSOAPEnvelope() );
   
  @@ -152,7 +152,7 @@
         }
       }
   
  -    if ( currentForm.equals("DOMDocument") ||
  +    if ( currentForm.equals("Document") ||
            currentForm.equals("SOAPEnvelope") ||
            currentForm.equals("AxisFault") )
         getAsString();
  @@ -183,7 +183,7 @@
   
       if ( currentForm.equals("SOAPEnvelope") ||
            currentForm.equals("AxisFault") )
  -      getAsDOMDocument();
  +      getAsDocument();
   
       if ( currentForm.equals("Document") ) { 
         try {
  @@ -204,7 +204,7 @@
       return( null );
     }
   
  -  private Document getAsDOMDocument() {
  +  private Document getAsDocument() {
       if ( currentForm.equals("Document") ) return( (Document) currentMessage );
   
       DOMParser  parser = new DOMParser();
  @@ -256,7 +256,7 @@
     private SOAPEnvelope getAsSOAPEnvelope() {
       if ( currentForm.equals("SOAPEnvelope") ) 
         return( (SOAPEnvelope) currentMessage );
  -    getAsDOMDocument();
  +    getAsDocument();
       setCurrentMessage( new SOAPEnvelope( (Document) currentMessage ),
                          "SOAPEnvelope" );
       return( (SOAPEnvelope) currentMessage );
  
  
  
  1.5       +6 -0      xml-axis/java/src/org/apache/axis/MessageContext.java
  
  Index: MessageContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/MessageContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MessageContext.java	2001/01/26 20:54:57	1.4
  +++ MessageContext.java	2001/01/31 19:49:48	1.5
  @@ -82,6 +82,12 @@
      */
     private Hashtable bag ;
   
  +  public MessageContext() {}
  +
  +  public MessageContext( Message inMsg ) {
  +    setIncomingMessage( inMsg );
  +  }
  +
     /**
      * Placeholder.
      */
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/client/HTTPCall.java
  
  Index: HTTPCall.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 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 and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.client ;
  
  import java.util.* ;
  import org.apache.axis.* ;
  import org.apache.axis.message.* ;
  import org.apache.axis.handlers.* ;
  
  /**
   *
   * @author Doug Davis (dug@us.ibm.com)
   */
  
  
  // Need to add proxy, ssl.... other cool things - but it's a start
  // Only supports String
  
  public class HTTPCall {
    private String  url ;
    private String  action ;
  
    public HTTPCall() {
    }
  
    public HTTPCall(String url) {
      this.url = url ;
    }
  
    public HTTPCall(String url, String action) {
      setURL( url );
      setAction( action );
    }
  
    public void setURL( String url ) {
      this.url = url ;
    }
  
    public void setAction( String action ) {
      this.action = action ;
    }
  
    public static Object invoke(String url, String act, String m, Object[] args) {
      HTTPCall  ahc = new HTTPCall();
      ahc.setURL( url );
      ahc.setAction( act );
      return( ahc.invoke( m, args ) );
    }
  
    public Object invoke( String method, Object[] args ) {
      // quote = HTTPCall.invoke( "getQuote", Object[] { "IBM" } );
      RPCBody              body   = new RPCBody( method, args );
      SOAPEnvelope         reqEnv = new SOAPEnvelope();
      SOAPEnvelope         resEnv = null ;
      HTTPDispatchHandler  client = new HTTPDispatchHandler();
      Message              reqMsg = new Message( reqEnv, "SOAPEnvelope" );
      Message              resMsg = null ;
      MessageContext       msgContext = new MessageContext( reqMsg );
      Vector               resBodies = null ;
      Vector               resArgs = null ;
      RPCArg               arg ;
  
      reqEnv.addBody( body );
      msgContext.setProperty( "HTTP_URL", url );   // horrible name!
      msgContext.setProperty( "HTTP_ACTION", action );   // horrible name!
      try {
        client.init();
        client.invoke( msgContext );
        client.cleanup();
      }
      catch( AxisFault fault ) {
        System.err.println( fault );
        System.exit(1); /// ha!
      }
  
      resMsg = msgContext.getOutgoingMessage();
      resEnv = (SOAPEnvelope) resMsg.getAs( "SOAPEnvelope" );
      resBodies = resEnv.getAsRPCBody();
      if ( resBodies == null || resBodies.size() == 0 ) return( null );
      body = (RPCBody) resBodies.get( 0 );
      resArgs = body.getArgs();
      arg = (RPCArg) resArgs.get(0);
      return( (String) arg.getValue() );
    }
  
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/handlers/HTTPDispatchHandler.java
  
  Index: HTTPDispatchHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 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 and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.handlers ;
  
  import java.io.* ;
  import java.net.* ;
  import java.util.* ;
  import org.w3c.dom.* ;
  import org.xml.sax.InputSource ;
  import org.apache.xerces.parsers.DOMParser ;
  import org.apache.axis.* ;
  import org.apache.axis.utils.* ;
  import org.apache.axis.message.* ;
  
  /**
   *
   * @author Doug Davis (dug@us.ibm.com)
   */
  public class HTTPDispatchHandler implements Handler {
    protected Hashtable  options ;
  
    public void init() {
    }
  
    public void cleanup() {
    }
  
    public void invoke(MessageContext msgContext) throws AxisFault {
      /* Find the service we're invoking so we can grab it's options */
      /***************************************************************/
      String   targetURL = (String) msgContext.getProperty( "HTTP_URL" );
      Message  outMsg    = null ;
      String   reqEnv    = null ;
  
      try {
        String   host ;
        int      port = 80 ;
        String   action = (String) msgContext.getProperty( "HTTP_ACTION" );
        URL      tmpURL        = new URL( targetURL );
        byte[]   buf           = new byte[4097];
        int      rc            = 0 ;
  
        host = tmpURL.getHost();
        if ( (port = tmpURL.getPort()) == -1 ) port = 80;
  
        Socket             sock = null ;
        sock = new Socket( host, port );
        reqEnv    = (String) msgContext.getIncomingMessage().getAs("String");
        OutputStream  out  = sock.getOutputStream();
        InputStream   inp  = sock.getInputStream();
        String        header = "POST " + tmpURL.getPath() + " HTTP/1.0\n" +
                               "Content-Length: " + reqEnv.length() + "\n" +
                               "SOAPAction: " + action + "\n\n" ;
  
        out.write( header.getBytes() );
        out.write( reqEnv.getBytes() );
  
        byte       lastB=0, b ;
        int        len = 0 ;
        int        colonIndex = -1 ;
        Hashtable  headers = new Hashtable();
        String     name, value ;
  
        // Need to add logic for getting the version # and the return code
        // but that's for tomorrow!
  
        for ( ;; ) {
          if ( (b = (byte) inp.read()) == -1 ) break ;
          if ( b != '\r' && b != '\n' ) {
            if ( b == ':' ) colonIndex = len ;
            lastB = (buf[len++] = b);
          }
          else if ( b == '\r' )
            continue ;
          else {
            if ( len == 0 ) break ;
            if ( colonIndex != -1 ) {
              name = new String( buf, 0, colonIndex );
              value = new String( buf, colonIndex+1, len-1-colonIndex );
            }
            else {
              name = new String( buf, 0, len );
              value = "" ;
            }
            headers.put( name, value );
            len = 0 ;
          }
        }
        if ( b != -1 ) {
          DOMParser  parser = new DOMParser();
          parser.parse( new InputSource( inp ) );
    
          outMsg = new Message( parser.getDocument(), "Document" );
          msgContext.setOutgoingMessage( outMsg );
        }
  
        inp.close();
        out.close();
        sock.close();
      }
      catch( Exception e ) {
        e.printStackTrace();
        if ( !(e instanceof AxisFault) ) e = new AxisFault(e);
        throw (AxisFault) e ;
      } 
    }
  
    public void undo(MessageContext msgContext) { 
    }
  
    public boolean canHandleBlock(QName qname) {
      return( false );
    }
  
    /**
     * Add the given option (name/value) to this handler's bag of options
     */
    public void addOption(String name, Object value) {
      if ( options == null ) options = new Hashtable();
      options.put( name, value );
    }
  
    /**
     * Returns the option corresponding to the 'name' given
     */
    public Object getOption(String name) {
      if ( options == null ) return( null );
      return( options.get(name) );
    }
  
    /**
     * Return the entire list of options
     */
    public Hashtable getOptions() {
      return( options );
    }
  
    public void setOptions(Hashtable opts) {
      options = opts ;
    }
  };
  
  
  
  1.5       +10 -0     xml-axis/java/src/org/apache/axis/message/RPCArg.java
  
  Index: RPCArg.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCArg.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RPCArg.java	2001/01/27 19:55:05	1.4
  +++ RPCArg.java	2001/01/31 19:49:54	1.5
  @@ -83,6 +83,16 @@
       value = elem.getFirstChild().getNodeValue();
     }
   
  +  public RPCArg(String name) {
  +    setName( name );
  +  }
  +
  +  // should go away once we support more than just String
  +  public RPCArg(String name, String value) {  
  +    setName( name );
  +    setValue( value );
  +  }
  +
     public String getNamespace() { return( namespace ); }
     public void   setNamespace(String ns) { namespace = ns ; }
   
  
  
  
  1.6       +10 -0     xml-axis/java/src/org/apache/axis/message/RPCBody.java
  
  Index: RPCBody.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCBody.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RPCBody.java	2001/01/27 19:55:05	1.5
  +++ RPCBody.java	2001/01/31 19:49:54	1.6
  @@ -94,6 +94,16 @@
           addArg( new RPCArg( (Element) list.get(i) ) );
     }
   
  +  public RPCBody(String methodName, Object[] args) {
  +    setMethodName( methodName );
  +    if ( args != null ) {
  +      for ( int i = 0 ; i < args.length ; i++ ) {
  +        RPCArg  arg = new RPCArg( "arg" + i, (String) args[i] );
  +        addArg( arg );
  +      }
  +    }
  +  }
  +
     public String getMethodName() { return( name ); }
     public void   setMethodName(String name) { this.name = name ; }
   
  
  
  

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic