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/05/30 16:20:43 UTC

cvs commit: xml-axis/java/samples/transport FileReader.java FileSender.java FileTest.java client_deploy.xml deploy.xml

dug         01/05/30 07:20:43

  Added:       java/samples/transport FileReader.java FileSender.java
                        FileTest.java client_deploy.xml deploy.xml
  Log:
  Added a new test - tests a non-socket transport
  
  Revision  Changes    Path
  1.1                  xml-axis/java/samples/transport/FileReader.java
  
  Index: FileReader.java
  ===================================================================
  package samples.transport ;
  
  /*
   * 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/>.
   */
  
  import java.io.* ;
  import java.lang.Thread ;
  
  import org.apache.axis.Message ;
  import org.apache.axis.AxisFault ;
  import org.apache.axis.MessageContext ;
  import org.apache.axis.handlers.BasicHandler ;
  import org.apache.axis.server.AxisServer ;
  
  /**
   * Waits for the XML to appear in a file called xml#.req and writes
   * the response in a file called xml#.res
   *
   * @author Doug Davis (dug@us.ibm.com)
   */
  public class FileReader extends Thread {
    static int      nextNum = 1 ;
    static boolean  pleaseStop = false ;
  
    public void run() {
      String tmp = "" ;
      AxisServer  server = new AxisServer();
      server.init();
  
      while( !pleaseStop ) {
        try {
          Thread.sleep( 100 );
          File file = new File( "xml" + nextNum + ".req" );
          if ( !file.exists() ) continue ;
  
          Thread.sleep( 100 );   // let the other side finish writing
          FileInputStream fis = new FileInputStream( "xml" + nextNum + ".req" );
  
          Message msg = new Message( fis, "InputStream" );
          MessageContext  msgContext = new MessageContext();
          msgContext.setRequestMessage( msg );
  
          // SOAPAction hack
          byte[]  buf = new byte[50];
          fis.read( buf, 0, 50 );
          String action = new String( buf );
          msgContext.setTargetService( action.trim() );
          // end of hack
  
          server.invoke( msgContext );
          msg = msgContext.getResponseMessage();
          fis.close();
  
          (new File("xml" + nextNum + ".req" )).delete();
  
          FileOutputStream fos = new FileOutputStream( "xml" + nextNum + ".res" );
          buf = (byte[]) msg.getAs( "Bytes" );
          fos.write( buf );
          fos.close();
          nextNum++ ;
        }
        catch( Exception e ) {
          if ( !(e instanceof FileNotFoundException) )
            e.printStackTrace();
        }
      }
    }
  
    public void halt() {
      pleaseStop = true ;
    }
  }
  
  
  
  1.1                  xml-axis/java/samples/transport/FileSender.java
  
  Index: FileSender.java
  ===================================================================
  package samples.transport ;
  
  /*
   * 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/>.
   */
  
  import java.io.* ;
  import java.lang.Thread ;
  
  import org.apache.axis.Message ;
  import org.apache.axis.AxisFault ;
  import org.apache.axis.MessageContext ;
  import org.apache.axis.handlers.BasicHandler ;
  
  
  /**
   * Just write the XML to a file called xml#.req and wait for
   * the result in a file called xml#.res
   *
   * Not thread-safe - just a dummy sample to show that we can indeed use
   * something other than HTTP as the transport.
   *
   * @author Doug Davis (dug@us.ibm.com)
   */
  
  public class FileSender extends BasicHandler {
    static int nextNum = 1 ;
  
    public void invoke(MessageContext msgContext) throws AxisFault {
      Message  msg = msgContext.getRequestMessage();
      byte[]   buf = (byte[]) msg.getAs("Bytes");
      try {
        FileOutputStream fos = new FileOutputStream( "xml" + nextNum + ".req" );
  
        // Remove this SOAPAction hack once we support not having it 
        String tmp = msgContext.getTargetService();
        tmp += "                                              ";
        tmp = tmp.substring( 0, 50 );
        fos.write( tmp.getBytes() );
        // end of hack
  
        fos.write( buf );
        fos.close();
      }
      catch( Exception e ) {
        e.printStackTrace();
      }
      for (;;) {
        try {
          Thread.sleep( 100 );
          File file = new File( "xml" + nextNum + ".res" );
          if ( !file.exists() ) continue ;
  
          Thread.sleep( 100 );   // let the other side finish writing
          FileInputStream fis = new FileInputStream( "xml" + nextNum + ".res" );
          msg = new Message( fis, "InputStream" );
          msg.getAs("Bytes");  // just flush the buffer
          fis.close();
          Thread.sleep( 100 );
          (new File("xml" + nextNum + ".res")).delete();
          msgContext.setResponseMessage( msg );
          break ;
        }
        catch( Exception e ) {
          // File not there - just loop
        }
      }
      nextNum++ ;
    }
  
    public void undo(MessageContext msgContext) {
    }
  }
  
  
  
  1.1                  xml-axis/java/samples/transport/FileTest.java
  
  Index: FileTest.java
  ===================================================================
  package samples.transport ;
  
  import java.lang.Thread ;
  
  import org.apache.axis.AxisFault ;
  import org.apache.axis.client.* ;
  import org.apache.axis.utils.Debug ;
  import org.apache.axis.utils.Options ;
  import org.apache.axis.encoding.* ;
  
  /* Tests the simple File transport.  To run:
   *      java org.apache.axis.utils.Admin client client_deploy.xml
   *      java org.apache.axis.utils.Admin server deploy.xml
   *      java samples.transport.FileTest IBM
   *      java samples.transport.FileTest XXX
   */
  
  class FileTest {
    public static void main(String args[]) {
      FileReader  reader = new FileReader();
      reader.start();
  
      try {
        Options opts = new Options( args );
      
        Debug.setDebugLevel( opts.isFlagSet( 'd' ) );
      
        args = opts.getRemainingArgs();
      
        if ( args == null ) {
          System.err.println( "Usage: GetQuote <symbol>" );
          System.exit(1);
        }
      
        String   symbol = args[0] ;
        HTTPCall call   = new HTTPCall( opts.getURL(),
                                        "urn:xmltoday-delayed-quotes" );
        ServiceDescription sd = new ServiceDescription("stockQuotes", true);
        sd.addOutputParam("return", SOAPTypeMappingRegistry.XSD_FLOAT);
        call.setServiceDescription(sd);
      
        if ( opts.isFlagSet('t') > 0 ) call.doLocal = true ;
      
        call.setUserID( opts.getUser() );
        call.setPassword( opts.getPassword() );
        call.setTransportInput( "FileSender" );
      
        Float res = new Float(0.0F);
        res = (Float) call.invoke( "http://schemas.xmlsoap.org/soap/envelope/", 
                                   "getQuote",
                                   new Object[] {symbol} );
      
        System.out.println( symbol + ": " + res );
  
        // Once more just for fun...
        res = (Float) call.invoke( "http://schemas.xmlsoap.org/soap/envelope/", 
                                   "getQuote",
                                   new Object[] {symbol} );
      
        System.out.println( symbol + ": " + res );
      }
      catch( Exception e ) {
        if ( e instanceof AxisFault ) ((AxisFault)e).dump();
        e.printStackTrace();
      }
  
      reader.halt();
    }
  }
  
  
  
  1.1                  xml-axis/java/samples/transport/client_deploy.xml
  
  Index: client_deploy.xml
  ===================================================================
  <!-- Use this file to deploy some handlers/chains and services  -->
  <!-- on the client.  To do this simply run:                     -->
  <!--   java org.apache.axis.utils.Admin client_deploy.xml       -->
  <!--      from the same dir that the Axis client will run in    -->
  <!-- This file will be replaced by WSDD once it's ready         -->
  
  <deploy>
    <handler name="FileSender" class="samples.transport.FileSender" />
  </deploy>
  
  
  
  1.1                  xml-axis/java/samples/transport/deploy.xml
  
  Index: deploy.xml
  ===================================================================
  <!-- Use this file to deploy some handlers/chains and services  -->
  <!-- Two ways to do this:                                       -->
  <!--   java org.apache.axis.utils.Admin deploy.xml              -->
  <!--      from the same dir that the Axis engine runs           -->
  <!-- or                                                         -->
  <!--   java org.apache.axis.client.AdminClient deploy.xml       -->
  <!--      after the axis server is running                      -->
  <!-- This file will be replaced by WSDD once it's ready         -->
  
  <deploy>
    <handler name="authen"  class="org.apache.axis.handlers.SimpleAuthenticationHandler" />
    <handler name="author"  class="org.apache.axis.handlers.SimpleAuthorizationHandler" />
    <chain   name="checks"  flow="authen,author" />
    <chain   name="stock"   flow="checks,RPCDispatcher" />
  
    <service name="urn:xmltoday-delayed-quotes" pivot="stock" >
      <option name="className" value="samples.stock.StockQuoteService" />
      <option name="methodName" value="getQuote" />
    </service>
    <service name="urn:cominfo" pivot="rpc" >
      <option name="className" value="samples.stock.ComInfoService" />
      <option name="methodName" value="getInfo" />
    </service>
  </deploy>