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 du...@apache.org on 2001/02/17 17:44:02 UTC

cvs commit: xml-axis/java/src/org/apache/axis/message RPCBody.java

dug         01/02/17 08:44:02

  Modified:    java/samples/stock GetInfo.java GetQuote.java
               java/src/org/apache/axis AxisFault.java
               java/src/org/apache/axis/client HTTPCall.java
                        HTTPMessage.java
               java/src/org/apache/axis/handlers RPCDispatchHandler.java
                        SimpleAuthenticationHandler.java
                        SimpleAuthorizationHandler.java
               java/src/org/apache/axis/message RPCBody.java
  Added:       java/samples/misc TestClient.java
  Removed:     java/src/org/apache/axis/client EchoClient.java
                        TestClient.java
  Log:
  Added a doLocal opt to all samples (-t)
  Removed the test client stuff from .../axis/client and created
    a samples/misc/TestClient instead
  Made HTTPCall use HTTPMessage
  Fixed a bug in the RPCBody stuff
  
  Revision  Changes    Path
  1.1                  xml-axis/java/samples/misc/TestClient.java
  
  Index: TestClient.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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package samples.misc ;
  
  import java.net.*;
  import java.io.*;
  import java.util.*;
  
  import org.apache.axis.*;
  import org.apache.axis.utils.Debug ;
  import org.apache.axis.utils.Options ;
  import org.apache.axis.client.HTTPMessage ;
  import org.apache.axis.server.SimpleAxisEngine;
  
  /**
   *
   * @author Doug Davis (dug@us.ibm.com)
   * @author Glen Daniels (gdaniels@allaire.com)
   */
  public class TestClient {
    public static void main(String args[]) {
      try {
        Options      opts    = new Options( args );
        String       url     = opts.getURL();
        String       action  = "EchoService" ;
  
        Debug.setDebugLevel( opts.isFlagSet( 'd' ) );
  
        args = opts.getRemainingArgs();
        if ( args != null ) action = args[0];
  
        HTTPMessage  hMsg    = new HTTPMessage( url, action );
  
        if ( opts.isFlagSet('t') > 0 ) hMsg.doLocal = true ;
  
        String       msg     = "<m:GetLastTradePrice xmlns:m=\"Some-URI\">\n" +
                               "<symbol>IBM</symbol>\n" +
                               "</m:GetLastTradePrice>\n" ;
  
        MessageContext msgContext = new MessageContext();
        Message        inMsg      = new Message( msg, "String" );
        Message        outMsg     = null ;
  
        System.out.println( "Request:\n" + msg );
          
        msgContext.setIncomingMessage( inMsg );
        hMsg.invoke( msgContext );
        outMsg = msgContext.getOutgoingMessage();
  
        System.out.println( "Response:\n" + outMsg.getAs( "String" ) );
      }
      catch( Exception e ) {
        if ( e instanceof AxisFault ) ((AxisFault)e).dump();
        else e.printStackTrace();
      }
    };
  };
  
  
  
  1.4       +6 -2      xml-axis/java/samples/stock/GetInfo.java
  
  Index: GetInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/stock/GetInfo.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GetInfo.java	2001/02/16 22:50:37	1.3
  +++ GetInfo.java	2001/02/17 16:44:01	1.4
  @@ -59,6 +59,7 @@
   import java.io.*;
   import java.util.*;
   
  +import org.apache.axis.AxisFault ;
   import org.apache.axis.utils.Debug ;
   import org.apache.axis.utils.Options ;
   import org.apache.axis.client.HTTPCall ;
  @@ -77,7 +78,7 @@
   
         args = opts.getRemainingArgs();
   
  -      if ( args.length % 2 != 0 ) {
  +      if ( args == null || args.length % 2 != 0 ) {
           System.err.println( "Usage: GetInfo <symbol> <datatype>" );
           System.exit(1);
         }
  @@ -85,6 +86,8 @@
         String  symbol = args[0] ;
         HTTPCall call = new HTTPCall( opts.getURL(), "urn:cominfo" );
   
  +      if ( opts.isFlagSet('t') > 0 ) call.doLocal = true ;
  +
         call.setUserID( opts.getUser() );
         call.setPassword( opts.getPassword() );
         String res = (String) call.invoke( "getInfo",
  @@ -93,7 +96,8 @@
         System.out.println( symbol + ": " + res );
       }
       catch( Exception e ) {
  -      System.err.println( e );
  +      if ( e instanceof AxisFault ) ((AxisFault)e).dump();
  +      else e.printStackTrace();
       }
     };
   
  
  
  
  1.11      +3 -0      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- GetQuote.java	2001/02/16 22:50:39	1.10
  +++ GetQuote.java	2001/02/17 16:44:01	1.11
  @@ -59,6 +59,7 @@
   import java.io.*;
   import java.util.*;
   
  +import org.apache.axis.AxisFault ;
   import org.apache.axis.client.HTTPCall ;
   import org.apache.axis.utils.Debug ;
   import org.apache.axis.utils.Options ;
  @@ -86,6 +87,7 @@
         String   symbol = args[0] ;
         HTTPCall call   = new HTTPCall( opts.getURL(), 
                                         "urn:xmltoday-delayed-quotes" );
  +      if ( opts.isFlagSet('t') > 0 ) call.doLocal = true ;
         call.setUserID( opts.getUser() );
         call.setPassword( opts.getPassword() );
         String res = (String) call.invoke( "getQuote", new Object[] {symbol} );
  @@ -93,6 +95,7 @@
         System.out.println( symbol + ": " + res );
       }
       catch( Exception e ) {
  +      if ( e instanceof AxisFault ) ((AxisFault)e).dump();
         e.printStackTrace();
       }
     };
  
  
  
  1.9       +8 -0      xml-axis/java/src/org/apache/axis/AxisFault.java
  
  Index: AxisFault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisFault.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AxisFault.java	2001/02/10 04:39:53	1.8
  +++ AxisFault.java	2001/02/17 16:44:01	1.9
  @@ -93,6 +93,14 @@
       setFaultString( stream.toString() );
     }
   
  +  public void dump() {
  +    System.out.println( "AxisFault\n" +
  +                        "  faultCode: " + faultCode + "\n" +
  +                        "  faultString: " + faultString + "\n" +
  +                        "  faultActor: " + faultActor + "\n" +
  +                        "  faultDetails: " + faultDetails + "\n"  );
  +  }
  +
     public void setFaultCode(String code) {
       faultCode = code ;
     }
  
  
  
  1.11      +14 -31    xml-axis/java/src/org/apache/axis/client/HTTPCall.java
  
  Index: HTTPCall.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/HTTPCall.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HTTPCall.java	2001/02/12 13:00:03	1.10
  +++ HTTPCall.java	2001/02/17 16:44:02	1.11
  @@ -57,7 +57,6 @@
   
   import java.util.* ;
   import org.w3c.dom.* ;
  -import org.apache.xerces.dom.DocumentImpl ;
   import org.apache.axis.* ;
   import org.apache.axis.message.* ;
   import org.apache.axis.handlers.* ;
  @@ -84,6 +83,9 @@
     private String  userID ;
     private String  passwd ;
   
  +  // For testing
  +  public  boolean doLocal = false ;
  +
     public HTTPCall() {
     }
   
  @@ -135,7 +137,7 @@
       RPCBody              body   = new RPCBody( method, args );
       SOAPEnvelope         reqEnv = new SOAPEnvelope();
       SOAPEnvelope         resEnv = null ;
  -    Handler              client = new HTTPDispatchHandler();
  +    HTTPMessage          hMsg   = new HTTPMessage( url, action );
       Message              reqMsg = new Message( reqEnv, "SOAPEnvelope" );
       Message              resMsg = null ;
       MessageContext       msgContext = new MessageContext( reqMsg );
  @@ -143,35 +145,18 @@
       Vector               resArgs = null ;
       RPCArg               arg ;
   
  +    hMsg.setUserID( userID );
  +    hMsg.setPassword( passwd );
  +
  +    // for testing - skip HTTP layer
  +    hMsg.doLocal = this.doLocal ;
  +
       body.setPrefix( "m" );
       body.setNamespaceURI( action );
  -    reqEnv.addBody( body );
  +    reqEnv.addBody( body.getAsSOAPBody() );
   
  -    // Until we have chains on the client force a debug header if needed
  -    if ( true ) { // Debug.getDebugLevel() > 0  ) {
  -      SOAPHeader  header = new SOAPHeader();
  -      header.setPrefix("d");
  -      header.setName("Debug");
  -      header.setNamespaceURI( Constants.URI_DEBUG );
  -      header.setActor( Constants.URI_NEXT_ACTOR );
  -      Document doc = new DocumentImpl();
  -      Node node = doc.createTextNode( "" + Debug.getDebugLevel() );
  -      header.addDataNode( node );
  -  
  -      reqEnv.addHeader( header );
  -    }
  -
  -    msgContext.setProperty( MessageContext.TRANS_URL, url );
  -    msgContext.setProperty( HTTPConstants.MC_HTTP_SOAPACTION, action );
  -    if ( userID != null ) {
  -      msgContext.setProperty( MessageContext.USERID, userID );
  -      if ( passwd != null )
  -        msgContext.setProperty( MessageContext.PASSWORD, passwd );
  -    }
       try {
  -      client.init();
  -      client.invoke( msgContext );
  -      client.cleanup();
  +      hMsg.invoke( msgContext );
       }
       catch( Exception e ) {
         Debug.Print( 1, e );
  @@ -180,10 +165,8 @@
       }
   
       resMsg = msgContext.getOutgoingMessage();
  -    resEnv = (SOAPEnvelope) resMsg.getAs( "SOAPEnvelope" );
  -    resBodies = resEnv.getAsRPCBody();
  -    if ( resBodies == null || resBodies.size() == 0 ) return( null );
  -    body = (RPCBody) resBodies.get( 0 );
  +    Document doc = (Document) resMsg.getAs("Document");
  +    body = new RPCBody( doc.getDocumentElement() );
       resArgs = body.getArgs();
       arg = (RPCArg) resArgs.get(0);
       Debug.Print( 1, "Exit: HTTPCall.invoke" );
  
  
  
  1.8       +57 -11    xml-axis/java/src/org/apache/axis/client/HTTPMessage.java
  
  Index: HTTPMessage.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/HTTPMessage.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HTTPMessage.java	2001/02/12 13:00:03	1.7
  +++ HTTPMessage.java	2001/02/17 16:44:02	1.8
  @@ -57,6 +57,7 @@
   
   import java.util.* ;
   import org.w3c.dom.* ;
  +import org.apache.xerces.dom.DocumentImpl ;
   
   import org.apache.axis.* ;
   import org.apache.axis.message.* ;
  @@ -79,9 +80,14 @@
   // Only supports String
   
   public class HTTPMessage {
  -  private String  url ;
  -  private String  action ;
  +  private String  url    = null ;
  +  private String  action = null ;
  +  private String  userID = null ;
  +  private String  passwd = null ;
   
  +  // For testing
  +  public boolean doLocal = false ;
  +
     public HTTPMessage() {
     }
   
  @@ -102,6 +108,22 @@
       this.action = action ;
     }
   
  +  public void setUserID(String user) {
  +    this.userID = user ;
  +  }
  +
  +  public String getUserID() {
  +    return( userID );
  +  }
  +
  +  public void setPassword(String pass) {
  +    this.passwd = pass ;
  +  }
  +
  +  public String getPassword() {
  +    return( passwd );
  +  }
  +
     public static void invoke(String url, String act, MessageContext mc ) 
         throws AxisFault
     {
  @@ -115,23 +137,47 @@
       Debug.Print( 1, "Enter: HTTPMessage.invoke" );
       Message              inMsg = mc.getIncomingMessage();
   
  -    Document             doc = (Document) inMsg.getAs("Document");
  -    Element              root = doc.getDocumentElement();
  -    SOAPBody             reqBody = new SOAPBody( root );
  -    SOAPEnvelope         reqEnv = new SOAPEnvelope();
  +    SOAPEnvelope         reqEnv = null ;
  +
  +    if ( inMsg.getCurrentForm().equals("SOAPEnvelope") )
  +      reqEnv = (SOAPEnvelope) inMsg.getAs("SOAPEnvelope");
  +    else {
  +      reqEnv = new SOAPEnvelope();
  +      SOAPBody  body = new SOAPBody( (Document) inMsg.getAs("Document") );
  +      reqEnv.addBody( body );
  +    }
  +
       Handler              client = new HTTPDispatchHandler();
       Message              reqMsg = new Message( reqEnv, "SOAPEnvelope" );
       MessageContext       msgContext = new MessageContext( reqMsg );
   
  -    reqEnv.addBody( reqBody );
  +    // For testing - skip HTTP layer
  +    if ( doLocal ) {
  +      client = new org.apache.axis.server.SimpleAxisEngine();
  +      msgContext.setProperty( MessageContext.TARGET_SERVICE, action );
  +    }
  +
  +    if ( true ) { // Debug.getDebugLevel() > 0  ) {
  +      SOAPHeader  header = new SOAPHeader();
  +      header.setPrefix("d");
  +      header.setName("Debug");
  +      header.setNamespaceURI( Constants.URI_DEBUG );
  +      header.setActor( Constants.URI_NEXT_ACTOR );
  +      Document doc = new DocumentImpl();
  +      Node node = doc.createTextNode( "" + Debug.getDebugLevel() );
  +      header.addDataNode( node );
   
  -    // if ( Debug.DebugOn(1) ) {
  -      // Debug.Print( 1, "Request Message:" );
  -      // Debug.Print( 1, (String) reqMsg.getAs("String") );
  -    // }
  +      reqEnv.addHeader( header );
  +    }
   
       msgContext.setProperty( MessageContext.TRANS_URL, url );
       msgContext.setProperty( HTTPConstants.MC_HTTP_SOAPACTION, action );
  +    if ( userID != null ) {
  +      msgContext.setProperty( MessageContext.USERID, userID );
  +      if ( passwd != null )
  +        msgContext.setProperty( MessageContext.PASSWORD, passwd );
  +    }
  +
       try {
         client.init();
         client.invoke( msgContext );
  
  
  
  1.11      +5 -2      xml-axis/java/src/org/apache/axis/handlers/RPCDispatchHandler.java
  
  Index: RPCDispatchHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/RPCDispatchHandler.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RPCDispatchHandler.java	2001/02/12 01:11:15	1.10
  +++ RPCDispatchHandler.java	2001/02/17 16:44:02	1.11
  @@ -101,7 +101,10 @@
           Vector       args  = body.getArgs();        //RPCArg's
     
           if ( !methodName.equals(mName) )
  -          throw new AxisFault( "AxisServier.error", "Method names don't match",
  +          throw new AxisFault( "AxisServier.error", 
  +                               "Method names don't match\n" +
  +                                 "Body name=" + mName + "\n" +
  +                                 "Service name=" + methodName,
                                  null, null );  // Should they??
     
           Class[]  argClasses = new Class[ args.size() ];
  @@ -126,7 +129,7 @@
           arg.setName( "return" );
           arg.setValue( objRes.toString() );
           resBody.addArg( arg );
  -        resEnv.addBody( resBody );
  +        resEnv.addBody( resBody.getAsSOAPBody() );
         }
   
         Message outMsg = new Message( resEnv, "SOAPEnvelope" );
  
  
  
  1.6       +5 -2      xml-axis/java/src/org/apache/axis/handlers/SimpleAuthenticationHandler.java
  
  Index: SimpleAuthenticationHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/SimpleAuthenticationHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleAuthenticationHandler.java	2001/02/12 01:11:15	1.5
  +++ SimpleAuthenticationHandler.java	2001/02/17 16:44:02	1.6
  @@ -115,9 +115,12 @@
                                null, null );
       }
       catch( Exception e ) {
  -      Debug.Print( 1, e );
         // If no file - just allow everyone!
  -      if ( e instanceof FileNotFoundException ) return ;
  +      if ( e instanceof FileNotFoundException ) {
  +        Debug.Print( 1, "No 'users.lst' file found" );
  +        return ;
  +      }
  +      Debug.Print( 1, e );
         if ( !(e instanceof AxisFault) ) e = new AxisFault(e);
         throw (AxisFault) e ;
       }
  
  
  
  1.7       +5 -2      xml-axis/java/src/org/apache/axis/handlers/SimpleAuthorizationHandler.java
  
  Index: SimpleAuthorizationHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/SimpleAuthorizationHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleAuthorizationHandler.java	2001/02/12 01:11:15	1.6
  +++ SimpleAuthorizationHandler.java	2001/02/17 16:44:02	1.7
  @@ -117,9 +117,12 @@
                                null, null );
       }
       catch( Exception e ) {
  -      Debug.Print( 1, e );
         // If no file - just allow everyone!
  -      if ( e instanceof FileNotFoundException ) return ;
  +      if ( e instanceof FileNotFoundException ) {
  +        Debug.Print( 1, "No 'perms.lst' file found" );
  +        return ;
  +      }
  +      Debug.Print( 1, e );
         if ( !(e instanceof AxisFault) ) e = new AxisFault(e);
         throw (AxisFault) e ;
       }
  
  
  
  1.9       +7 -1      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RPCBody.java	2001/02/10 04:39:56	1.8
  +++ RPCBody.java	2001/02/17 16:44:02	1.9
  @@ -59,6 +59,7 @@
   
   import java.util.* ;
   import org.w3c.dom.* ;
  +import org.apache.xerces.dom.DocumentImpl ;
   import org.xml.sax.InputSource ;
   import org.apache.axis.message.* ;
   
  @@ -66,7 +67,7 @@
    *
    * @author Doug Davis (dug@us.ibm.com)
    */
  -public class RPCBody extends SOAPBody {
  +public class RPCBody { 
     protected String    methodName ;
     protected String    prefix ;
     protected String    namespaceURI ;
  @@ -144,6 +145,11 @@
         root.appendChild( arg.getAsXML(doc) );
       }
       return( root );
  +  }
  +
  +  public SOAPBody getAsSOAPBody() {
  +    Document doc = new DocumentImpl();
  +    return( new SOAPBody( getAsXML(doc) ) );
     }
   
   };