axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/client HTTPCall.java
Date Sun, 06 May 2001 03:09:19 GMT
rubys       01/05/05 20:09:19

  Modified:    java/src/org/apache/axis/client HTTPCall.java
  Added:       java/samples/echo SOAPStruct.java SOAPStructSer.java
                        TestClient.java
  Log:
  Echo interop client
  
  Revision  Changes    Path
  1.1                  xml-axis/java/samples/echo/SOAPStruct.java
  
  Index: SOAPStruct.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 samples.echo;
   
  /**
   * Test structure used by the echo interop test.
   *
   * @author Sam Ruby <rubys@us.ibm.com>
   */
  public class SOAPStruct {
  
      // items of the structure.  Defined as Objects so as to permit nulls
      // Note: these need to be public in order to be directly set by the
      // deserializer.  Bean accessors are also provided for a potential
      // future BeanDeserializer.
      public Integer varInt;
      public String varString;
      public Float varFloat;
  
      /**
       * null constructor
       */
      public SOAPStruct() {}
  
      /**
       * convenience constructor that sets all of the fields
       */
      public SOAPStruct(int i, String s, float f) {
          this.varInt=new Integer(i);
          this.varString=s;
          this.varFloat=new Float(f);
      }
  
      /**
       * bean getter for VarInt
       */
      public Integer getVarInt() {
          return varInt;
      }
  
      /**
       * bean setter for VarInt
       */
      public void setVarInt (Integer varInt) {
          this.varInt=varInt;
      }
  
      /**
       * bean getter for VarString
       */
      public String getVarString() {
          return varString;
      }
  
      /**
       * bean setter for VarString
       */
      public void setVarString (String varString) {
          this.varString=varString;
      }
  
      /**
       * bean getter for VarFloat
       */
      public Float getVarFloat() {
          return varFloat;
      }
  
      /**
       * bean setter for VarFloat
       */
      public void setVarFloat (Float varFloat) {
          this.varFloat=varFloat;
      }
  
      /**
       * Equality comparison.  The implementation is very careful to
       * check for nulls.
       */
      public boolean equals(Object object) {
          if (!(object instanceof SOAPStruct)) return false;
  
          SOAPStruct that= (SOAPStruct) object;
  
          if (this.varInt == null) {
              if (that.varInt != null) return false;
          } else {
              if (!this.varInt.equals(that.varInt)) return false;
          }
  
          if (this.varString == null) {
              if (that.varString != null) return false;
          } else {
              if (!this.varString.equals(that.varString)) return false;
          }
  
          if (this.varFloat == null) {
              if (that.varFloat != null) return false;
          } else {
              if (!this.varFloat.equals(that.varFloat)) return false;
          }
  
          return true;
      };
  }
  
  
  
  1.1                  xml-axis/java/samples/echo/SOAPStructSer.java
  
  Index: SOAPStructSer.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 samples.echo;
  
  import java.io.IOException;
  import java.util.Hashtable;
  
  import org.apache.axis.encoding.*;
  import org.apache.axis.utils.QName;
  
  import org.xml.sax.*;
  
  /**
   * Test serializer/deserializerFactory for the SOAPStruct used by the
   * echo interop test.
   *
   * @author Glen Daniels <gdaniels@macromedia.com>
   * @author Sam Ruby <rubys@us.ibm.com>
   */
  public class SOAPStructSer extends DeserializerBase implements Serializer
  {
      public static final String INTEGERMEMBER = "varInt";
      public static final String STRINGMEMBER  = "varString";
      public static final String FLOATMEMBER   = "varFloat";
      public static final QName myTypeQName = new QName("typeNS", "SOAPStruct");
      
      public static class SOAPStructSerFactory implements DeserializerFactory {
          public DeserializerBase getDeserializer() {
              return new SOAPStructSer();
          }
      }
  
      public static DeserializerFactory getFactory() {
          return new SOAPStructSerFactory();
      }
      
      private Hashtable typesByMemberName = new Hashtable();  
      
      public SOAPStructSer() {
          typesByMemberName.put(INTEGERMEMBER, SOAPTypeMappingRegistry.XSD_INT);
          typesByMemberName.put(STRINGMEMBER, SOAPTypeMappingRegistry.XSD_STRING);
          typesByMemberName.put(FLOATMEMBER, SOAPTypeMappingRegistry.XSD_FLOAT);
          value = new SOAPStruct();
      }
      
      /** DESERIALIZER STUFF - event handlers
       */
      
      public void onStartChild(String namespace, String localName,
                               String qName, Attributes attributes)
          throws SAXException
      {
          QName typeQName = (QName)typesByMemberName.get(localName);
          if (typeQName == null)
              throw new SAXException("Invalid element in SOAPStruct struct - " + localName);
          
          // These can come in either order.
          DeserializerBase dSer = context.getDeserializer(typeQName);
          dSer.registerValueTarget(value, localName);
          
          if (dSer == null)
              throw new SAXException("No deserializer for a " + typeQName + "???");
          
          context.pushElementHandler(dSer);
      }
      
      /** SERIALIZER STUFF
       */
      
      public void serialize(QName name, Attributes attributes,
                            Object value, SerializationContext context)
          throws IOException
      {
          if (!(value instanceof SOAPStruct))
              throw new IOException("Can't serialize a " + value.getClass().getName() + "
with a SOAPStructSerializer.");
          SOAPStruct data = (SOAPStruct)value;
          
          context.startElement(name, attributes);
          context.serialize(new QName("", INTEGERMEMBER), null, data.varInt);
          context.serialize(new QName("", STRINGMEMBER), null, data.varString);
          context.serialize(new QName("", FLOATMEMBER), null, data.varFloat);
          context.endElement();
      }
  }
  
  
  
  1.1                  xml-axis/java/samples/echo/TestClient.java
  
  Index: TestClient.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 samples.echo ;
  
  import org.apache.axis.AxisFault ;
  import org.apache.axis.client.HTTPCall ;
  import org.apache.axis.encoding.SOAPTypeMappingRegistry;
  import org.apache.axis.encoding.ServiceDescription;
  import org.apache.axis.encoding.TypeMappingRegistry;
  import org.apache.axis.utils.Options ;
  import org.apache.axis.utils.QName ;
  
  /**
   * Test Client for the echo interop service.  See the main entrypoint
   * for more details on usage.
   *
   * @author Sam Ruby <rubys@us.ibm.com>
   */
  public class TestClient {
  
      private static HTTPCall call;
      private static TypeMappingRegistry map = new SOAPTypeMappingRegistry();
  
      /**
       * Test an echo method.  Declares success if the response returns
       * true with an Object.equal comparison with the object to be sent.
       * @param method name of the method to invoke
       * @param toSend object of the correct type to be sent
       */
      public static void test(String method, Object toSend) {
  
          try {
              // Default return type based on what we expect
              ServiceDescription sd = new ServiceDescription(method, true);
              sd.addOutputParam("return", map.getTypeQName(toSend.getClass()));
              call.setServiceDescription(sd);
  
              // issue the request
              Object gotBack = call.invoke(
                  "http://soapinterop.org/", method, new Object[] {toSend} );
  
              // verify the result
              if (toSend.equals(gotBack)) {
                  System.out.println(method + "\t OK");
              } else {
                  System.out.println(method + "\t FAIL: " + gotBack);
              }
          } catch (Exception e) {
             System.out.println(method + "\t FAIL: " + e);
          }
      }
  
      /**
       * Main entry point.  Tests a variety of echo methods and reports
       * on their results.
       *
       * Arguments are of the form:
       *   -h localhost -p 8080 -s /soap/servlet/rpcrouter
       */
      public static void main(String args[]) throws Exception {
          // set up the call object
          Options opts = new Options(args);
          call = new HTTPCall(opts.getURL(), "http://soapinterop.org/");
  
          // register the SOAPStruct class
          QName ssqn = new QName("http://soapinterop.org/xsd", "SOAPStruct");
          call.addSerializer(SOAPStruct.class, ssqn, new SOAPStructSer());
          call.addDeserializerFactory(ssqn, SOAPStruct.class,
                                      SOAPStructSer.getFactory());
  
          // execute the tests
          test("echoString", "abdefg");
          test("echoFloat", new Float(3.7F));
          test("echoInteger", new Integer(42));
          test("echoStruct", new SOAPStruct(5, "Hello", 10.3F));
      }
  
  }
  
  
  
  1.26      +18 -1     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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- HTTPCall.java	2001/05/05 22:16:55	1.25
  +++ HTTPCall.java	2001/05/06 03:09:19	1.26
  @@ -66,6 +66,9 @@
   import org.apache.axis.* ;
   import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.transport.http.HTTPDispatchHandler;
  +import org.apache.axis.encoding.Serializer;
  +import org.apache.axis.encoding.TypeMappingRegistry;
  +import org.apache.axis.encoding.DeserializerFactory;
   
   import org.w3c.dom.* ;
   
  @@ -92,19 +95,23 @@
     private String  passwd ;
     private String  encodingStyleURI ;
     private ServiceDescription serviceDesc;
  +  private MessageContext msgContext;
   
     // For testing
     public  boolean doLocal = false ;
     private static final boolean DEBUG_LOG = false;
   
     public HTTPCall() {
  +    msgContext = new MessageContext();
     }
   
     public HTTPCall(String url) {
       this.url = url ;
  +    msgContext = new MessageContext();
     }
   
     public HTTPCall(String url, String action) {
  +    msgContext = new MessageContext();
       setURL( url );
       setAction( action );
     }
  @@ -146,6 +153,17 @@
       this.serviceDesc = serviceDesc;
     }
   
  +  public void addSerializer(Class _class, QName qName, Serializer serializer) {
  +    TypeMappingRegistry typeMap = msgContext.getTypeMappingRegistry();
  +    typeMap.addSerializer(_class, qName, serializer);
  +  }
  +    
  +  public void addDeserializerFactory(QName qName, Class _class,
  +                                     DeserializerFactory deserializerFactory) {
  +    TypeMappingRegistry typeMap = msgContext.getTypeMappingRegistry();
  +    typeMap.addDeserializerFactory(qName, _class, deserializerFactory);
  +  }
  +
     public static Object invoke(String url, String act, String m, Object[] args) 
         throws AxisFault
     {
  @@ -169,7 +187,6 @@
       HTTPMessage          hMsg   = new HTTPMessage( url, action );
       Message              reqMsg = new Message( reqEnv, "SOAPEnvelope" );
       Message              resMsg = null ;
  -    MessageContext       msgContext =  new MessageContext();
       Vector               resBodies = null ;
       Vector               resArgs = null ;
       Object               result = null ;
  
  
  

Mime
View raw message