Author: costin
Date: Fri Aug 29 21:28:23 2008
New Revision: 690459

URL: http://svn.apache.org/viewvc?rev=690459&view=rev
Log:
Removed jmx where not needed, added few files to make it easier to port default 
servlet

Added:
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java
   (with props)
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java
   (with props)
Modified:
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteMain.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MapperAdapter.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageReader.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageWriter.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/ProxyAdapter.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/AsyncHttp.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/BlockingHttp.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/SocketPool.java
    
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/Http11Parser.java

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteMain.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteMain.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteMain.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteMain.java
 Fri Aug 29 21:28:23 2008
@@ -39,6 +39,13 @@
 
   // ------------------- Main ---------------------
   public static void main( String args[]) throws Exception {
+    try {
+        Class<?> c = 
Class.forName("org.apache.tomcat.util.modeler.JmxObjectManager");
+        c.newInstance();
+    } catch (Throwable t) {
+        System.err.println("JMX not available");
+    }
+    
     CoyoteMain sa=new CoyoteMain();
     IntrospectionUtils.processArgs(sa, args);
     IntrospectionUtils.processArgs(fileAdapter, args);

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java
 Fri Aug 29 21:28:23 2008
@@ -16,15 +16,13 @@
 package org.apache.coyote.adapters;
 
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
 
 import org.apache.coyote.Adapter;
 import org.apache.coyote.ProtocolHandler;
-import org.apache.coyote.http11.Http11NioProtocol;
 import org.apache.coyote.http11.async.AsyncProtocolHandler;
 import org.apache.juli.JdkLoggerConfig;
+import org.apache.tomcat.util.ObjectManager;
 import org.apache.tomcat.util.buf.BufferInfo;
-import org.apache.tomcat.util.modeler.Registry;
 
 
 /** 
@@ -47,9 +45,7 @@
   
   protected ProtocolHandler proto;
 
-  protected Registry registry;
-  
-  protected Adapter adapter;
+  protected Adapter adapter = new MapperAdapter();
   protected int maxThreads = 20;
   boolean started = false;
   boolean async = false; // use old nio connector
@@ -78,20 +74,12 @@
    * @param adapter
    */
   public void addAdapter(String path, Adapter added) {
-    if (adapter == null && "/".equals(path)) {
-      adapter = added;
-    } else {
-      if (!(adapter instanceof MapperAdapter)) {
-        Adapter oldDefault = adapter;
-        adapter = new MapperAdapter();
-        ((MapperAdapter) adapter).setDefaultAdapter(oldDefault);
-      }
       if ("/".equals(path)) {
-        ((MapperAdapter) adapter).setDefaultAdapter(added);        
+          ((MapperAdapter) adapter).setDefaultAdapter(added);        
       } else {
-        ((MapperAdapter) adapter).getMapper().addWrapper(path, added);
+          ((MapperAdapter) adapter).getMapper().addWrapper(path, added);
       }
-    }
+      ObjectManager.get().registerObject(adapter, path, "Adapter");
   }
   
   /**
@@ -109,12 +97,10 @@
     daemon = b;
   }
   
-  public void setAsync(boolean b) {
-      async = b;
-  }
-  
   public void init() {
     JdkLoggerConfig.loadCustom();
+    ObjectManager.get().registerObject(this, "CoyoteServer-" + port, 
+            "CoyoteServer");
   }
 
   protected void initAdapters() {
@@ -146,36 +132,20 @@
   }
   
   public void setPort(int port) {
-    initJMX();
     if (proto != null) {
         proto.setAttribute("port", Integer.toString(port));
     }
     this.port = port;
   }
   
-  public void setNioConnector() {
-    Http11NioProtocol proto = new Http11NioProtocol();
-    proto.setCompression("on");
-    proto.setCompressionMinSize(32);
-    proto.setPort(port);
-    proto.getEndpoint().setDaemon(daemon);
-    setConnector(proto);
-  }
-  
-  public void setAsyncConnector() {
-      AsyncProtocolHandler proto = new AsyncProtocolHandler();
-      proto.setPort(port);
-      proto.setDaemon(daemon);
-      
-      setConnector(proto);
-  }
-  
   public void setConnector(ProtocolHandler h) {
       this.proto = h;
       h.setAttribute("port", Integer.toString(port));
       if (daemon) {
           h.setAttribute("daemon", "1");
       }
+
+      ObjectManager.get().registerObject(proto, "ep-" + port, null);
   }
   
   public void start() throws IOException {
@@ -184,39 +154,32 @@
         return;
       }
       if (proto == null) {
-          // Default for now. 
-          if (async) {
-              setAsyncConnector();
-          } else {
-              setNioConnector();
-          }
+          // Default for now - it's smallest, fewer deps. Easy to use nio 
+          // or apr with setConnector.
+          AsyncProtocolHandler proto = new AsyncProtocolHandler();
+          proto.setPort(port);
+          proto.setDaemon(daemon);
+          
+          setConnector(proto);
       }
       initAdapters();
-      registry.registerComponent(adapter, ":name=adapter" + (port), null);
-      registry.registerComponent(BufferInfo.get(), ":name=BufferInfo" + port, 
-          "BufferInfo");
+      
+      ObjectManager.get().registerObject(BufferInfo.get(), 
+              "BufferInfo" + port, "BufferInfo"); 
       
       proto.setAdapter(adapter);
       
-      registry.registerComponent(proto, ":name=ep-" + port, null);
       proto.init();
       proto.start();
       
       started = true;
     } catch (Throwable e) {
       e.printStackTrace();
-      throw new IOException(e);
+      throw new RuntimeException(e);
     }
   }
   
-  public void initJMX() {
-    ManagementFactory.getPlatformMBeanServer();
-    registry = Registry.getRegistry(null, null);
-    
-  }
-
   public boolean getStarted() {
     return started;
   } 
- 
 }
\ No newline at end of file

Added: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java?rev=690459&view=auto
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java
 (added)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java
 Fri Aug 29 21:28:23 2008
@@ -0,0 +1,42 @@
+/*
+ */
+package org.apache.coyote.adapters;
+
+import org.apache.coyote.Request;
+import org.apache.tomcat.util.http.mapper.MappingData;
+
+public class CoyoteUtils {
+
+    public static String getContextPath(Request request) {
+        MappingData md = MapperAdapter.getMappingData(request);
+        String ctxPath = (md.contextPath.isNull()) ? "/" : 
+            md.contextPath.toString();
+        return ctxPath;
+    }
+
+    public static String getPathInfo(Request request) {
+        MappingData md = MapperAdapter.getMappingData(request);
+        String ctxPath = (md.pathInfo.isNull()) ? "/" : 
+            md.pathInfo.toString();
+        return ctxPath;
+    }
+    public static String getServletPath(Request request) {
+        MappingData md = MapperAdapter.getMappingData(request);
+        String ctxPath = (md.wrapperPath.isNull()) ? "/" : 
+            md.wrapperPath.toString();
+        return ctxPath;
+    }
+    
+    // TODO: collate all notes in a signle file
+    static int READER_NOTE = 5;
+    
+    public static MessageReader getReader(Request req) {
+        MessageReader r = (MessageReader) req.getNote(READER_NOTE);
+        if (r == null) {
+            r = new MessageReader();
+            r.setRequest(req);
+            req.setNote(READER_NOTE, r);
+        }
+        return r;
+    }
+}

Propchange: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MapperAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MapperAdapter.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MapperAdapter.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MapperAdapter.java
 Fri Aug 29 21:28:23 2008
@@ -22,8 +22,8 @@
 import org.apache.coyote.Response;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.mapper.Mapper;
 import org.apache.tomcat.util.http.mapper.MappingData;
+import org.apache.tomcat.util.http.mapper.SimpleMapper;
 import org.apache.tomcat.util.net.SocketStatus;
 
 /**
@@ -31,19 +31,29 @@
  */
 public class MapperAdapter implements Adapter {
 
-    private Mapper mapper=new Mapper();
+    private SimpleMapper mapper=new SimpleMapper();
+    
+    static final int MAP_NOTE = 4;
     
     public MapperAdapter() {
-        mapper = new Mapper();
         mapper.setDefaultHostName("localhost");
         mapper.setContext("", new String[] {"index.html"},
             null);
     }
 
-    public MapperAdapter(Mapper mapper2) {
+    public MapperAdapter(SimpleMapper mapper2) {
         mapper = mapper2;
     }
     
+    public static MappingData getMappingData(Request req) {
+        MappingData md = (MappingData) req.getNote(MAP_NOTE);
+        if (md == null) {
+            md = new MappingData();
+            req.setNote(MAP_NOTE, md);
+        }
+        return md;
+    }
+    
     public static void decodeRequest(Request reqB) throws IOException {
       MessageBytes decodedURI = reqB.decodedURI();
       decodedURI.duplicate(reqB.requestURI());
@@ -184,8 +194,9 @@
         try {
           // compute decodedURI - not done by connector
           decodeRequest(req);
-          MappingData mapRes = new MappingData();
-            
+          MappingData mapRes = getMappingData(req);
+          mapRes.recycle();
+          
           mapper.map(req.requestURI(), mapRes);
             
             Adapter h=(Adapter)mapRes.wrapper;
@@ -206,7 +217,11 @@
             // TODO: add this note in the nio/apr connectors
             // TODO: play nice with TomcatLite, other adapters that flush/close
             if (res.getNote(CoyoteServer.COMET_RES_NOTE) == null) {
-                MessageWriter.getWriter(req, res, 0).flush();
+                MessageWriter mw = MessageWriter.getWriter(req, res, 0);
+                mw.flush();
+                mw.recycle();
+                MessageReader reader = CoyoteUtils.getReader(req);
+                reader.recycle();
                 res.finish();
 
                 req.recycle();
@@ -215,7 +230,7 @@
         }
     }
 
-    public Mapper getMapper() {
+    public SimpleMapper getMapper() {
       return mapper;
     }
 

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageReader.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageReader.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageReader.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageReader.java
 Fri Aug 29 21:28:23 2008
@@ -17,6 +17,7 @@
 package org.apache.coyote.adapters;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Reader;
 import java.util.HashMap;
 
@@ -455,4 +456,64 @@
           encoders.put(enc, conv);
         }
     }
+    
+    class MRInputStream extends InputStream {
+        public long skip(long n)
+                throws IOException {
+            return MessageReader.this.skip(n);
+        }
+
+        public void mark(int readAheadLimit)
+        {
+            try {
+                MessageReader.this.mark(readAheadLimit);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+
+        public void reset()
+        throws IOException {
+            MessageReader.this.reset();
+        }
+
+
+
+        public int read()
+        throws IOException {    
+            return MessageReader.this.readByte();
+        }
+
+        public int available() throws IOException {
+            return MessageReader.this.available();
+        }
+
+        public int read(final byte[] b) throws IOException {
+            return MessageReader.this.read(b, 0, b.length);
+        }
+
+
+        public int read(final byte[] b, final int off, final int len)
+        throws IOException {
+
+            return MessageReader.this.read(b, off, len);
+        }
+
+
+        /** 
+         * Close the stream
+         * Since we re-cycle, we can't allow the call to super.close()
+         * which would permantely disable us.
+         */
+        public void close() throws IOException {
+            MessageReader.this.close();
+        }
+    }
+    
+    MRInputStream is = new MRInputStream();
+    
+    public InputStream asInputStream() {
+        return is;
+    }
 }

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageWriter.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageWriter.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageWriter.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/MessageWriter.java
 Fri Aug 29 21:28:23 2008
@@ -518,6 +518,18 @@
 
     } 
 
+    public void println() throws IOException {
+        write("\n");
+    }
+
+    public void println(String s) throws IOException {
+        write(s);
+        write("\n");
+    }
+
+    public void print(String s) throws IOException {
+        write(s);
+    }
 
     public void flushChars()
         throws IOException {

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/ProxyAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/ProxyAdapter.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/ProxyAdapter.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/ProxyAdapter.java
 Fri Aug 29 21:28:23 2008
@@ -20,8 +20,6 @@
 import java.util.List;
 import java.util.logging.Logger;
 
-import javax.servlet.ServletException;
-
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.Request;
@@ -173,12 +171,4 @@
         public void dataWritten(ByteChunk bc) {
         }    
     }
-
-    public static void main(String[] args) throws ServletException, 
IOException {
-        CoyoteServer server = new CoyoteServer(8901, new ProxyAdapter());
-        server.setDaemon(false);
-        server.setAsync(true);
-        server.start();
-    }  
-
 }

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/AsyncHttp.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/AsyncHttp.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/AsyncHttp.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/AsyncHttp.java
 Fri Aug 29 21:28:23 2008
@@ -28,13 +28,14 @@
 import org.apache.coyote.Request;
 import org.apache.coyote.Response;
 import org.apache.coyote.http11.Constants;
+import org.apache.tomcat.util.ObjectManager;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.Http11Parser;
 import org.apache.tomcat.util.http.HttpMessages;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.modeler.Registry;
+//import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.net.SelectorCallback;
 import org.apache.tomcat.util.net.SelectorPool;
 import org.apache.tomcat.util.net.SelectorThread;
@@ -95,7 +96,6 @@
         DONE
     }
     static AtomicInteger serCnt = new AtomicInteger();
-    static Registry registry = Registry.getRegistry(null, null);
 
     // ---- Buffers owned by the AsyncHttp object ----
     protected Logger log = Logger.getLogger("AsyncHttp");
@@ -306,12 +306,8 @@
         }
         selectorCallback = new AsyncHttpSelectorCallback(); 
         ser = serCnt.incrementAndGet();
-        try {
-            registry.registerComponent(this, ":name=AsyncHttp-" + 
-                    ser, "AsyncHttp");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        ObjectManager.get().registerObject(this,
+                "AsyncHttp-" + ser, "AsyncHttp");
 
         this.selector = client.getSelector();
 
@@ -1276,7 +1272,7 @@
         serviceDone = true;
         maybeRelease();
     }
-    
+
     public void ioThreadRun(SelectorData selThread) throws IOException {
         // Currently used only to set keep alive.
         // If we need more, need to use state or pass a param.
@@ -1299,7 +1295,7 @@
                 if (!allDone) {
                     allDone = true;
                     // pipeline or keepalive
-                    selector.ioThreadRun(selectorData);
+                    selector.runInSelectorThread(selectorData);
                 }
             } else {
                 if (debug) {

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/BlockingHttp.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/BlockingHttp.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/BlockingHttp.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/BlockingHttp.java
 Fri Aug 29 21:28:23 2008
@@ -155,7 +155,7 @@
                             Condition cond,
                             String name) throws IOException {
         if (to < 0) {
-            throw new IOException(new TimeoutException());
+            throw new RuntimeException(new TimeoutException());
         } else if (to == 0) {
             to = timeout;
         }

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/SocketPool.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/SocketPool.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/SocketPool.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/client/SocketPool.java
 Fri Aug 29 21:28:23 2008
@@ -10,7 +10,8 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.logging.Logger;
 
-import org.apache.tomcat.util.modeler.Registry;
+//import org.apache.tomcat.util.modeler.Registry;
+import org.apache.tomcat.util.ObjectManager;
 import org.apache.tomcat.util.net.SelectorCallback;
 import org.apache.tomcat.util.net.SelectorThread.SelectorData;
 
@@ -79,17 +80,12 @@
     AtomicInteger waitingSockets = new AtomicInteger();
     AtomicInteger closedSockets = new AtomicInteger();
 
-    static Registry registry = Registry.getRegistry(null, null);
-
     // TODO: keep track of all socket pools, enforce max total sockets.
     // TODO: for linux, find how many sockets we can have open, use as limit
     
     public SocketPool(String id) {
-        try {
-            registry.registerComponent(this, ":name=SocketPool,id=" + id, 
"SocketPool");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        ObjectManager.get().registerObject(this, 
+                "SocketPool,id=" + id, "SocketPool");
     }
 
     public int getTargetCount() {

Modified: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/Http11Parser.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/Http11Parser.java?rev=690459&r1=690458&r2=690459&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/Http11Parser.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/Http11Parser.java
 Fri Aug 29 21:28:23 2008
@@ -201,6 +201,8 @@
       return pos;
     }
     
+    // TODO: InternalNioInputBuffer now has support for HT and multiple SP
+    
     public final int readToDelim(MessageBytes res, byte delim) {
       boolean space = false;
       // Mark the current buffer position

Added: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java?rev=690459&view=auto
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java
 (added)
+++ 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java
 Fri Aug 29 21:28:23 2008
@@ -0,0 +1,471 @@
+package org.apache.tomcat.util.http;
+
+import java.util.Hashtable;
+
+/**
+ * 
+ * TODO: move to separate class, to adapters.
+ * Copied from HttpServletResponse
+ */
+public class HttpStatus {
+
+
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * This Hashtable contains the mapping of HTTP and WebDAV
+     * status codes to descriptive text.  This is a static
+     * variable.
+     */
+    protected static Hashtable mapStatusCodes = new Hashtable();
+
+
+    // ------------------------------------------------------ HTTP Status Codes
+
+    /*
+     * Server status codes; see RFC 2068.
+     */
+
+    /**
+     * Status code (100) indicating the client can continue.
+     */
+
+    public static final int SC_CONTINUE = 100;
+
+    
+    /**
+     * Status code (101) indicating the server is switching protocols
+     * according to Upgrade header.
+     */
+
+    public static final int SC_SWITCHING_PROTOCOLS = 101;
+
+    /**
+     * Status code (200) indicating the request succeeded normally.
+     */
+
+    public static final int SC_OK = 200;
+
+    /**
+     * Status code (201) indicating the request succeeded and created
+     * a new resource on the server.
+     */
+
+    public static final int SC_CREATED = 201;
+
+    /**
+     * Status code (202) indicating that a request was accepted for
+     * processing, but was not completed.
+     */
+
+    public static final int SC_ACCEPTED = 202;
+
+    /**
+     * Status code (203) indicating that the meta information presented
+     * by the client did not originate from the server.
+     */
+
+    public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
+
+    /**
+     * Status code (204) indicating that the request succeeded but that
+     * there was no new information to return.
+     */
+
+    public static final int SC_NO_CONTENT = 204;
+
+    /**
+     * Status code (205) indicating that the agent <em>SHOULD</em> reset
+     * the document view which caused the request to be sent.
+     */
+
+    public static final int SC_RESET_CONTENT = 205;
+
+    /**
+     * Status code (206) indicating that the server has fulfilled
+     * the partial GET request for the resource.
+     */
+
+    public static final int SC_PARTIAL_CONTENT = 206;
+
+    /**
+     * Status code (300) indicating that the requested resource
+     * corresponds to any one of a set of representations, each with
+     * its own specific location.
+     */
+
+    public static final int SC_MULTIPLE_CHOICES = 300;
+
+    /**
+     * Status code (301) indicating that the resource has permanently
+     * moved to a new location, and that future references should use a
+     * new URI with their requests.
+     */
+
+    public static final int SC_MOVED_PERMANENTLY = 301;
+
+    /**
+     * Status code (302) indicating that the resource has temporarily
+     * moved to another location, but that future references should
+     * still use the original URI to access the resource.
+     *
+     * This definition is being retained for backwards compatibility.
+     * SC_FOUND is now the preferred definition.
+     */
+
+    public static final int SC_MOVED_TEMPORARILY = 302;
+
+    /**
+    * Status code (302) indicating that the resource reside
+    * temporarily under a different URI. Since the redirection might
+    * be altered on occasion, the client should continue to use the
+    * Request-URI for future requests.(HTTP/1.1) To represent the
+    * status code (302), it is recommended to use this variable.
+    */
+
+    public static final int SC_FOUND = 302;
+
+    /**
+     * Status code (303) indicating that the response to the request
+     * can be found under a different URI.
+     */
+
+    public static final int SC_SEE_OTHER = 303;
+
+    /**
+     * Status code (304) indicating that a conditional GET operation
+     * found that the resource was available and not modified.
+     */
+
+    public static final int SC_NOT_MODIFIED = 304;
+
+    /**
+     * Status code (305) indicating that the requested resource
+     * <em>MUST</em> be accessed through the proxy given by the
+     * <code><em>Location</em></code> field.
+     */
+
+    public static final int SC_USE_PROXY = 305;
+
+     /**
+     * Status code (307) indicating that the requested resource 
+     * resides temporarily under a different URI. The temporary URI
+     * <em>SHOULD</em> be given by the <code><em>Location</em></code> 
+     * field in the response.
+     */
+
+     public static final int SC_TEMPORARY_REDIRECT = 307;
+
+    /**
+     * Status code (400) indicating the request sent by the client was
+     * syntactically incorrect.
+     */
+
+    public static final int SC_BAD_REQUEST = 400;
+
+    /**
+     * Status code (401) indicating that the request requires HTTP
+     * authentication.
+     */
+
+    public static final int SC_UNAUTHORIZED = 401;
+
+    /**
+     * Status code (402) reserved for future use.
+     */
+
+    public static final int SC_PAYMENT_REQUIRED = 402;
+
+    /**
+     * Status code (403) indicating the server understood the request
+     * but refused to fulfill it.
+     */
+
+    public static final int SC_FORBIDDEN = 403;
+
+    /**
+     * Status code (404) indicating that the requested resource is not
+     * available.
+     */
+
+    public static final int SC_NOT_FOUND = 404;
+
+    /**
+     * Status code (405) indicating that the method specified in the
+     * <code><em>Request-Line</em></code> is not allowed for the resource
+     * identified by the <code><em>Request-URI</em></code>.
+     */
+
+    public static final int SC_METHOD_NOT_ALLOWED = 405;
+
+    /**
+     * Status code (406) indicating that the resource identified by the
+     * request is only capable of generating response entities which have
+     * content characteristics not acceptable according to the accept
+     * headers sent in the request.
+     */
+
+    public static final int SC_NOT_ACCEPTABLE = 406;
+
+    /**
+     * Status code (407) indicating that the client <em>MUST</em> first
+     * authenticate itself with the proxy.
+     */
+
+    public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
+
+    /**
+     * Status code (408) indicating that the client did not produce a
+     * request within the time that the server was prepared to wait.
+     */
+
+    public static final int SC_REQUEST_TIMEOUT = 408;
+
+    /**
+     * Status code (409) indicating that the request could not be
+     * completed due to a conflict with the current state of the
+     * resource.
+     */
+
+    public static final int SC_CONFLICT = 409;
+
+    /**
+     * Status code (410) indicating that the resource is no longer
+     * available at the server and no forwarding address is known.
+     * This condition <em>SHOULD</em> be considered permanent.
+     */
+
+    public static final int SC_GONE = 410;
+
+    /**
+     * Status code (411) indicating that the request cannot be handled
+     * without a defined <code><em>Content-Length</em></code>.
+     */
+
+    public static final int SC_LENGTH_REQUIRED = 411;
+
+    /**
+     * Status code (412) indicating that the precondition given in one
+     * or more of the request-header fields evaluated to false when it
+     * was tested on the server.
+     */
+
+    public static final int SC_PRECONDITION_FAILED = 412;
+
+    /**
+     * Status code (413) indicating that the server is refusing to process
+     * the request because the request entity is larger than the server is
+     * willing or able to process.
+     */
+
+    public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413;
+
+    /**
+     * Status code (414) indicating that the server is refusing to service
+     * the request because the <code><em>Request-URI</em></code> is longer
+     * than the server is willing to interpret.
+     */
+
+    public static final int SC_REQUEST_URI_TOO_LONG = 414;
+
+    /**
+     * Status code (415) indicating that the server is refusing to service
+     * the request because the entity of the request is in a format not
+     * supported by the requested resource for the requested method.
+     */
+
+    public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
+
+    /**
+     * Status code (416) indicating that the server cannot serve the
+     * requested byte range.
+     */
+
+    public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
+
+    /**
+     * Status code (417) indicating that the server could not meet the
+     * expectation given in the Expect request header.
+     */
+
+    public static final int SC_EXPECTATION_FAILED = 417;
+
+    /**
+     * Status code (500) indicating an error inside the HTTP server
+     * which prevented it from fulfilling the request.
+     */
+
+    public static final int SC_INTERNAL_SERVER_ERROR = 500;
+
+    /**
+     * Status code (501) indicating the HTTP server does not support
+     * the functionality needed to fulfill the request.
+     */
+
+    public static final int SC_NOT_IMPLEMENTED = 501;
+
+    /**
+     * Status code (502) indicating that the HTTP server received an
+     * invalid response from a server it consulted when acting as a
+     * proxy or gateway.
+     */
+
+    public static final int SC_BAD_GATEWAY = 502;
+
+    /**
+     * Status code (503) indicating that the HTTP server is
+     * temporarily overloaded, and unable to handle the request.
+     */
+
+    public static final int SC_SERVICE_UNAVAILABLE = 503;
+
+    /**
+     * Status code (504) indicating that the server did not receive
+     * a timely response from the upstream server while acting as
+     * a gateway or proxy.
+     */
+
+    public static final int SC_GATEWAY_TIMEOUT = 504;
+
+    /**
+     * Status code (505) indicating that the server does not support
+     * or refuses to support the HTTP protocol version that was used
+     * in the request message.
+     */
+
+    public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
+    
+
+
+    /**
+     * Status code (413) indicating the server is refusing to
+     * process a request because the request entity is larger
+     * than the server is willing or able to process.
+     */
+    public static final int SC_REQUEST_TOO_LONG = 413;
+
+
+    // -------------------------------------------- Extended WebDav status code
+
+
+    /**
+     * Status code (207) indicating that the response requires
+     * providing status for multiple independent operations.
+     */
+    public static final int SC_MULTI_STATUS = 207;
+    // This one colides with HTTP 1.1
+    // "207 Parital Update OK"
+
+
+    /**
+     * Status code (418) indicating the entity body submitted with
+     * the PATCH method was not understood by the resource.
+     */
+    public static final int SC_UNPROCESSABLE_ENTITY = 418;
+    // This one colides with HTTP 1.1
+    // "418 Reauthentication Required"
+
+
+    /**
+     * Status code (419) indicating that the resource does not have
+     * sufficient space to record the state of the resource after the
+     * execution of this method.
+     */
+    public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
+    // This one colides with HTTP 1.1
+    // "419 Proxy Reauthentication Required"
+
+
+    /**
+     * Status code (420) indicating the method was not executed on
+     * a particular resource within its scope because some part of
+     * the method's execution failed causing the entire method to be
+     * aborted.
+     */
+    public static final int SC_METHOD_FAILURE = 420;
+
+
+    /**
+     * Status code (423) indicating the destination resource of a
+     * method is locked, and either the request did not contain a
+     * valid Lock-Info header, or the Lock-Info header identifies
+     * a lock held by another principal.
+     */
+    public static final int SC_LOCKED = 423;
+
+
+    // ------------------------------------------------------------ Initializer
+
+
+    static {
+        // HTTP 1.0 tatus Code
+        addStatusCodeMap(SC_OK, "OK");
+        addStatusCodeMap(SC_CREATED, "Created");
+        addStatusCodeMap(SC_ACCEPTED, "Accepted");
+        addStatusCodeMap(SC_NO_CONTENT, "No Content");
+        addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
+        addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
+        addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
+        addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
+        addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
+        addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
+        addStatusCodeMap(SC_NOT_FOUND, "Not Found");
+        addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
+        addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
+        addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
+        addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
+        addStatusCodeMap(SC_CONTINUE, "Continue");
+        addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
+        addStatusCodeMap(SC_CONFLICT, "Conflict");
+        addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
+        addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
+        addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
+        // WebDav Status Codes
+        addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
+        addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
+        addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
+                         "Insufficient Space On Resource");
+        addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
+        addStatusCodeMap(SC_LOCKED, "Locked");
+    }
+
+
+    // --------------------------------------------------------- Public Methods
+
+
+    /**
+     * Returns the HTTP status text for the HTTP or WebDav status code
+     * specified by looking it up in the static mapping.  This is a
+     * static function.
+     *
+     * @param   nHttpStatusCode [IN] HTTP or WebDAV status code
+     * @return  A string with a short descriptive phrase for the
+     *                  HTTP status code (e.g., "OK").
+     */
+    public static String getStatusText(int nHttpStatusCode) {
+        Integer intKey = new Integer(nHttpStatusCode);
+
+        if (!mapStatusCodes.containsKey(intKey)) {
+            return "";
+        } else {
+            return (String) mapStatusCodes.get(intKey);
+        }
+    }
+
+
+    // -------------------------------------------------------- protected 
Methods
+
+
+    /**
+     * Adds a new status code -> status text mapping.  This is a static
+     * method because the mapping is a static variable.
+     *
+     * @param   nKey    [IN] HTTP or WebDAV status code
+     * @param   strVal  [IN] HTTP status text
+     */
+    protected static void addStatusCodeMap(int nKey, String strVal) {
+        mapStatusCodes.put(new Integer(nKey), strVal);
+    }
+
+}
\ No newline at end of file

Propchange: 
tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/http/HttpStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to