You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2009/12/04 08:17:04 UTC

svn commit: r887087 [3/3] - in /tomcat/trunk/modules/tomcat-lite: java/org/apache/tomcat/lite/http/ java/org/apache/tomcat/lite/io/ java/org/apache/tomcat/lite/proxy/ java/org/apache/tomcat/lite/servlet/ test/org/apache/coyote/lite/ test/org/apache/tom...

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/BBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/BBuffer.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/BBuffer.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/BBuffer.java Fri Dec  4 07:16:59 2009
@@ -330,11 +330,11 @@
         return true;
     }
 
-    public byte get(int off) {
+    public int get(int off) {
         if (start + off >= end) {
             throw new ArrayIndexOutOfBoundsException();
         }
-        return buff[start + off];
+        return buff[start + off] & 0xFF;
     }
 
     /** 
@@ -495,7 +495,10 @@
 //        }
 //        return true;
 //    }
-
+    public int indexOf(String src) {
+        return indexOf(src, 0, src.length(), 0);
+    }
+    
     public int indexOf(String src, int srcOff, int srcLen, int myOff) {
         char first = src.charAt(srcOff);
 
@@ -635,7 +638,9 @@
         return start;
     }
 
-    
+    public void advance(int len) {
+        start += len;
+    }
 
     @Override
     public void position(int newStart) {
@@ -647,6 +652,11 @@
         buff[end++] = b;
     }
 
+    public void putByte(int b) {
+        makeSpace(1);
+        buff[end++] = (byte) b;
+    }
+
     public int read(BBuffer res) {
         res.setBytes(buff, start, remaining());
         end = start;
@@ -899,19 +909,17 @@
         }
     }
 
-    public int substract() {
-
-        if ((end - start) == 0) {
+    public int read() {
+        if (end  == start) {
             return -1;
         }
-
         return (buff[start++] & 0xFF);
 
     }
 
     public int substract(BBuffer src) {
 
-        if ((end - start) == 0) {
+        if (end == start) {
             return -1;
         }
 
@@ -945,7 +953,7 @@
     public String toString(String enc) {
         if (null == buff) {
             return null;
-        } else if (end - start == 0) {
+        } else if (end == start) {
             return "";
         }
         
@@ -1188,6 +1196,6 @@
             super.setBytesInternal(b, off, len);
         }
     }
-    
+
     
 }

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/CBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/CBuffer.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/CBuffer.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/CBuffer.java Fri Dec  4 07:16:59 2009
@@ -162,6 +162,12 @@
         return this;
     }
 
+    public CBuffer append(int i) {
+        // TODO: can be optimizeed...
+        append(Integer.toString(i));
+        return this;
+    }
+
     /**
      * Add data to the buffer
      */
@@ -261,7 +267,13 @@
         return this;
     }
     
-    
+
+    public void toAscii(BBuffer bb) {
+        for (int i = start; i < end; i++) {
+            bb.append(value[i]);
+        }
+    }
+
     /**
      *  Append and advance CharBuffer.
      * 

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/DumpChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/DumpChannel.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/DumpChannel.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/DumpChannel.java Fri Dec  4 07:16:59 2009
@@ -2,7 +2,10 @@
  */
 package org.apache.tomcat.lite.io;
 
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 
 // TODO: dump to a file, hex, etc.
 /**
@@ -12,6 +15,7 @@
     
     IOBuffer in = new IOBuffer(this);
     IOBuffer out = new IOBuffer(this);
+    static final boolean dumpToFile = false;
     
     public DumpChannel(String id) {
         this.id = id;
@@ -65,7 +69,9 @@
         }
     }
     
-    private void out(String dir, BBucket first, boolean closed) {
+    static int did = 0;
+    
+    protected void out(String dir, BBucket first, boolean closed) {
         // Dump
         if (first != null) {
             String hd = Hex.getHexDump(first.array(), first.position(), 
@@ -76,9 +82,18 @@
                     hd);
         } else {
             System.err.println("\n" + dir + ": " + id + " " +
-                    (closed ? "CLS" : "") +
+                    (closed ? "CLS " : "") +
                      "END\n"); 
         }
+        if (dumpToFile && first != null) {
+            try {
+                OutputStream os = new FileOutputStream("dmp" + did++);
+                os.write(first.array(), first.position(), first.remaining());
+                os.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            } 
+        }
     }
     
     @Override

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOBuffer.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOBuffer.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOBuffer.java Fri Dec  4 07:16:59 2009
@@ -63,7 +63,6 @@
     
     // ===== Buffer access =====
     
-    BBucket first;
     
     /**
      * Return first non-empty buffer.
@@ -88,7 +87,6 @@
                     buffers.removeFirst();
                     o = (buffers.size() == 0) ? null : buffers.getFirst();                    
                 } else {
-                    first = o;
                     return o;
                 }
             }
@@ -103,7 +101,18 @@
     
 
     public void advance(int len) {
-        first.position(first.position() + len);
+        while (len > 0) {
+            BBucket first = peekFirst();
+            if (first == null) {
+                return;
+            }
+            if (len > first.remaining()) {
+                len -= first.remaining();
+                first.position(first.limit());
+            } else {
+                first.position(first.position() + len);                
+            }
+        }
     }
 
     public void queue(String s) throws IOException {
@@ -250,16 +259,21 @@
     // =================== Helper methods ==================
 
     /**
-     * Non-blocking.
+     * Non-blocking read.
+     * 
+     * @return -1 if EOF, -2 if no data available, or 0..255 for normal read.
      */
     public int read() throws IOException {
+        if (isClosedAndEmpty()) {
+            return -1;
+        }
         BBucket bucket = peekFirst();
         if (bucket == null) {
-            return -1;
+            return -2;
         }
         int res = bucket.array()[bucket.position()];
         bucket.position(bucket.position() + 1);
-        return res;
+        return res & 0xFF;
     }
     
     public int peek() throws IOException {
@@ -348,6 +362,16 @@
         
     }
 
+    public int read(BBuffer bb, int len) throws IOException {
+        bb.makeSpace(len);
+        int rd = read(bb.array(), bb.limit(), len);
+        if (rd < 0) {
+            return rd;
+        }
+        bb.limit(bb.limit() + rd);
+        return rd;
+    }
+    
     /**
      * Non-blocking read.
      */
@@ -478,23 +502,35 @@
                 cs.remaining());
     }
     
+    /**
+     *  Append a buffer. The buffer will not be modified.
+     */
     public IOBuffer append(BBucket cs) throws IOException {
         append(cs.array(), cs.position(), cs.remaining());
         return this;
     }
-    
+
+    /**
+     *  Append a buffer. The buffer will not be modified.
+     */
+    public IOBuffer append(BBucket cs, int len) throws IOException {
+        append(cs.array(), cs.position(), len);
+        return this;
+    }
+
     public IOBuffer append(IOBuffer cs) throws IOException {
         for (int i = 0; i < cs.getBufferCount(); i++) {
-            Object o = cs.peekBucket(i);
-            if (o instanceof BBucket) {
-                append((BBucket)o);
-            } else if (o instanceof ByteBuffer) {
-                append((ByteBuffer) o);
-            } else if (o instanceof CharSequence) {
-                append((CharSequence) o);                
-            } else {
-                throw new IOException("Unknown type " + o);
-            }
+            BBucket o = cs.peekBucket(i);
+            append(o);
+        }
+
+        return this;        
+    }
+
+    public IOBuffer append(IOBuffer cs, int len) throws IOException {
+        for (int i = 0; i < cs.getBufferCount(); i++) {
+            BBucket o = cs.peekBucket(i);
+            append(o);
         }
 
         return this;        
@@ -505,7 +541,7 @@
         append(data, 0, data.length);
         return this;
     }
-    
+
     public IOBuffer append(char c) throws IOException {
         ByteBuffer bb = getWriteBuffer();
         bb.put((byte) c);
@@ -571,16 +607,14 @@
             if (closeQueued) {
                 throw new IOException("Closed");
             }
-            synchronized (buffers) {
-                BBucket last = (buffers.size() == 0) ? 
-                        null : buffers.getLast();
-                if (last == null || last != appendable ||
-                        last.array().length - last.limit() < 16) {
-                    last = BBuffer.allocate(ALLOC_SIZE);
-                }
-                appending = true;
-                appendable = (BBuffer) last;            
+            BBucket last = (buffers.size() == 0) ? 
+                    null : buffers.getLast();
+            if (last == null || last != appendable ||
+                    last.array().length - last.limit() < 16) {
+                last = BBuffer.allocate(ALLOC_SIZE);
             }
+            appending = true;
+            appendable = (BBuffer) last;            
             
             if (writeBuffer == null || writeBuffer.array() != appendable.array()) {
                 writeBuffer = ByteBuffer.wrap(appendable.array());
@@ -592,10 +626,10 @@
     }        
     
     public void releaseWriteBuffer(int read) throws IOException {
-        if (!appending) {
-            throw new IOException("Not appending");
-        }
         synchronized (buffers) {
+            if (!appending) {
+                throw new IOException("Not appending");
+            }
             if (writeBuffer != null) {
                 if (read > 0) {
                     appendable.limit(writeBuffer.position());
@@ -607,8 +641,8 @@
                     notifyDataAvailable(appendable);                
                 }
             }
+            appending = false;
         }
-        appending = false;
     }
 
     

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOChannel.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOChannel.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOChannel.java Fri Dec  4 07:16:59 2009
@@ -158,7 +158,7 @@
         }
     }
 
-    public void setSink(IOChannel previous) {
+    public void setSink(IOChannel previous) throws IOException {
         this.net = previous;
     }
 
@@ -170,8 +170,9 @@
     
     /** 
      * Called to add an filter _after_ the current channel.
+     * @throws IOException 
      */
-    public IOChannel addFilterAfter(IOChannel next) {
+    public IOChannel addFilterAfter(IOChannel next) throws IOException {
         this.app = next;
         app.setSink(this);
 
@@ -182,6 +183,9 @@
 
         dataReceivedCallback = null;
         dataFlushedCallback = null;
+        
+        // we may have data in our buffers
+        next.handleReceived(this);
         return this;
     }
 

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOConnector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOConnector.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOConnector.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/IOConnector.java Fri Dec  4 07:16:59 2009
@@ -33,8 +33,9 @@
         throws IOException; 
 
     // TODO: failures ? 
+    // TODO: use String target or url
     public abstract void connect(String host, int port, 
-                                      IOConnector.ConnectedCallback sc) throws IOException;
+            IOConnector.ConnectedCallback sc) throws IOException;
     
     public void stop() {
         

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioChannel.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioChannel.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioChannel.java Fri Dec  4 07:16:59 2009
@@ -79,7 +79,6 @@
         .append(readInterest ? "R/" : "")
         .append(outClosed ? "Out-CLOSE/" : "")
         .append(inClosed ? "In-CLOSE/" : "")
-        .append(selKey == null ? -1 : ((SelectionKey) (selKey)).interestOps())
         .append("/")
         .append(channel.toString());
         

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioThread.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioThread.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioThread.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/NioThread.java Fri Dec  4 07:16:59 2009
@@ -104,7 +104,7 @@
   // time events.
   private long minSleep = 100;
 
-  boolean daemon = true;
+  boolean daemon = false;
   
   // TODO: trace log - record all events with timestamps, replay
 
@@ -408,7 +408,7 @@
               ch.callback.handleConnected(ch);
           }
       } catch (Throwable t) {
-          log.warning("Error in connect, closing ");
+          log.warning("Error in connect, closing " + t);
           close(ch, t);
           try {
               if (ch.callback != null) {
@@ -463,6 +463,9 @@
       if (channel instanceof SocketChannel) {
           SocketChannel sc = (SocketChannel) channel;
           if (sc.isOpen() && sc.isConnected()) {
+              if (debug) {
+                  log.info("Half shutdown " + ch);
+              }
               sc.socket().shutdownOutput(); // TCP end to the other side
           }
       }
@@ -499,7 +502,9 @@
                   SocketChannel sc = (SocketChannel) channel;
 
                   if (sc.isConnected()) {
-                      //System.err.println("Close socket, opened=" + o);
+                      if (debug) {
+                          log.info("Close socket, opened=" + o);
+                      }
                       try {
                           sc.socket().shutdownInput();
                       } catch(IOException io1) {
@@ -526,8 +531,7 @@
               }
       }
       } catch (IOException ex2) {
-          log.severe("SelectorThread: Error closing socket " + ex2);
-          ex2.printStackTrace();
+          log.log(Level.SEVERE, "SelectorThread: Error closing socket ", ex2);
       }
   }
 
@@ -559,7 +563,7 @@
               selectorData.zeroReads = 0;
           } else if (done < 0) {
               if (debug) {
-                  log.info("SelectorThread: EOF while reading");
+                  log.info("SelectorThread: EOF while reading " + selectorData);
               }
           } else {
               // need more...

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SocketIOChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SocketIOChannel.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SocketIOChannel.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SocketIOChannel.java Fri Dec  4 07:16:59 2009
@@ -144,6 +144,7 @@
         try {
             synchronized(in) {
                 // data between 0 and position
+                int total = 0;
                 while (true) {
                     if (in.isAppendClosed()) { // someone closed me ?
                         ch.inputClosed(); // remove read interest.
@@ -165,9 +166,9 @@
                     }
                     
                     if (read < 0) {
-                        ch.inputClosed();
                         // mark the in buffer as closed
                         in.close();
+                        ch.inputClosed();
                         sendHandleReceivedCallback();
                         return;
                     }
@@ -177,6 +178,7 @@
                         }
                         return;
                     }
+                    total += read;
                     newData = true;
                 }
             }

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SslChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SslChannel.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SslChannel.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/io/SslChannel.java Fri Dec  4 07:16:59 2009
@@ -91,7 +91,7 @@
     
     
     @Override
-    public void setSink(IOChannel net) {
+    public void setSink(IOChannel net) throws IOException {
         try {
             initSsl();
             super.setSink(net);
@@ -223,13 +223,15 @@
         SSLEngineResult wrap = sslEngine.wrap(EMPTY, 
                 myNetOutData);
         myNetOutData.flip();
+        if (wrap.getStatus() != Status.CLOSED) {
+            System.err.println("Unexpected status " + wrap);
+        }
         net.getOut().write(myNetOutData);
         // TODO: timer to close socket if we don't get
         // clean close handshake
     }
     
     private synchronized void startRealSending() throws IOException {
-        IOBuffer netOut = net.getOut();
         while (true) {
         
             myAppOutData.compact();
@@ -411,6 +413,7 @@
     @Override
     public void handleReceived(IOChannel ch) throws IOException {
         processInput(net.getIn(), in);
+        // Maybe we don't have data - that's fine.
         sendHandleReceivedCallback();
     }
 

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/HttpProxyService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/HttpProxyService.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/HttpProxyService.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/HttpProxyService.java Fri Dec  4 07:16:59 2009
@@ -106,7 +106,6 @@
             serverNet.getOut().queue(OK);
             serverNet.startSending();
 
-            serverHttp.resetBuffers(); // no buffers
             serverHttp.release(); // no longer used
         }
     }
@@ -230,7 +229,7 @@
         serverHttp.setDataReceivedCallback(copy);
         copy.handleReceived(serverHttp);
 
-        httpClient.sendRequest();
+        httpClient.send();
         
 
         //serverHttp.handleReceived(serverHttp.getSink());
@@ -280,7 +279,6 @@
                 clientHttpReq.getHttpChannel().setDataReceivedCallback(copy);
                 copy.handleReceived(clientHttpReq.getHttpChannel());
 
-                serverHttp.sendHeaders();
                 serverHttp.startSending();
                 
                 

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/StaticContentService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/StaticContentService.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/StaticContentService.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/proxy/StaticContentService.java Fri Dec  4 07:16:59 2009
@@ -104,8 +104,6 @@
           }
           res.setContentType(contentType);
       
-          res.sendHead();
-
           if (chunked) {
               res.getBody()
                   .queue(BBuffer.wrapper(mb, 0, mb.remaining()));

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/TomcatLite.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/TomcatLite.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/TomcatLite.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/TomcatLite.java Fri Dec  4 07:16:59 2009
@@ -41,10 +41,9 @@
 import org.apache.tomcat.lite.http.HttpResponse;
 import org.apache.tomcat.lite.http.MappingData;
 import org.apache.tomcat.lite.http.HttpChannel.HttpService;
-import org.apache.tomcat.lite.io.WrappedException;
 import org.apache.tomcat.lite.io.CBuffer;
 import org.apache.tomcat.lite.io.MemoryIOConnector;
-import org.apache.tomcat.lite.io.CBuffer;
+import org.apache.tomcat.lite.io.WrappedException;
 
 /**
  * Helper allowing to run servlets using Tomcat lite http server.

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java Fri Dec  4 07:16:59 2009
@@ -64,7 +64,7 @@
         HttpConnector clientCon = DefaultHttpConnector.get();
         HttpChannel ch = clientCon.get("localhost", 8885);
         ch.getRequest().setRequestURI("/examples/servlets/servlet/HelloWorldExample");
-        ch.sendRequest();
+        ch.getRequest().send();
         BBuffer res = ch.readAll(null, 0);
         
         assertTrue(res.toString().indexOf("<title>Hello World!</title>") >= 0);

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java Fri Dec  4 07:16:59 2009
@@ -19,6 +19,7 @@
 import org.apache.tomcat.lite.http.Dispatcher;
 import org.apache.tomcat.lite.http.HttpChannel;
 import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.http.HttpRequest;
 import org.apache.tomcat.lite.http.BaseMapper.ContextMapping;
 import org.apache.tomcat.lite.http.HttpConnector.HttpChannelEvents;
 import org.apache.tomcat.lite.http.services.EchoCallback;
@@ -48,12 +49,12 @@
     public static HttpConnector testClient = DefaultHttpConnector.get();
     public static HttpConnector testServer = new HttpConnector(serverCon);
     public static HttpConnector testProxy = new HttpConnector(serverCon);
-    
+
     static Dispatcher mcb;
     static HttpProxyService proxy;
 
    
-    public static HttpConnector getTestServer() {
+    public static HttpConnector initTestEnv() {
         if (defaultServer == null) {
             defaultServer = new TestMain();
             defaultServer.run();
@@ -61,11 +62,17 @@
         return defaultServer.testServer;
     }
 
+    public static HttpConnector getClientAndInit() {
+        if (defaultServer == null) {
+            defaultServer = new TestMain();
+            defaultServer.run();
+        }
+        return defaultServer.testClient;
+    }
+
 
     public static void initTestCallback(Dispatcher d) {
         BaseMapper.ContextMapping mCtx = d.addContext(null, "", null, null, null, null);
-//      testServer.setDebugHttp(true);
-//      testServer.setDebug(true);
         
         d.addWrapper(mCtx, "/", new StaticContentService()
             .setContentType("text/html")
@@ -98,8 +105,8 @@
 
         BBuffer out = BBuffer.allocate();
 
-        HttpChannel aclient = DefaultHttpConnector.get().get(url);
-        aclient.sendRequest();
+        HttpRequest aclient = DefaultHttpConnector.get().request(url);
+        aclient.send();
         aclient.readAll(out, 
                 //Long.MAX_VALUE);//
                 2000000);
@@ -194,6 +201,8 @@
             testProxy.setPort(port);
 //            testProxy.setDebugHttp(true);
 //            testProxy.setDebug(true);
+//            testClient.setDebug(true);
+//            testClient.setDebugHttp(true);
 
             // dispatcher rejects 'http://'
             testProxy.setHttpService(proxy);
@@ -214,8 +223,9 @@
                 e.printStackTrace();
             }
             
-            port = basePort + 443;
-            
+//            testServer.setDebugHttp(true);
+//            testServer.setDebug(true);
+
         }   
         
         Runtime.getRuntime().addShutdownHook(new Thread() {

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/ClientTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/ClientTest.java?rev=887087&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/ClientTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/ClientTest.java Fri Dec  4 07:16:59 2009
@@ -0,0 +1,60 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import org.apache.tomcat.lite.TestMain;
+
+import junit.framework.TestCase;
+
+/**
+ * Examples and tests for Tomcat-lite in client mode.
+ * 
+ */
+public class ClientTest extends TestCase {
+
+    /** 
+     * All connectors created this way will share a single 
+     * IO thread. Each connector will have its keep-alive 
+     * pool - so it's better to share them.
+     * 
+     * Since I want to test keep-alive works, I use a static one
+     */
+    static HttpConnector httpCon = DefaultHttpConnector.get();
+
+    /** 
+     * Start a http server, runs on 8802 - shared by all tests.
+     * Will use /echo handler. 
+     */
+    static HttpConnector testServer = TestMain.initTestEnv();
+
+    
+    public void testSimpleBlocking() throws IOException {
+        HttpRequest req = httpCon.request("http://localhost:8802/echo/test1");
+        HttpResponse res = req.waitResponse();
+        
+        assertEquals(200, res.getStatus());
+        //assertEquals("", res.getHeader(""));
+        
+        BufferedReader reader = res.getReader();
+        String line1 = reader.readLine();
+        assertEquals("REQ HEAD:", line1);
+    }
+    
+    public void testSimpleCallback() throws IOException {
+        
+    }
+    
+    public void testGetParams() throws IOException {
+    }    
+
+    public void testPostParams() throws IOException {
+    }    
+
+    public void testPostBody() throws IOException {
+    }    
+    
+
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/ClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java Fri Dec  4 07:16:59 2009
@@ -17,48 +17,41 @@
 import org.apache.tomcat.lite.io.MemoryIOConnector;
 import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
 
+// TODO: rename to Http11ConnectionTest
 public class HttpChannelInMemoryTest extends TestCase {
+    /**
+     *  Connection under test 
+     */
+    Http11Connection conn;
+
+    /** 
+     * Last http channel created by the connection
+     */
+    HttpChannel http;
     
-    MemoryIOConnector memoryServerConnector =  new MemoryIOConnector();
-    MemoryIOConnector memoryClientConnector = 
-        new MemoryIOConnector().withServer(memoryServerConnector);
-
-    
-    // Used for pipelined requests - after the first request is 
-    // processed, a new HttpChannel is used ( first may still be 
-    // in use )
-    HttpChannel lastServer;
-    
-    // The server channel will use this for I/O...
+    // Input/output for the connection
     MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
 
-    HttpConnector serverConnector = new HttpConnector(memoryServerConnector) {
-        @Override
-        public HttpChannel get(CharSequence target) throws IOException {
-            throw new IOException();
-        }
-        public HttpChannel getServer() {
-            lastServer = new HttpChannel().serverMode(true);
-            lastServer.withBuffers(net);
-            lastServer.setConnector(this);
-            //lastServer.withIOConnector(memoryServerConnector);
-            return lastServer;
-        }
-    };
-
-    HttpConnector httpClient = new HttpConnector(memoryClientConnector);
+    HttpConnector serverConnector = new HttpConnector(null);
 
+    // Callback results for callback tests
     boolean hasBody = false;
     boolean bodyDone = false;
     boolean bodySentDone = false;
     boolean headersDone = false;
     boolean allDone = false;
     
-    
-    HttpChannel http = serverConnector.getServer();
-    
     public void setUp() throws IOException {
+        // Requests will not be serviced - you must manually generate
+        // the response.
         serverConnector.setHttpService(null);
+    
+        conn = new Http11Connection(serverConnector) {
+            protected HttpChannel checkHttpChannel() throws IOException {
+                return http = super.checkHttpChannel();
+            }
+        }.serverMode();
+        conn.setSink(net);
     }
     
    
@@ -80,6 +73,7 @@
         "\r\n";
         net.getIn().append(req);        
         
+        //http = lastServer.get(0);
         assertTrue(http.getRequest().method().equals("GET"));
         assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
         assertEquals(http.getRequest().getMimeHeaders().size(), 4);
@@ -96,7 +90,7 @@
         // now second response must be in. 
         // the connector will create a new http channel
         
-        http = lastServer;
+        //http = lastServer.get(1);
         
         assertTrue(http.getRequest().method().equals("HEAD"));
         assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
@@ -105,12 +99,101 @@
                 .equals("Foo.com"));
     }
 
+    public void testHttp11Close() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.1\r\n" +
+        "Host:  Foo.com\n" + 
+        "Connection: close\n" +
+        "\n"; 
+        net.getIn().append(req);        
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
+        
+        http.getOut().append("Response1");
+        http.getOut().close();
+        http.startSending();
+        http.release(); 
+        
+        assertTrue(net.out.indexOf("connection:close") > 0);
+        assertFalse(net.isOpen());
+    }
+
+    public void testHttp10Close() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.0\r\n" +
+        "Host:  Foo.com \n" + 
+        "\r\n"; 
+        net.getIn().append(req);        
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.0"));
+        
+        http.getOut().append("Response1");
+        http.getOut().close();
+        http.startSending();
+        
+        assertTrue(net.out.indexOf("connection:close") > 0);
+        assertFalse(net.isOpen());
+    }
+
+    public void testHttp10KA() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.0\r\n" +
+        "Connection: Keep-Alive\n" +
+        "Host:  Foo.com \n" + 
+        "\r\n"; 
+        net.getIn().append(req);        
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.0"));
+        
+        http.getOut().append("Hi");
+        http.getOut().close();
+        http.startSending();
+        
+        // after request
+        assertEquals(conn.activeHttp, null);
+        
+        assertTrue(net.out.indexOf("connection:keep-alive") > 0);
+        assertTrue(net.isOpen());
+        // inserted since we can calculate the response
+        assertEquals(http.getResponse().getHeader("Content-Length"),
+                   "2");
+    }
+    
+    public void testHttp10KANoCL() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.0\r\n" +
+        "Connection: Keep-Alive\n" +
+        "Host:  Foo.com \n" + 
+        "\r\n"; 
+        net.getIn().append(req);        
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.0"));
+        
+        http.getOut().append("Hi");
+        http.startSending();
+
+        http.getOut().append("After");
+        http.getOut().close();
+        http.startSending();
+        
+        // after request
+        assertEquals(conn.activeHttp, null);
+        
+        assertFalse(net.out.indexOf("connection:keep-alive") > 0);
+        assertFalse(net.isOpen());
+        // inserted since we can calculate the response
+        assertEquals(http.getResponse().getHeader("Content-Length"),
+                null);
+        assertEquals(http.getResponse().getHeader("Transfer-Encoding"),
+                null);
+    }
+    
     public void testMultiLineHead() throws IOException {
-        http.getNet().getIn().append("GET / HTTP/1.0\n" +
+        net.getIn().append("GET / HTTP/1.0\n" +
                 "Cookie: 1234\n" +
                 "  456 \n" +
                 "Connection:   Close\n\n");
-        http.getNet().getIn().close();
+        net.getIn().close();
         
         MultiMap headers = http.getRequest().getMimeHeaders();
         CBuffer cookie = headers.getHeader("Cookie");
@@ -118,20 +201,20 @@
         assertEquals(conn.toString(), "Close");
         assertEquals(cookie.toString(), "1234 456");
         
-        assertEquals(http.headRecvBuf.toString(), 
+        assertEquals(http.conn.headRecvBuf.toString(), 
                 "GET / HTTP/1.0\n" +
                 "Cookie: 1234 456   \n" + // \n -> trailing space
                 "Connection:   Close\n\n");
     }
 
     public void testCloseSocket() throws IOException {
-        http.getNet().getIn().append("GET / HTTP/1.1\n"
+        net.getIn().append("GET / HTTP/1.1\n"
                 + "Host: localhost\n"
                 + "\n");
-        assertTrue(http.keepAlive());
+        assertTrue(((Http11Connection)http.conn).keepAlive());
 
-        http.getNet().getIn().close();
-        assertFalse(http.keepAlive());
+        net.getIn().close();
+        assertFalse(((Http11Connection)http.conn).keepAlive());
     }
     
     public void test2ReqByte2Byte() throws IOException {
@@ -166,7 +249,6 @@
         
         http.release(); // now second response must be in
         
-        http = lastServer;
         assertTrue(http.getRequest().method().equals("HEAD"));
         assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
         assertTrue(http.getRequest().getMimeHeaders().size() == 2);
@@ -182,14 +264,16 @@
     }
     
     public void testEndWithoutFlushCallbacks() throws IOException {
+        
+        net.getIn().append(POST);
+
+        net.getIn().close();
         http.setCompletedCallback(new RequestCompleted() {
             public void handle(HttpChannel data, Object extra)
             throws IOException {
                 allDone = true;
             }
         });
-        http.getNet().getIn().append(POST);
-        http.getNet().getIn().close();
         
         http.sendBody.queue("Hi");
         http.getOut().close();
@@ -200,41 +284,48 @@
     }
 
     public void testCallbacks() throws IOException {
-        http.setCompletedCallback(new RequestCompleted() {
-            public void handle(HttpChannel data, Object extra)
-            throws IOException {
-                allDone = true;
-            }
-        });
-        http.setHttpService(new HttpService() {
+        // already accepted - will change
+        serverConnector.setHttpService(new HttpService() {
             public void service(HttpRequest httpReq, HttpResponse httpRes)
-            throws IOException {
+                    throws IOException {
+                
                 headersDone = true;
-            }
-        });
-        http.setDataReceivedCallback(new IOConnector.DataReceivedCallback() {
-            @Override
-            public void handleReceived(IOChannel ch) throws IOException {
-                if (ch.getIn().isAppendClosed()) {
-                    bodyDone = true;
-                }
-            }
-        });
-        http.setDataFlushedCallback(new IOConnector.DataFlushedCallback() {
-            @Override
-            public void handleFlushed(IOChannel ch) throws IOException {
-                if (ch.getOut().isAppendClosed()) {
-                    bodySentDone = true;
-                }
+                HttpChannel http = httpReq.getHttpChannel();
+                
+                http.setCompletedCallback(new RequestCompleted() {
+                    public void handle(HttpChannel data, Object extra)
+                    throws IOException {
+                        allDone = true;
+                    }
+                });
+                http.setDataReceivedCallback(new IOConnector.DataReceivedCallback() {
+                    @Override
+                    public void handleReceived(IOChannel ch) throws IOException {
+                        if (ch.getIn().isAppendClosed()) {
+                            bodyDone = true;
+                        }
+                    }
+                });
+                http.setDataFlushedCallback(new IOConnector.DataFlushedCallback() {
+                    @Override
+                    public void handleFlushed(IOChannel ch) throws IOException {
+                        if (ch.getOut().isAppendClosed()) {
+                            bodySentDone = true;
+                        }
+                    }
+                });
             }
         });
 
         // Inject the request
-        http.getNet().getIn().append(POST);
+        net.getIn().append("POST / HTTP/1.0\n" +
+                "Connection: Close\n" +
+                "Content-Length: 4\n\n" +
+                "1");
         assertTrue(headersDone);
-        http.getNet().getIn().append("1234");
+        net.getIn().append("234");
         
-        http.getNet().getIn().close();
+        net.getIn().close();
         assertTrue(bodyDone);
         
         
@@ -253,17 +344,16 @@
         "1234"; 
 
     public void testClose() throws IOException {
-        http.getNet().getIn().append(POST);
-        http.getNet().getIn().close();
-        
-        HttpBody receiveBody = http.receiveBody;
+        net.getIn().append(POST);
+        net.getIn().close();
+
+        IOBuffer receiveBody = http.receiveBody;
         IOBuffer appData = receiveBody;
         BBuffer res = BBuffer.allocate(1000);
         appData.readAll(res);
         
         assertEquals(res.toString(), "1234");
-        assertFalse(http.keepAlive());
-        assertFalse(http.keepAlive());
+        assertFalse(((Http11Connection)http.conn).keepAlive());
         
         http.sendBody.queue(res);
         http.getOut().close();
@@ -275,13 +365,13 @@
     }
     
     public void testReadLine() throws Exception {
-        http.getNet().getIn().append("POST / HTTP/1.0\n" +
+        net.getIn().append("POST / HTTP/1.0\n" +
         		"Content-Length: 28\n\n" +
                 "Line 1\n" +
                 "Line 2\r\n" +
                 "Line 3\r" +
                 "Line 4");
-        http.getNet().getIn().close();
+        net.getIn().close();
         
         BufferedReader r = http.getRequest().getReader();
         assertEquals("Line 1", r.readLine());

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java Fri Dec  4 07:16:59 2009
@@ -4,14 +4,14 @@
 
 import java.io.IOException;
 
-import org.apache.tomcat.lite.io.BBuffer;
-import org.apache.tomcat.lite.io.CBuffer;
-
 import junit.framework.TestCase;
 
+import org.apache.tomcat.lite.io.BBuffer;
+
 public class HttpChannelTest extends TestCase {
 
     HttpChannel ch = new HttpChannel().serverMode(true);
+    Http11Connection con = new Http11Connection(null).serverMode();
     HttpRequest req = ch.getRequest();
     
     
@@ -39,7 +39,6 @@
     BBuffer f3 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\r");
     BBuffer f4 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\n\r");
 
-    
     public void reqTest(String lineS, String method, String req, 
             String qry, String proto) throws IOException {
         BBuffer line = BBuffer.wrapper(lineS);
@@ -47,7 +46,7 @@
         protoB.recycle();
         requestB.recycle();
         methodB.recycle();
-        ch.parseRequestLine(line, methodB, requestB, queryB, protoB);
+        con.parseRequestLine(line, methodB, requestB, queryB, protoB);
         assertEquals(proto, protoB.toString());
         assertEquals(req, requestB.toString());
         assertEquals(qry, queryB.toString());
@@ -62,7 +61,7 @@
     private MultiMap processQry(String qry) throws IOException {
         BBuffer head = BBuffer.wrapper("GET /a?" + qry + " HTTP/1.0\n" +
         		"Host: a\n\n");
-        ch.parseMessage(head);
+        con.parseMessage(ch, head);
         MultiMap params = req.getParameters();
         return params;
     }
@@ -82,7 +81,7 @@
             String expLine, String expRest) throws IOException {
         head = BBuffer.wrapper(headS);
         head.readLine(line);
-        ch.parseHeader(head, line, name, value);
+        con.parseHeader(ch, head, line, name, value);
         
         assertEquals(expName, name.toString());
         assertEquals(expValue, value.toString());
@@ -111,7 +110,7 @@
         statusB.recycle();
         msgB.recycle();
         BBuffer line = BBuffer.wrapper(lineS);
-        ch.parseResponseLine(line, 
+        con.parseResponseLine(line, 
                 protoB, statusB, msgB);
         assertEquals(proto, protoB.toString());
         assertEquals(status, statusB.toString());

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java Fri Dec  4 07:16:59 2009
@@ -94,13 +94,12 @@
     }       
 
     
-    private void checkResponse(HttpConnector httpClient) throws Exception {
-        HttpChannel ch = httpClient.get("localhost", port);
-        ch.getRequest().setRequestURI("/hello");
-        ch.getRequest().setProtocol("HTTP/1.0");
-        // problems with keep alive !!!
-        ch.sendRequest();
-        BBuffer res = ch.readAll(null, 1000000);
+    private void checkResponse(HttpConnector httpCon) throws Exception {
+        HttpRequest ch = httpCon.request("localhost", port);
+        ch.setRequestURI("/hello");
+        ch.setProtocol("HTTP/1.0");
+        ch.send();
+        BBuffer res = ch.readAll();
         
         assertTrue(res.toString().indexOf("Hello") >= 0);
     }    
@@ -120,12 +119,11 @@
     public void testSimpleRequestGoogle() throws Exception {
         SslConnector sslCon = new SslConnector();
         httpClient = new HttpConnector(sslCon);
-        HttpChannel client = httpClient.get("www.google.com", 443);
-        client.getRequest().setRequestURI("/accounts/ServiceLogin");
-        client.sendRequest();
+        HttpRequest client = httpClient.request("www.google.com", 443);
+        client.setRequestURI("/accounts/ServiceLogin");
+        client.send();
         
-        BBuffer res = BBuffer.allocate(10000);
-        client.readAll(res, 1000000);
+        BBuffer res = client.readAll();
         assertTrue(res.toString().indexOf("<title>Google Accounts</title>") > 0);
     }
         

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java Fri Dec  4 07:16:59 2009
@@ -22,25 +22,24 @@
 
 import org.apache.tomcat.lite.TestMain;
 import org.apache.tomcat.lite.io.BBuffer;
-import org.apache.tomcat.lite.io.CBuffer;
 import org.apache.tomcat.lite.io.SocketConnector;
 
 public class LiveHttp1Test extends TestCase {
     // Proxy tests extend this class, run same tests via proxy on 8903 
     protected int clientPort = 8802;
 
-    HttpChannel httpClient;
+    HttpRequest httpClient;
 
     BBuffer bodyRecvBuffer = BBuffer.allocate(1024);
 
-    int to = 1000;
+    int to = 1000000;
 
     public void setUp() throws IOException {
         // DefaultHttpConnector.get().setDebug(true);
         // DefaultHttpConnector.get().setDebugHttp(true);
-        TestMain.getTestServer();
+        TestMain.initTestEnv();
 
-        httpClient = DefaultHttpConnector.get().get("localhost", clientPort);
+        httpClient = DefaultHttpConnector.get().request("localhost", clientPort);
 
         bodyRecvBuffer.recycle();
     }
@@ -53,9 +52,9 @@
     }
 
     public void testSimpleRequest() throws Exception {
-        httpClient.getRequest().requestURI().set("/hello");
+        httpClient.requestURI().set("/hello");
 
-        httpClient.sendRequest();
+        httpClient.send();
         httpClient.readAll(bodyRecvBuffer, to);
         assertEquals("Hello world", bodyRecvBuffer.toString());
     }
@@ -75,18 +74,18 @@
     }
 
     public void testSimpleChunkedRequest() throws Exception {
-        httpClient.getRequest().requestURI().set("/chunked/foo");
-        httpClient.sendRequest();
+        httpClient.requestURI().set("/chunked/foo");
+        httpClient.send();
         httpClient.readAll(bodyRecvBuffer, to);
         assertTrue(bodyRecvBuffer.toString().indexOf("AAA") >= 0);
     }
 
     // Check waitResponseHead()
     public void testRequestHead() throws Exception {
-        httpClient.getRequest().requestURI().set("/echo/foo");
+        httpClient.requestURI().set("/echo/foo");
 
         // Send the request, wait response
-        httpClient.sendRequest();
+        httpClient.send();
 
         httpClient.readAll(bodyRecvBuffer, to);
         assertTrue(bodyRecvBuffer.toString().indexOf("GET /echo/foo") > 0);
@@ -109,19 +108,19 @@
     }
 
     public void notFound() throws Exception {
-        httpClient.getRequest().requestURI().set("/foo");
-        httpClient.sendRequest();
+        httpClient.requestURI().set("/foo");
+        httpClient.send();
         httpClient.readAll(bodyRecvBuffer, to);
     }
 
     // compression not implemented
     public void testGzipRequest() throws Exception {
-        httpClient.getRequest().requestURI().set("/hello");
-        httpClient.getRequest().setHeader("accept-encoding",
+        httpClient.requestURI().set("/hello");
+        httpClient.setHeader("accept-encoding",
             "gzip");
 
         // Send the request, wait response
-        httpClient.sendRequest();
+        httpClient.send();
         // cstate.waitResponseHead(10000); // headers are received
         // ByteChunk data = new ByteChunk(1024);
         // acstate.serializeResponse(acstate.res, data);
@@ -133,10 +132,10 @@
     }
 
     public void testWrongPort() throws Exception {
-        httpClient = DefaultHttpConnector.get().get("localhost", 18904);
-        httpClient.getRequest().requestURI().set("/hello");
+        httpClient = DefaultHttpConnector.get().request("localhost", 18904);
+        httpClient.requestURI().set("/hello");
 
-        httpClient.sendRequest();
+        httpClient.send();
         
         httpClient.readAll(bodyRecvBuffer, to);
         assertEquals(0, bodyRecvBuffer.remaining());

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java?rev=887087&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java Fri Dec  4 07:16:59 2009
@@ -0,0 +1,89 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.TestMain;
+import org.apache.tomcat.lite.io.IOBuffer;
+import org.apache.tomcat.lite.http.SpdyConnection.SpdyConnectionManager;
+
+public class SpdyTest extends TestCase {
+    HttpConnector http11Con = TestMain.getClientAndInit();
+    
+    static HttpConnector spdyCon = DefaultHttpConnector.get()
+        .withConnectionManager(new SpdyConnectionManager());
+    
+    HttpConnector memSpdyCon = 
+        new HttpConnector(null).withConnectionManager(new SpdyConnectionManager());
+    
+    public void testClient() throws IOException {
+        HttpRequest req = 
+            spdyCon.request("http://localhost:8802/echo/test1");
+        
+        HttpResponse res = req.waitResponse();
+        
+        assertEquals(200, res.getStatus());
+        //assertEquals("", res.getHeader(""));
+        
+        BufferedReader reader = res.getReader();
+        String line1 = reader.readLine();
+        //assertEquals("", line1);        
+    }
+    
+    // Initial frame generated by Chrome
+    public void testParse() throws IOException {
+            InputStream is = 
+            getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreq0");
+        
+        IOBuffer iob = new IOBuffer();
+        iob.append(is);
+        
+        SpdyConnection con = (SpdyConnection) memSpdyCon.newConnection();
+        
+        // By default it has a dispatcher buit-in 
+        con.serverMode = true;
+        
+        con.dataReceived(iob);
+        
+        HttpChannel spdyChannel = con.channels.get(1);
+
+        assertEquals(1, con.lastFrame.version);
+        assertEquals(1, con.lastFrame.type);
+        assertEquals(1, con.lastFrame.flags);
+
+        assertEquals(417, con.lastFrame.length);
+
+        // TODO: test req, headers
+        HttpRequest req = spdyChannel.getRequest();
+        assertTrue(req.getHeader("accept").indexOf("application/xml") >= 0);
+        
+    }
+    
+    // Does int parsing works ?
+    public void testLargeInt() throws Exception {
+        
+        IOBuffer iob = new IOBuffer();
+        iob.append(0xFF);
+        iob.append(0xFF);
+        iob.append(0xFF);
+        iob.append(0xFF);
+
+        iob.append(0xFF);
+        iob.append(0xFF);
+        iob.append(0xFF);
+        iob.append(0xFF);
+
+        SpdyConnection con = (SpdyConnection) memSpdyCon.newConnection();
+        con.dataReceived(iob);
+        assertEquals(0x7FFF, con.currentInFrame.version);
+        assertEquals(0xFFFF, con.currentInFrame.type);
+        assertEquals(0xFF, con.currentInFrame.flags);
+        assertEquals(0xFFFFFF, con.currentInFrame.length);
+        
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java Fri Dec  4 07:16:59 2009
@@ -18,6 +18,7 @@
 import java.io.IOException;
 import java.util.logging.Logger;
 
+import org.apache.tomcat.lite.http.Http11Connection;
 import org.apache.tomcat.lite.http.HttpChannel;
 import org.apache.tomcat.lite.http.HttpRequest;
 import org.apache.tomcat.lite.http.HttpResponse;
@@ -43,7 +44,7 @@
         res.setContentType(contentType);
         
         IOBuffer tmp = new IOBuffer(null);
-        req.serialize(tmp);
+        Http11Connection.serialize(req, tmp);
         
         sproc.getOut().append("REQ HEAD:\n");
         sproc.getOut().append(tmp.readAll(null));

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java Fri Dec  4 07:16:59 2009
@@ -61,7 +61,7 @@
         }
         res.setContentType(contentType);
 
-        res.sendHead();
+        res.flush();
 
         Thread.currentThread().sleep(t2);
 

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/spdyreq0
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/spdyreq0?rev=887087&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/spdyreq0
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java Fri Dec  4 07:16:59 2009
@@ -12,12 +12,9 @@
 import junit.framework.TestCase;
 
 public class OneTest extends TestCase {
-    MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
-    HttpChannel http = new HttpChannel()
-        .serverMode(true).withBuffers(net);
  
     public void setUp() throws Exception {
-        TestMain.getTestServer();
+        TestMain.initTestEnv();
     }
     
     public void tearDown() throws IOException {

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java Fri Dec  4 07:16:59 2009
@@ -25,11 +25,12 @@
 import org.apache.tomcat.lite.http.DefaultHttpConnector;
 import org.apache.tomcat.lite.http.HttpChannel;
 import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.http.HttpRequest;
 import org.apache.tomcat.lite.http.HttpChannel.HttpService;
 import org.apache.tomcat.lite.http.HttpChannel.RequestCompleted;
 
 public class LiveHttpThreadedTest extends TestCase {
-  HttpConnector staticMain = TestMain.getTestServer();
+  HttpConnector staticMain = TestMain.initTestEnv();
   
   
   int tCount = 1;
@@ -104,13 +105,13 @@
   };
   
   void makeRequest(int i, boolean block) throws Exception {
-    HttpChannel cstate = DefaultHttpConnector.get().get("localhost", 8802);
+    HttpRequest cstate = DefaultHttpConnector.get().request("localhost", 8802);
     
-    cstate.getRequest().requestURI().set("/hello");
+    cstate.requestURI().set("/hello");
     cstate.setCompletedCallback(reqCallback);
     
     // Send the request, wait response
-    cstate.sendRequest();
+    cstate.send();
   }
   
 }

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java Fri Dec  4 07:16:59 2009
@@ -28,7 +28,7 @@
   String resStr;
     
   public void setUp() throws Exception {
-      TestMain.getTestServer();
+      TestMain.initTestEnv();
   }
   
   public void tearDown() throws IOException {

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java Fri Dec  4 07:16:59 2009
@@ -8,6 +8,7 @@
 
 import org.apache.tomcat.lite.http.HttpChannel;
 import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.http.HttpConnector.HttpConnection;
 import org.apache.tomcat.lite.io.MemoryIOConnector;
 import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
 
@@ -20,14 +21,13 @@
         new MemoryIOConnector().withServer(memoryServerConnector);
 
     
-    HttpConnector httpPool = new HttpConnector(memoryServerConnector) {
+    HttpConnector httpCon = new HttpConnector(memoryServerConnector) {
         @Override
         public HttpChannel get(CharSequence target) throws IOException {
             throw new IOException();
         }
         public HttpChannel getServer() {
             lastServer = new HttpChannel().serverMode(true);
-            lastServer.withBuffers(net);
             lastServer.setConnector(this);
             //lastServer.withIOConnector(memoryServerConnector);
             return lastServer;
@@ -65,9 +65,12 @@
     
     MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
     HttpChannel http;
+
+    HttpConnection serverConnection;
     
     public void setUp() throws IOException {
-        http = httpPool.getServer();
+        http = httpCon.getServer();
+        serverConnection = httpCon.handleAccepted(net);
     }
  
     /**
@@ -75,13 +78,13 @@
      * @throws IOException
      */
     public void testProxy() throws IOException {
-        http.setHttpService(new HttpProxyService()
+        httpCon.setHttpService(new HttpProxyService()
             .withSelector(memoryClientConnector)
             .withHttpClient(httpClient));
 
-        http.getNet().getIn().append("GET http://www.cyberluca.com/ HTTP/1.0\n" +
+        net.getIn().append("GET http://www.apache.org/ HTTP/1.0\n" +
                 "Connection: Close\n\n");
-        http.getNet().getIn().close();
+        net.getIn().close();
         
         // lastClient.rawSendBuffers has the request sent by proxy
         lastClient.getNet().getIn()

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java Fri Dec  4 07:16:59 2009
@@ -25,9 +25,6 @@
 import org.apache.tomcat.lite.http.HttpRequest;
 import org.apache.tomcat.lite.http.HttpResponse;
 import org.apache.tomcat.lite.io.BBuffer;
-import org.apache.tomcat.lite.io.MemoryIOConnector;
-import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
-import org.apache.tomcat.lite.servlet.TomcatLite;
 
 /**
  * Example of testing servlets without using sockets.
@@ -37,12 +34,10 @@
 public class TomcatLiteNoConnectorTest extends TestCase {
 
   TomcatLite lite;
-  MemoryIOConnector net;
   HttpConnector con;
   
   public void setUp() throws Exception {
-      net = new MemoryIOConnector();
-      con = new HttpConnector(net);
+      con = new HttpConnector(null);
       
       lite = new TomcatLite();
       lite.setHttpConnector(con);
@@ -55,39 +50,21 @@
     lite.stop();
   }
   
-
   public void testSimpleRequest() throws Exception {
-      MemoryIOConnector.MemoryIOChannel ch = new MemoryIOChannel();
-      
       HttpChannel httpCh = con.getServer();
-      httpCh.withBuffers(ch);
       
       HttpRequest req = httpCh.getRequest();
       req.setURI("/test1/1stTest");
 
       HttpResponse res = httpCh.getResponse();
       
-      lite.getHttpConnector().getDispatcher().service(req, res, true);
-      // req/res will be recycled
-      
-      // parse out to a response
-      BBuffer out = ch.out;
-      MemoryIOChannel clientCh = new MemoryIOChannel();
-      clientCh.getIn().append(out);
-      
-      HttpChannel client = con.get("localhost", 80);
-      client.withBuffers(clientCh);
-      clientCh.handleReceived(clientCh);
-      
-      
-      HttpResponse cres = client.getResponse();
-      assertEquals(res.getStatus(), 200);
+      lite.getHttpConnector().getDispatcher().service(req, res, true, false);
     
-      BBuffer resBody = BBuffer.allocate(200);
-      cres.getBody().readAll(resBody);
+      BBuffer resBody = res.getBody().readAll(null);
       assertEquals("Hello world", resBody.toString());
-      assertEquals(cres.getHeader("Foo"), "Bar");
-      assertEquals(cres.getStatus(), 200);
+
+      assertEquals(res.getHeader("Foo"), "Bar");
+      assertEquals(res.getStatus(), 200);
   }
   
 //

Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java?rev=887087&r1=887086&r2=887087&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java Fri Dec  4 07:16:59 2009
@@ -52,7 +52,7 @@
             System.out.println( " Socket Exception: " + ex );
             return;
         }
-        //socket.setSoTimeout(10000);
+        //socket.setSoTimeout(2000);
         
         //socket obtained, rebuild the request.
         rebuildRequest(client, client.request, socket);
@@ -144,7 +144,6 @@
             // write the request
             out.write( reqbytes, 0, reqbytes.length );
             out.flush();
-            reqbuf = null;
         } catch ( Exception ex1 ) {
             System.out.println( " Error writing request " + ex1 );
                 if ( debug > 0 ) {
@@ -385,9 +384,9 @@
          * @exception IOException if an error occurs
          */
         private void fill() throws IOException {
-            if (markpos < 0)
+            if (markpos < 0) {
                 pos = 0;        /* no mark: throw away the buffer */
-            else if (pos >= buf.length)  /* no room left in buffer */
+            } else if (pos >= buf.length)  {/* no room left in buffer */
                 if (markpos > 0) {  /* can throw away early part of the buffer */
                     int sz = pos - markpos;
                     System.arraycopy(buf, markpos, buf, 0, sz);
@@ -404,10 +403,12 @@
                     System.arraycopy(buf, 0, nbuf, 0, pos);
                     buf = nbuf;
                 }
-                count = pos;
-                int n = in.read(buf, pos, buf.length - pos); 
-                if (n > 0)
+            }
+            count = pos;
+            int n = in.read(buf, pos, buf.length - pos); 
+            if (n > 0) {
                 count = n + pos;
+            }
         }
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org