axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Glen Daniels" <gdani...@macromedia.com>
Subject Re: cvs commit: xml-axis/java/test/functional TestMessageSample.java FunctionalTests.java
Date Mon, 17 Dec 2001 14:01:42 GMT
First, a nit.  Vector is synchronized, which slows it down versus ArrayList.
In situations where multiple threads aren't sharing the object in question,
there's usually no reason to take the performance hit.

Second, while I'm all for supporting an array of Elements, could we still
support the method(Element) case as well?  We could look for (Element[])
first and if not found try (Element) sending elements[0] as a convenience
(which also saves backwards compatibility for those already doing this).

And on a totally different cleanup-related note, I think we can safely
remove the "MessageContext as first argument" syntax now that we've put
alpha-3 out.  Not to mention getting rid of addOption() and
ServiceClient....

--G

----- Original Message -----
From: <dug@apache.org>
To: <xml-axis-cvs@apache.org>
Sent: Sunday, December 16, 2001 7:57 PM
Subject: cvs commit: xml-axis/java/test/functional TestMessageSample.java
FunctionalTests.java


> dug         01/12/16 16:57:41
>
>   Modified:    java/src/org/apache/axis/providers/java MsgProvider.java
>                java/src/org/apache/axis/utils Admin.java
>                java/test/functional FunctionalTests.java
>   Added:       java/samples/message MessageService.java deploy.wsdd
>                         testMessage.java undeploy.wsdd
>                java/test/functional TestMessageSample.java
>   Log:
>   Java has a bit of an "issue" in that you can ask for
>   (Element[]).class but you can't ask a ClassLoader to
>   actually load that class - so you can't dynamically invoke
>   a method with Element[] as one of its parameters when the
>   array of Class's is supposed to have been loaded from a particular
>   classloader (or at least I couldn't figure out how to do it).
>   So switched everything from Element[] to Vector, and added
>   a test for it.
>
>   Revision  Changes    Path
>   1.1                  xml-axis/java/samples/message/MessageService.java
>
>   Index: MessageService.java
>   ===================================================================
>   package samples.message ;
>
>   import org.w3c.dom.Element ;
>   import org.apache.axis.MessageContext ;
>   import java.util.Vector ;
>
>   public class MessageService {
>       public Element[] echoElements(MessageContext msgC, Vector elems) {
>           Element[]  result = new Element[elems.size()];
>
>           for ( int i = 0 ; i < elems.size() ; i++ )
>               result[i] = (Element) elems.get(i);
>
>           return( result );
>       }
>   }
>
>
>
>   1.1                  xml-axis/java/samples/message/deploy.wsdd
>
>   Index: deploy.wsdd
>   ===================================================================
>   <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"
>
> xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
>               xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
>     <service name="MessageService" provider="java:MSG">
>       <parameter name="className" value="samples.message.MessageService"
> />
>       <parameter name="methodName" value="echoElements" />
>     </service>
>   </deployment>
>
>
>
>   1.1                  xml-axis/java/samples/message/testMessage.java
>
>   Index: testMessage.java
>   ===================================================================
>   package samples.message ;
>
>   import org.apache.axis.client.Service;
>   import org.apache.axis.client.Call;
>   import org.apache.axis.message.SOAPBodyElement;
>   import org.apache.axis.utils.Options;
>   import org.apache.axis.utils.XMLUtils;
>   import org.w3c.dom.Element;
>   import java.net.URL;
>   import java.util.Vector ;
>
>   public class testMessage {
>       public String doit(String[] args) throws Exception {
>           Options opts = new Options(args);
>
> opts.setDefaultURL("http://localhost:8080/axis/services/MessageService")
> ;
>
>           Service  service = new Service();
>           Call     call    = (Call) service.createCall();
>
>           call.setTargetEndpointAddress( new URL(opts.getURL()) );
>           SOAPBodyElement[] input = new SOAPBodyElement[2];
>
>           input[0] = new
> SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
>                                                                   "e1",
> "Hello"));
>           input[1] = new
> SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
>                                                                   "e1",
> "World"));
>
>           Vector          elems = (Vector) call.invoke( input );
>           SOAPBodyElement elem  = null ;
>           Element         e     = null ;
>
>           elem = (SOAPBodyElement) elems.get(0);
>           e    = elem.getAsDOM();
>
>           String str = "Res elem[0]=" + XMLUtils.ElementToString(e);
>
>           elem = (SOAPBodyElement) elems.get(1);
>           e    = elem.getAsDOM();
>           str = str + "Res elem[1]=" + XMLUtils.ElementToString(e);
>
>           return( str );
>       }
>
>       public static void main(String[] args) throws Exception {
>           String res = (new testMessage()).doit(args);
>           System.out.println(res);
>       }
>   }
>
>
>
>   1.1                  xml-axis/java/samples/message/undeploy.wsdd
>
>   Index: undeploy.wsdd
>   ===================================================================
>   <undeployment name="test" xmlns="http://xml.apache.org/axis/wsdd/">
>     <service name="MessageService"/>
>   </undeployment>
>
>
>
>   1.20      +22 -12
> xml-axis/java/src/org/apache/axis/providers/java/MsgProvider.java
>
>   Index: MsgProvider.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/providers/java/MsgProvider.j
> ava,v
>   retrieving revision 1.19
>   retrieving revision 1.20
>   diff -u -r1.19 -r1.20
>   --- MsgProvider.java 2001/12/16 18:22:48 1.19
>   +++ MsgProvider.java 2001/12/17 00:57:41 1.20
>   @@ -120,6 +120,11 @@
>
>                doc = reqBody.getAsDOM().getOwnerDocument();
>
>   +            Vector newBodies = new Vector();
>   +            for (int i = 0 ; i < bodies.size() ; i++ )
>   +                newBodies.add(
> ((SOAPBodyElement)bodies.get(i)).getAsDOM() );
>   +            bodies = newBodies ;
>   +
>                /* If no methodName was specified during deployment then
> get it */
>                /* from the root of the Body element
> */
>                /* Hmmm, should we do this????
> */
>   @@ -134,13 +139,17 @@
>
> /////////////////////////////////////////////////////////////////
>                argClasses = new Class[1];
>                argObjects = new Object[1];
>   -            // argClasses[0] =
> clsLoader.loadClass("org.w3c.dom.Element");
>   -            // argClasses[0] =
> clsLoader.loadClass(Element[].class.getName()) ;
>   -            argClasses[0] = Element[].class ;
>   -            argObjects[0] = bodies.toArray();
>   +            argClasses[0] = clsLoader.loadClass("java.util.Vector");
>   +            argObjects[0] = bodies ;
>
>                try {
>                  method = jc.getJavaClass().getMethod( methodName,
> argClasses );
>   +              Element[] result = (Element[]) method.invoke( obj,
> argObjects );
>   +              if ( result != null ) {
>   +                  for ( int i = 0 ; i < result.length ; i++ )
>   +                      resEnv.addBodyElement( new
> SOAPBodyElement(result[i]));
>   +              }
>   +              return ;
>                }
>                catch( NoSuchMethodException exp ) {exp2 = exp;}
>
>   @@ -149,18 +158,19 @@
>
> /////////////////////////////////////////////////////////////////
>                  argClasses = new Class[2];
>                  argObjects = new Object[2];
>   -              // argClasses[0] =
> clsLoader.loadClass("org.w3c.dom.Element");
>   -              // argClasses[0] =
> clsLoader.loadClass(Element[].class.getName()) ;
>                  argClasses[0] =
> clsLoader.loadClass("org.apache.axis.MessageContext");
>   -              argClasses[1] = Element[].class ;
>   +              argClasses[1] =
> clsLoader.loadClass("java.util.Vector");
>                  argObjects[0] = msgContext ;
>   -              Element[] els = new Element[bodies.size()];
>   -              for ( int j = 0 ; j < bodies.size() ; j++ )
>   -                  els[j] =
> ((SOAPBodyElement)bodies.get(j)).getAsDOM();
>   -              argObjects[1] = els ;
>   -
>   +              argObjects[1] = bodies ;
>   +
>                  try {
>                    method = jc.getJavaClass().getMethod( methodName,
> argClasses );
>   +                Element[] result = (Element[]) method.invoke( obj,
> argObjects );
>   +                if ( result != null ) {
>   +                    for ( int i = 0 ; i < result.length ; i++ )
>   +                        resEnv.addBodyElement( new
> SOAPBodyElement(result[i]));
>   +                }
>   +                return ;
>                  }
>                  catch( NoSuchMethodException exp ) {exp2 = exp;}
>                }
>
>
>
>   1.92      +5 -3
> xml-axis/java/src/org/apache/axis/utils/Admin.java
>
>   Index: Admin.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/utils/Admin.java,v
>   retrieving revision 1.91
>   retrieving revision 1.92
>   diff -u -r1.91 -r1.92
>   --- Admin.java 2001/12/16 18:19:50 1.91
>   +++ Admin.java 2001/12/17 00:57:41 1.92
>   @@ -171,13 +171,15 @@
>        /**
>         * Process a given XML document - needs cleanup.
>         */
>   -    public Document AdminService(MessageContext msgContext, Element[]
> xml)
>   +    public Element[] AdminService(MessageContext msgContext, Vector
> xml)
>            throws AxisFault
>        {
>            category.debug(JavaUtils.getMessage("enter00",
> "Admin:AdminService") );
>   -        Document doc = process( msgContext, xml[0] );
>   +        Document doc = process( msgContext, (Element) xml.get(0) );
>   +        Element[] result = new Element[1];
>   +        result[0] = doc.getDocumentElement();
>            category.debug(JavaUtils.getMessage("exit00",
> "Admin:AdminService") );
>   -        return( doc );
>   +        return( result );
>        }
>
>        /** Process an engine configuration file by deploying appropriate
> stuff
>
>
>
>   1.15      +3 -0
> xml-axis/java/test/functional/FunctionalTests.java
>
>   Index: FunctionalTests.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/test/functional/FunctionalTests.java,v
>   retrieving revision 1.14
>   retrieving revision 1.15
>   diff -u -r1.14 -r1.15
>   --- FunctionalTests.java 2001/12/12 14:02:28 1.14
>   +++ FunctionalTests.java 2001/12/17 00:57:41 1.15
>   @@ -46,6 +46,9 @@
>            // Element service test.
>            suite.addTestSuite(TestElementSample.class);
>
>   +        // Message service test.
>   +        suite.addTestSuite(TestMessageSample.class);
>   +
>            return suite;
>        }
>    }
>
>
>
>   1.1
> xml-axis/java/test/functional/TestMessageSample.java
>
>   Index: TestMessageSample.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 test.functional;
>
>   import junit.framework.TestCase;
>   import org.apache.axis.AxisFault;
>   import org.apache.axis.client.AdminClient;
>   import org.apache.log4j.Category;
>   import samples.message.testMessage;
>
>   /** Test the message sample code.
>    */
>   public class TestMessageSample extends TestCase {
>       static Category category =
>               Category.getInstance(TestMessageSample.class.getName());
>
>       public TestMessageSample(String name) {
>           super(name);
>       }
>
>       public void doTestDeploy() throws Exception {
>           String[] args = { "samples/message/deploy.wsdd" };
>           AdminClient.main(args);
>       }
>
>       public void doTestMessage() throws Exception {
>           String[] args = { };
>           String res = (new testMessage()).doit(args);
>           String expected="Res elem[0]=<ns1:e1
> xmlns:ns1=\"urn:foo\">Hello</ns1:e1>Res elem[1]=<ns2:e1
> xmlns:ns2=\"urn:foo\">World</ns2:e1>";
>           assertEquals("test result elements", res, expected);
>       }
>
>       public void doTestUndeploy () throws Exception {
>           String[] args = { "samples/message/undeploy.wsdd" };
>           AdminClient.main(args);
>       }
>
>       public static void main(String args[]) throws Exception {
>           TestMessageSample tester = new TestMessageSample("tester");
>           tester.testMessageService();
>       }
>
>       public void testMessageService () throws Exception {
>           try {
>               category.info("Testing message sample.");
>               category.info("Testing deployment...");
>               doTestDeploy();
>               category.info("Testing service...");
>               doTestMessage();
>               doTestUndeploy();
>               category.info("Test complete.");
>           }
>           catch( Exception e ) {
>               if ( e instanceof AxisFault ) ((AxisFault)e).dump();
>               e.printStackTrace();
>               throw new Exception("Fault returned from test: "+e);
>           }
>       }
>
>   }
>
>
>
>
>
>


Mime
View raw message