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/10/17 16:01:06 UTC

cvs commit: xml-axis/java/src/org/apache/axis/message EnvelopeBuilder.java MessageElement.java SOAPEnvelope.java

dug         01/10/17 07:01:06

  Modified:    java     build.xml
               java/samples/misc TestClient.java
               java/samples/stock testit.cmd
               java/src/org/apache/axis/client AdminClient.java Call.java
               java/src/org/apache/axis/encoding
                        DeserializationContext.java
                        SerializationContext.java
               java/src/org/apache/axis/message EnvelopeBuilder.java
                        MessageElement.java SOAPEnvelope.java
  Added:       java/samples/misc testit.cmd testit.sh
  Log:
  - Make "clean" erase more files
  - Add more testit's
  - Add support for passing in a SOAPEnvelope/SOPABodyElement into Call APIs
  - Change TestClient to use 'em
  
  Revision  Changes    Path
  1.53      +2 -0      xml-axis/java/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/build.xml,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- build.xml	2001/10/15 19:24:00	1.52
  +++ build.xml	2001/10/17 14:01:05	1.53
  @@ -420,6 +420,8 @@
       <delete dir="${dist.dir}"/>
       <delete file="client-config.xml"/>
       <delete file="server-config.xml"/>
  +    <delete dir="test-reports"/>
  +    <delete file="TEST-test.functional.FunctionalTests.txt"/>
       <antcall target="cleanAddr"/>
     </target>
   </project>
  
  
  
  1.12      +17 -15    xml-axis/java/samples/misc/TestClient.java
  
  Index: TestClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/misc/TestClient.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestClient.java	2001/09/05 17:22:58	1.11
  +++ TestClient.java	2001/10/17 14:01:06	1.12
  @@ -64,7 +64,12 @@
   import org.apache.axis.utils.Options ;
   import org.apache.axis.client.ServiceClient ;
   import org.apache.axis.transport.http.HTTPTransport ;
  +import org.apache.axis.transport.http.HTTPConstants ;
  +import org.apache.axis.client.Call ;
  +import org.apache.axis.client.Service ;
  +import org.apache.axis.message.SOAPEnvelope ;
   
  +
   /**
    *
    * @author Doug Davis (dug@us.ibm.com)
  @@ -87,33 +92,30 @@
        * @param service an optional service argument, which will be used for
        * specifying the transport-level service
        */
  -    public static String doTest (String args[], String service) throws Exception {
  +    public static String doTest (String args[], String op) throws Exception {
         Options      opts    = new Options( args );
         String       url     = opts.getURL();
         String       action  = "EchoService" ;
           
  -        if (service != null) {
  -            action = service;
  -        }
  +      if (op != null) action = op;
   
         args = opts.getRemainingArgs();
         if ( args != null ) action = args[0];
   
  -      ServiceClient client = new ServiceClient(new HTTPTransport());
  -      client.set(HTTPTransport.URL, url);
  -      client.set(HTTPTransport.ACTION, action);
  +      InputStream   input   = new ByteArrayInputStream(msg.getBytes());
  +      Service       service = new Service();
  +      Call          call    = (Call) service.createCall();
  +      SOAPEnvelope  env     = new SOAPEnvelope(input);
   
  -      Message        reqMsg      = new Message( msg );
  -      Message        resMsg     = null ;
  +      call.setTargetEndpointAddress( new URL(url) );
  +      call.setProperty( HTTPConstants.MC_HTTP_SOAPACTION, action );
   
         System.out.println( "Request:\n" + msg );
  -        
  -      client.setRequestMessage( reqMsg );
  -      client.invoke();
  -      resMsg = client.getMessageContext().getResponseMessage();
  +
  +      env = call.invoke( env );
   
  -      System.out.println( "Response:\n" + resMsg.getAsString() );
  -        return (String)resMsg.getAsString();
  +      System.out.println( "Response:\n" + env.toString() );
  +      return( env.toString() );
       }
       
     public static void main(String args[]) throws Exception{
  
  
  
  1.1                  xml-axis/java/samples/misc/testit.cmd
  
  Index: testit.cmd
  ===================================================================
  rem this assumes webserver is running on port 8080
  
  java samples.misc.TestClient
  
  
  
  1.1                  xml-axis/java/samples/misc/testit.sh
  
  Index: testit.sh
  ===================================================================
  #!/bin/sh
  # this assumes webserver is running on port 8080
  
  java samples.misc.TestClient
  
  
  
  1.11      +6 -6      xml-axis/java/samples/stock/testit.cmd
  
  Index: testit.cmd
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/stock/testit.cmd,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- testit.cmd	2001/10/15 19:24:00	1.10
  +++ testit.cmd	2001/10/17 14:01:06	1.11
  @@ -1,22 +1,22 @@
   rem this assumes webserver is running on port 8080
   
  -echo First test the StockQuoteService.jws file
  +@echo First test the StockQuoteService.jws file
   java samples.stock.GetQuote -uuser1 -wpass1 XXX -s/axis/StockQuoteService.jws %*
   
  -echo Deploy everything first
  +@echo Deploy everything first
   java org.apache.axis.client.AdminClient deploy.xml %*
   
  -echo These next 2 should work...
  +@echo These next 2 should work...
   java samples.stock.GetQuote -uuser1 -wpass1 XXX %*
   java samples.stock.GetQuote -uuser2 XXX %*
   
  -echo The rest of these should fail... (nicely of course)
  +@echo The rest of these should fail... (nicely of course)
   java samples.stock.GetQuote XXX %*
   java samples.stock.GetQuote -uuser1 -wpass2 XXX %*
   java samples.stock.GetQuote -uuser3 -wpass3 XXX %*
   
  -echo This should work but print debug info on the client and server
  +@echo This should work but print debug info on the client and server
   java samples.stock.GetQuote -d -uuser1 -wpass1 XXX %*
   
  -echo Now undeploy everything
  +@echo Now undeploy everything
   java org.apache.axis.client.AdminClient undeploy.xml %*
  
  
  
  1.35      +1 -9      xml-axis/java/src/org/apache/axis/client/AdminClient.java
  
  Index: AdminClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/AdminClient.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- AdminClient.java	2001/10/15 19:24:00	1.34
  +++ AdminClient.java	2001/10/17 14:01:06	1.35
  @@ -224,15 +224,7 @@
               
               input.close();
               SOAPBodyElement body = (SOAPBodyElement) result.elementAt(0);
  -            StringWriter writer = new StringWriter();
  -            call.getEngine().addOption(AxisEngine.PROP_XML_DECL, 
  -                                       new Boolean(false));
  -            SerializationContext ctx = new SerializationContext(writer,
  -                                                  call.getMessageContext());
  -            ctx.setPretty(true);
  -            body.output(ctx);
  -            sb.append(writer.toString());
  -            sb.append('\n');
  +            sb.append( body.toString() );
           }
           
           return sb.toString();
  
  
  
  1.13      +40 -21    xml-axis/java/src/org/apache/axis/client/Call.java
  
  Index: Call.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Call.java	2001/10/16 13:25:52	1.12
  +++ Call.java	2001/10/17 14:01:06	1.13
  @@ -368,22 +368,25 @@
           /* If ALL of the params are SOAPBodyElements then we're doing       */
           /* Messaging, otherwise just fall through to normal RPC processing. */
           /********************************************************************/
  +        SOAPEnvelope  env = null ;
           int i ;
  +
           for ( i = 0 ; params != null && i < params.length ; i++ )
               if ( !(params[i] instanceof SOAPBodyElement) ) break ;
  +
           if ( i == params.length ) {
               /* ok, we're doing Messaging, so build up the message */
               /******************************************************/
  -            SOAPEnvelope env = new SOAPEnvelope();
  -            Message      msg = null ;
  +            env = new SOAPEnvelope();
               
               for ( i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ )
                   env.addHeader((SOAPHeader)myHeaders.get(i));
   
  -            for ( i = 0 ; i < params.length ; i++ )
  -                env.addBodyElement( (SOAPBodyElement) params[i] );
  +            if ( !(params[0] instanceof SOAPEnvelope) )
  +                for ( i = 0 ; i < params.length ; i++ )
  +                    env.addBodyElement( (SOAPBodyElement) params[i] );
   
  -            msg = new Message( env );
  +            Message msg = new Message( env );
               msgContext.setRequestMessage( msg );
   
               invoke();
  @@ -435,6 +438,38 @@
       /* End of core JAX-RPC stuff                                            */
       /************************************************************************/
   
  +    /** Invoke the service with a custom SOAPEnvelope.
  +     *
  +     * Note: Not part of JAX-RPC specification.
  +     *
  +     * @param env a SOAPEnvelope to send.
  +     * @exception AxisFault
  +     */
  +    public SOAPEnvelope invoke(SOAPEnvelope env) 
  +                                  throws java.rmi.RemoteException {
  +        try { 
  +            Message msg = null ;
  +            int     i ;
  +
  +            for ( i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ )
  +                env.addHeader((SOAPHeader)myHeaders.get(i));
  +
  +            msg = new Message( env );
  +            msgContext.setRequestMessage( msg );
  +            invoke();
  +            msg = msgContext.getResponseMessage();
  +            if ( msg == null ) return( null );
  +            return( msg.getAsSOAPEnvelope() );
  +        }
  +        catch( Exception exp ) {
  +            if ( exp instanceof AxisFault ) throw (AxisFault) exp ;
  +
  +            throw new AxisFault( "Error invoking operation",
  +                                                exp );
  +        }
  +    }
  +
  +
       /** Register a Transport that should be used for URLs of the specified
        * protocol.
        *
  @@ -723,21 +758,6 @@
        * Invocation
        */
   
  -    /** Invoke the service with a custom SOAPEnvelope.
  -     *
  -     * Note: Not part of JAX-RPC specification.
  -     *
  -     * @param env a SOAPEnvelope to send.
  -     * @exception AxisFault
  -     */
  -    public SOAPEnvelope invoke(SOAPEnvelope env) throws AxisFault
  -    {
  -        msgContext.reset();
  -        msgContext.setRequestMessage(new Message(env));
  -        invoke();
  -        return msgContext.getResponseMessage().getAsSOAPEnvelope();
  -    }
  -
       /** Invoke an RPC service with a method name and arguments.
        *
        * This will call the service, serializing all the arguments, and
  @@ -972,5 +992,4 @@
       {
           return this.outParams;
       }
  -
   }
  
  
  
  1.27      +15 -0     xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java
  
  Index: DeserializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DeserializationContext.java	2001/10/16 13:25:52	1.26
  +++ DeserializationContext.java	2001/10/17 14:01:06	1.27
  @@ -165,6 +165,21 @@
           inputSource = is;
       }
       
  +    public DeserializationContext(InputSource is, MessageContext ctx, 
  +                                  String messageType, SOAPEnvelope env)
  +    {
  +        EnvelopeBuilder builder = new EnvelopeBuilder(env, messageType);
  +        
  +        msgContext = ctx;
  +        
  +        envelope = builder.getEnvelope();
  +        envelope.setRecorder(recorder);
  +        
  +        pushElementHandler(new EnvelopeHandler(builder));
  +
  +        inputSource = is;
  +    }
  +    
       public void parse() throws SAXException
       {
           if (inputSource != null) {
  
  
  
  1.42      +14 -11    xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- SerializationContext.java	2001/10/16 13:25:52	1.41
  +++ SerializationContext.java	2001/10/17 14:01:06	1.42
  @@ -161,20 +161,23 @@
       {
           this.writer = writer;
           this.msgContext = msgContext;
  -        if (msgContext==null) throw new NullPointerException();
  -        AxisEngine engine = msgContext.getAxisEngine();
  -        Boolean shouldSendDecl = (Boolean)engine.getOption(
  +        // if (msgContext==null) throw new NullPointerException();
  +        AxisEngine engine = null ;
  +        if ( msgContext != null ) {
  +            engine = msgContext.getAxisEngine();
  +            Boolean shouldSendDecl = (Boolean)engine.getOption(
                                                     AxisEngine.PROP_XML_DECL);
  -        if (shouldSendDecl != null)
  -            sendXMLDecl = shouldSendDecl.booleanValue();
  -        Boolean shouldSendMultiRefs = (Boolean)engine.getOption(
  +            if (shouldSendDecl != null)
  +                sendXMLDecl = shouldSendDecl.booleanValue();
  +            Boolean shouldSendMultiRefs = (Boolean)engine.getOption(
                                                     AxisEngine.PROP_DOMULTIREFS);
  -        if (shouldSendMultiRefs != null)
  -            doMultiRefs = shouldSendMultiRefs.booleanValue();
  +            if (shouldSendMultiRefs != null)
  +                doMultiRefs = shouldSendMultiRefs.booleanValue();
   
  -        // Only turn this off is the user tells us to
  -        if ( !msgContext.isPropertyTrue(Call.SEND_TYPE_ATTR, true ) )
  -            sendXSIType = false ;
  +            // Only turn this off is the user tells us to
  +            if ( !msgContext.isPropertyTrue(Call.SEND_TYPE_ATTR, true ) )
  +                sendXSIType = false ;
  +        }
       }
   
       public void setSendDecl(boolean sendDecl)
  
  
  
  1.7       +7 -0      xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java
  
  Index: EnvelopeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EnvelopeBuilder.java	2001/10/03 15:30:05	1.6
  +++ EnvelopeBuilder.java	2001/10/17 14:01:06	1.7
  @@ -31,6 +31,13 @@
           myElement = envelope;
       }
       
  +    public EnvelopeBuilder(SOAPEnvelope env, String messageType)
  +    {
  +        envelope = env ;
  +        envelope.setMessageType(messageType);
  +        myElement = envelope;
  +    }
  +    
       public SOAPEnvelope getEnvelope()
       {
           return envelope;
  
  
  
  1.48      +17 -0     xml-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- MessageElement.java	2001/10/03 21:11:37	1.47
  +++ MessageElement.java	2001/10/17 14:01:06	1.48
  @@ -56,6 +56,7 @@
    */
   
   
  +import org.apache.axis.client.AxisClient;
   import org.apache.axis.Constants;
   import org.apache.axis.MessageContext;
   import org.apache.axis.encoding.DeserializationContext;
  @@ -431,4 +432,20 @@
           context.endElement();
       }
   
  +    public String toString() {
  +        try {
  +            StringWriter  writer = new StringWriter();
  +            SerializationContext context = null ;
  +            AxisClient     tmpEngine = new AxisClient(null);
  +            tmpEngine.addOption(tmpEngine.PROP_XML_DECL, new Boolean(false));
  +            MessageContext msgContext = new MessageContext(tmpEngine);
  +            context = new SerializationContext(writer, msgContext);
  +            this.output(context);
  +            return( writer.toString() );
  +        }
  +        catch( Exception exp ) {
  +            exp.printStackTrace();
  +            return( null );
  +        }
  +    }
   }
  
  
  
  1.37      +26 -1     xml-axis/java/src/org/apache/axis/message/SOAPEnvelope.java
  
  Index: SOAPEnvelope.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPEnvelope.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- SOAPEnvelope.java	2001/10/03 15:30:05	1.36
  +++ SOAPEnvelope.java	2001/10/17 14:01:06	1.37
  @@ -57,11 +57,18 @@
   
   import org.apache.axis.AxisFault;
   import org.apache.axis.Constants;
  +import org.apache.axis.Message;
  +import org.apache.axis.MessageContext;
   import org.apache.axis.encoding.SerializationContext;
  +import org.apache.axis.encoding.DeserializationContext;
   import org.apache.axis.utils.Mapping;
   import org.apache.axis.utils.QName;
   import org.xml.sax.helpers.AttributesImpl;
  +import org.xml.sax.InputSource;
  +import org.apache.axis.client.AxisClient ;
   
  +import java.io.InputStream ;
  +import java.io.StringWriter;
   import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Iterator;
  @@ -105,6 +112,22 @@
           
           setDirty(true);
       }
  +
  +    public SOAPEnvelope(InputStream input) {
  +        try {
  +            InputSource is = new InputSource(input);
  +            DeserializationContext dser = null ;
  +            AxisClient     tmpEngine = new AxisClient(null);
  +            MessageContext msgContext = new MessageContext(tmpEngine);
  +            dser = new DeserializationContext(is, msgContext,
  +                                              Message.REQUEST, this );
  +            dser.parse();
  +        }
  +        catch( Exception e ) {
  +            e.printStackTrace();
  +            throw new RuntimeException( e.toString() );
  +        }
  +    }
       
       public String getMessageType()
       {
  @@ -307,7 +330,9 @@
   
           if (bodyElements.isEmpty()) {
               // This is a problem.
  -            throw new Exception("No body elements!");
  +            // throw new Exception("No body elements!");
  +            // If there are no body elements just return - it's ok that
  +            // the body is empty
           }
   
           // Output <SOAP-ENV:Body>