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 gd...@apache.org on 2001/11/01 14:12:31 UTC

cvs commit: xml-axis/java/test/functional TestTCPTransportSample.java

gdaniels    01/11/01 05:12:31

  Modified:    java/samples/transport/tcp AdminClient.java TCPListener.java
               java/src/org/apache/axis/client AdminClient.java
               java/test/functional TestTCPTransportSample.java
  Log:
  Fix functional tests (manually deploy TCP transport for the nonce)
  
  Revision  Changes    Path
  1.10      +11 -3     xml-axis/java/samples/transport/tcp/AdminClient.java
  
  Index: AdminClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/transport/tcp/AdminClient.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AdminClient.java	2001/10/30 16:46:32	1.9
  +++ AdminClient.java	2001/11/01 13:12:31	1.10
  @@ -56,6 +56,7 @@
   package samples.transport.tcp ;
   
   import org.apache.axis.client.Call;
  +import org.apache.axis.SimpleTargetedChain;
   
   /**
    * An admin client object, which will work with the TCP transport.
  @@ -68,12 +69,19 @@
   public class AdminClient extends org.apache.axis.client.AdminClient {
   
       public static void main(String args[]) {
  -      
  +
           Call.addTransportPackage("samples.transport");
           Call.setTransportForProtocol("tcp", TCPTransport.class);
  -        
  +
           try {
  -            org.apache.axis.client.AdminClient.main(args);
  +            org.apache.axis.client.AdminClient client =
  +                new org.apache.axis.client.AdminClient(System.err);
  +
  +            SimpleTargetedChain c = new SimpleTargetedChain();
  +            c.setPivotHandler(new TCPSender());
  +            client.getCall().getEngine().deployTransport("tcp", c);
  +
  +            System.out.println(client.process(args));
           }
           catch( Exception e ) {
               System.err.println( e );
  
  
  
  1.11      +26 -26    xml-axis/java/samples/transport/tcp/TCPListener.java
  
  Index: TCPListener.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/transport/tcp/TCPListener.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TCPListener.java	2001/10/31 23:50:19	1.10
  +++ TCPListener.java	2001/11/01 13:12:31	1.11
  @@ -88,21 +88,21 @@
   
       // These have default values.
       private String transportName = "TCPTransport";
  -    
  +
       private static final String AXIS_ENGINE = "AxisEngine" ;
  -    
  +
       private int port;
       private ServerSocket srvSocket;
  -    
  +
       private AxisEngine engine = null ;
  -    
  +
       // becomes true when we want to quit
       private boolean done = false;
  -    
  +
       public static void main (String args[]) {
           new TCPListener(args).run();
       }
  -    
  +
       public TCPListener (String[] args) {
           // look for -p, -d arguments
           try {
  @@ -112,22 +112,22 @@
               category.error("Hosed URL: "+ex);
               System.exit(1);
           }
  -        
  +
           try {
               srvSocket = new ServerSocket(port);
           } catch (IOException ex) {
               category.error("Can't create server socket on port "+port);
               System.exit(1);
           }
  -        
  +
           category.info("TCPListener is listening on port "+port+".");
       }
  -    
  +
       public void run () {
           if (srvSocket == null) {
               return;
           }
  -        
  +
           Socket sock;
           while (!done) {
               try {
  @@ -142,8 +142,8 @@
               }
           }
       }
  -    
  -    
  +
  +
       public class SocketHandler implements Runnable {
           private Socket socket;
           public SocketHandler (Socket socket) {
  @@ -154,7 +154,7 @@
               if ( engine == null ) {
                   engine = new AxisServer();
                   engine.init();
  -                
  +
                   SimpleTargetedChain c = new SimpleTargetedChain();
                   c.setPivotHandler(new TCPSender());
   
  @@ -165,7 +165,7 @@
                       System.exit(-1);
                   }
               }
  -            
  +
               /* Place the Request message in the MessagContext object - notice */
               /* that we just leave it as a 'ServletRequest' object and let the  */
               /* Message processing routine convert it - we don't do it since we */
  @@ -173,7 +173,7 @@
               /* even need to be parsed.                                         */
               /*******************************************************************/
               MessageContext    msgContext = new MessageContext(engine);
  -            
  +
               InputStream inp;
               try {
                   inp = socket.getInputStream();
  @@ -181,7 +181,7 @@
                   category.error("Couldn't get input stream from "+socket);
                   return;
               }
  -            
  +
               // ROBJ 911
               // the plain ol' inputstream seems to hang in the SAX parse..... WHY?????
               // because there is no content length!
  @@ -198,7 +198,7 @@
                       category.error("Length line "+line+" was not terminated with \r\n");
                       return;
                   }
  -                
  +
                   // TEST SUPPORT ONLY
                   // If the line says "ping", then respond "\n".
                   // If the line says "quit", then respond "\n" and exit.
  @@ -215,18 +215,18 @@
                       category.error("AxisListener quitting.");
                       System.exit(0);
                   }
  -                
  -                
  +
  +
                   // OK, assume it is content length
                   int len = Integer.parseInt(line.toString());
                   // read that many bytes into ByteArrayInputStream...
  -                
  +
                   // experiment, doesn't work:
                   //        NonBlockingBufferedInputStream nbbinp = new NonBlockingBufferedInputStream();
                   //        nbbinp.setContentLength(len);
                   //        nbbinp.setInputStream(inp);
                   //        msg = new Message(nbbinp, "InputStream");
  -                
  +
                   byte[] mBytes = new byte[len];
                   inp.read(mBytes);
                   msg = new Message(new ByteArrayInputStream(mBytes));
  @@ -234,16 +234,16 @@
                   category.error("Couldn't read from socket input stream: "+ex);
                   return;
               }
  -            
  -            
  +
  +
               /* Set the request(incoming) message field in the context */
               /**********************************************************/
               msgContext.setRequestMessage( msg );
  -            
  +
               /* Set the Transport Specific Request/Response chains IDs */
               /******************************************************/
               msgContext.setTransportName(transportName);
  -            
  +
               try {
                   /* Invoke the Axis engine... */
                   /*****************************/
  @@ -254,7 +254,7 @@
                       e = new AxisFault( e );
                   msgContext.setResponseMessage( new Message((AxisFault)e) );
               }
  -            
  +
               /* Send it back along the wire...  */
               /***********************************/
               msg = msgContext.getResponseMessage();
  
  
  
  1.43      +27 -3     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.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- AdminClient.java	2001/10/31 23:50:19	1.42
  +++ AdminClient.java	2001/11/01 13:12:31	1.43
  @@ -59,7 +59,9 @@
   import org.apache.axis.message.SOAPBodyElement;
   import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.utils.Options;
  +import org.apache.log4j.Category;
   
  +import javax.xml.rpc.JAXRPCException;
   import java.io.ByteArrayInputStream;
   import java.io.FileInputStream;
   import java.io.IOException;
  @@ -83,13 +85,24 @@
   
   public class AdminClient
   {
  +    static Category category =
  +            Category.getInstance(AdminClient.class.getName());
  +
       protected PrintWriter _log;
  +    protected Call call;
   
       /**
        * Construct an admin client w/o a logger
        */
       public AdminClient()
       {
  +        try {
  +            Service service = new Service();
  +            call = (Call) service.createCall();
  +        } catch (JAXRPCException e) {
  +            category.fatal("Couldn't get a call", e);
  +            call = null;
  +        }
       }
   
       /**
  @@ -97,6 +110,7 @@
        */
       public AdminClient(PrintWriter log)
       {
  +        this();
           _log = log;
       }
   
  @@ -105,6 +119,7 @@
        */
       public AdminClient(OutputStream out)
       {
  +        this();
           _log = new PrintWriter(out);
       }
   
  @@ -121,6 +136,14 @@
       }
   
       /**
  +     * External access to our Call object
  +     */
  +    public Call getCall()
  +    {
  +        return call;
  +    }
  +
  +    /**
        * <p>Processes a set of administration commands.</p>
        * <p>The following commands are available:</p>
        * <ul>
  @@ -218,10 +241,11 @@
           return sb.toString();
       }
   
  -    public static String process(Options opts, InputStream input)  throws Exception
  +    public String process(Options opts, InputStream input)  throws Exception
       {
  -        Service service = new Service();
  -        Call    call = (org.apache.axis.client.Call) service.createCall();
  +        if (call == null) {
  +            throw new Exception("AdminClient did not initialize correctly: 'call' is null!");
  +        }
   
           call.setTargetEndpointAddress( new URL(opts.getURL()) );
           call.setProperty( HTTPConstants.MC_HTTP_SOAPACTION, "AdminService");
  
  
  
  1.13      +6 -0      xml-axis/java/test/functional/TestTCPTransportSample.java
  
  Index: TestTCPTransportSample.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/functional/TestTCPTransportSample.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestTCPTransportSample.java	2001/10/31 23:50:22	1.12
  +++ TestTCPTransportSample.java	2001/11/01 13:12:31	1.13
  @@ -58,12 +58,14 @@
   import junit.framework.AssertionFailedError;
   import junit.framework.TestCase;
   import org.apache.axis.AxisFault;
  +import org.apache.axis.SimpleTargetedChain;
   import org.apache.axis.client.Call;
   import org.apache.axis.client.Service;
   import org.apache.axis.encoding.XMLType;
   import org.apache.log4j.Category;
   import samples.transport.tcp.AdminClient;
   import samples.transport.tcp.GetQuote;
  +import samples.transport.tcp.TCPSender;
   
   import java.net.URL;
   
  @@ -96,6 +98,10 @@
   
               Service  service = new Service();
               Call     call    = (Call) service.createCall();
  +
  +            SimpleTargetedChain c = new SimpleTargetedChain();
  +            c.setPivotHandler(new TCPSender());
  +            call.getEngine().deployTransport("tcp", c);
   
               call.setTargetEndpointAddress( new URL("tcp://localhost:8088") );
               call.setOperationName( "getQuote" );