alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jetty example source code file (continue.patch)

This example Jetty source code file (continue.patch) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jetty tags/keywords

ignoreme, illegalstateexception, index, index, ioexception, servletinputstream, start, state, state, state_header, todo, todo, unknown, unknown

The Jetty continue.patch source code

Index: VERSION.txt
===================================================================
--- VERSION.txt	(revision 2128)
+++ VERSION.txt	(working copy)
@@ -1,5 +1,6 @@
 jetty-SNAPSHOT
  + Improved JSON parsing from Readers
+ + Delay 100 continues until getInputStream
 
 jetty-6.1.6rc0 - 3 October 2007
  + Added jetty.lib system property to start.config
Index: modules/jetty/src/test/java/org/mortbay/jetty/DumpHandler.java
===================================================================
--- modules/jetty/src/test/java/org/mortbay/jetty/DumpHandler.java	(revision 2127)
+++ modules/jetty/src/test/java/org/mortbay/jetty/DumpHandler.java	(working copy)
@@ -28,6 +28,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.log.Log;
 import org.mortbay.util.StringUtil;
 import org.mortbay.util.ajax.Continuation;
 import org.mortbay.util.ajax.ContinuationSupport;
@@ -168,7 +169,7 @@
                 writer.write(new String(content,0,len));
         }
         catch(IOException e)
-        {
+        {   
             writer.write(e.toString());
         }
         
@@ -178,16 +179,24 @@
         // commit now
         writer.flush();
         response.setContentLength(buf.size()+1000);
-        buf.writeTo(out);
-        
-        buf.reset();
-        writer.flush();
-        for (int pad=998-buf.size();pad-->0;)
-            writer.write(" ");
-        writer.write("\015\012");
-        writer.flush();
-        buf.writeTo(out);
-        
-        response.setHeader("IgnoreMe","ignored");
+
+        try
+        {
+            buf.writeTo(out);
+
+            buf.reset();
+            writer.flush();
+            for (int pad=998-buf.size();pad-->0;)
+                writer.write(" ");
+            writer.write("\015\012");
+            writer.flush();
+            buf.writeTo(out);
+
+            response.setHeader("IgnoreMe","ignored");
+        }
+        catch(Exception e)
+        {
+            Log.ignore(e);
+        }
     }
 }
\ No newline at end of file
Index: modules/jetty/src/test/java/org/mortbay/jetty/RFC2616Test.java
===================================================================
--- modules/jetty/src/test/java/org/mortbay/jetty/RFC2616Test.java	(revision 2133)
+++ modules/jetty/src/test/java/org/mortbay/jetty/RFC2616Test.java	(working copy)
@@ -383,9 +383,11 @@
                                             "\n",true);
             offset=checkContains(response,offset,"HTTP/1.1 100 ","8.2.3 expect 100")+1;
             checkNotContained(response,offset,"HTTP/1.1 200","8.2.3 expect 100");
+            /* can't test this with localconnector.
             response=connector.getResponses("654321\015\012");
             offset=checkContains(response,offset,"HTTP/1.1 200","8.2.3 expect 100")+1;
             offset=checkContains(response,offset,"654321","8.2.3 expect 100")+1;
+            */
 
         }
         catch (Exception e)
Index: modules/jetty/src/main/java/org/mortbay/jetty/HttpConnection.java
===================================================================
--- modules/jetty/src/main/java/org/mortbay/jetty/HttpConnection.java	(revision 2127)
+++ modules/jetty/src/main/java/org/mortbay/jetty/HttpConnection.java	(working copy)
@@ -283,8 +283,21 @@
     /**
      * @return The input stream for this connection. The stream will be created if it does not already exist.
      */
-    public ServletInputStream getInputStream()
+    public ServletInputStream getInputStream() throws IOException
     {
+        if (_expect == HttpHeaderValues.CONTINUE_ORDINAL)
+        {
+            // TODO delay sending 100 response until a read is attempted.
+            if (((HttpParser)_parser).getHeaderBuffer()==null || ((HttpParser)_parser).getHeaderBuffer().length()<2)
+            {
+                _generator.setResponse(HttpStatus.ORDINAL_100_Continue, null);
+                _generator.completeHeader(null, true);
+                _generator.complete();
+                _generator.reset(false);
+            }
+            _expect = UNKNOWN;
+        }
+
         if (_in == null) 
             _in = new HttpParser.Input(((HttpParser)_parser),_connector.getMaxIdleTime());
         return _in;
@@ -543,6 +556,14 @@
                 
                 if (!retrying)
                 {
+                    if (_expect == HttpHeaderValues.CONTINUE_ORDINAL)
+                    {
+                        // Continue not sent so don't parse any content 
+                        _expect = UNKNOWN;
+                        if (_parser instanceof HttpParser)
+                            ((HttpParser)_parser).setState(HttpParser.STATE_END);
+                    }
+                    
                     if (_request.getContinuation()!=null)
                     {
                         Log.debug("continuation still pending {}");
@@ -565,7 +586,7 @@
                     }
                     else
                     {
-                        _response.complete(); // TODO ????????????
+                        _response.complete(); 
                     }
                 }
             }
@@ -798,14 +819,6 @@
                     {
                         if (_expect == HttpHeaderValues.CONTINUE_ORDINAL)
                         {
-                            // TODO delay sending 100 response until a read is attempted.
-                            if (((HttpParser)_parser).getHeaderBuffer()==null || ((HttpParser)_parser).getHeaderBuffer().length()<2)
-                            {
-                                _generator.setResponse(HttpStatus.ORDINAL_100_Continue, null);
-                                _generator.completeHeader(null, true);
-                                _generator.complete();
-                                _generator.reset(false);
-                            }
                         }
                         else if (_expect == HttpHeaderValues.PROCESSING_ORDINAL)
                         {
@@ -825,7 +838,7 @@
                 _request.setCharacterEncodingUnchecked(_charset);
             
             // Either handle now or wait for first content
-            if (((HttpParser)_parser).getContentLength()<=0 && !((HttpParser)_parser).isChunking())
+            if ((((HttpParser)_parser).getContentLength()<=0 && !((HttpParser)_parser).isChunking())||_expect==HttpHeaderValues.CONTINUE_ORDINAL) 
                 handleRequest();
             else
                 _delayedHandling=true;
Index: modules/jetty/src/main/java/org/mortbay/jetty/AbstractGenerator.java
===================================================================
--- modules/jetty/src/main/java/org/mortbay/jetty/AbstractGenerator.java	(revision 2127)
+++ modules/jetty/src/main/java/org/mortbay/jetty/AbstractGenerator.java	(working copy)
@@ -316,7 +316,8 @@
      */
     public void setVersion(int version)
     {
-        if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START");
+        if (_state != STATE_HEADER) 
+            throw new IllegalStateException("STATE!=START "+_state);
         _version = version;
         if (_version==HttpVersions.HTTP_0_9_ORDINAL && _method!=null)
             _noContent=true;

Other Jetty examples (source code examples)

Here is a short list of links related to this Jetty continue.patch source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.