You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/04/18 17:26:56 UTC

svn commit: r935355 - in /james/imap/trunk: decode/src/main/java/org/apache/james/imap/decode/ decode/src/test/java/org/apache/james/imap/decode/parser/ deployment/src/test/java/org/apache/james/imap/functional/ seda/src/main/java/org/apache/james/imap...

Author: norman
Date: Sun Apr 18 15:26:55 2010
New Revision: 935355

URL: http://svn.apache.org/viewvc?rev=935355&view=rev
Log:
Start to work on easier integration for NIO Frameworks by moving some stuff to abstract classes (IMAP-130)

Added:
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
    james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
    james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestStreamHandler.java
      - copied, changed from r934483, james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
Removed:
    james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
Modified:
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
    james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ImapHostSystem.java
    james/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java (original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java Sun Apr 18 15:26:55 2010
@@ -19,33 +19,23 @@
 
 package org.apache.james.imap.decode;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
 import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.decode.base.FixedLengthInputStream;
 
 /**
  * Wraps the client input reader with a bunch of convenience methods, allowing
  * lookahead=1 on the underlying character stream. TODO need to look at
- * encoding, and whether we should be wrapping an InputStream instead.
+ * encoding
  * 
  * @version $Revision: 109034 $
  */
-public class ImapRequestLineReader {
-    private InputStream input;
+public abstract class ImapRequestLineReader {
+    
 
-    private OutputStream output;
+    protected boolean nextSeen = false;
 
-    private boolean nextSeen = false;
-
-    private char nextChar; // unknown
-
-    public ImapRequestLineReader(InputStream input, OutputStream output) {
-        this.input = input;
-        this.output = output;
-    }
+    protected char nextChar; // unknown
 
     /**
      * Reads the next regular, non-space character in the current line. Spaces
@@ -82,26 +72,7 @@ public class ImapRequestLineReader {
      * @throws DecodingException
      *             If the end-of-stream is reached.
      */
-    public char nextChar() throws DecodingException {
-        if (!nextSeen) {
-            int next = -1;
-
-            try {
-                next = input.read();
-            } catch (IOException e) {
-                throw new DecodingException(HumanReadableText.SOCKET_IO_FAILURE, 
-                        "Error reading from stream.", e);
-            }
-            if (next == -1) {
-                throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, 
-                        "Unexpected end of stream.");
-            }
-
-            nextSeen = true;
-            nextChar = (char) next;
-        }
-        return nextChar;
-    }
+    public abstract char nextChar() throws DecodingException;
 
     /**
      * Moves the request line reader to end of the line, checking that no
@@ -162,33 +133,19 @@ public class ImapRequestLineReader {
      * @throws DecodingException
      *             If a char can't be read into each array element.
      */
-    public InputStream read(int size) throws DecodingException {
-
-        // Unset the next char.
-        nextSeen = false;
-        nextChar = 0;
-        return new FixedLengthInputStream(input, size);
-
-    }
+    public abstract InputStream read(int size) throws DecodingException;
 
     /**
      * Sends a server command continuation request '+' back to the client,
      * requesting more data to be sent.
      */
-    public void commandContinuationRequest() throws DecodingException {
-        try {
-            output.write('+');
-            output.write('\r');
-            output.write('\n');
-            output.flush();
-        } catch (IOException e) {
-            throw new DecodingException(
-                    HumanReadableText.SOCKET_IO_FAILURE, 
-                    "Unexpected exception in sending command continuation request.",
-                    e);
-        }
-    }
+    public abstract void commandContinuationRequest() throws DecodingException;
 
+    /**
+     * Consume the rest of the line
+     * 
+     * @throws DecodingException
+     */
     public void consumeLine() throws DecodingException {
         char next = nextChar();
         while (next != '\n') {

Added: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java?rev=935355&view=auto
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java (added)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java Sun Apr 18 15:26:55 2010
@@ -0,0 +1,116 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.decode;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.decode.base.FixedLengthInputStream;
+
+/**
+ * {@link ImapRequestLineReader} which use normal IO Streaming
+ *
+ */
+public class ImapRequestStreamLineReader extends ImapRequestLineReader{
+    private InputStream input;
+
+    private OutputStream output;
+    
+
+    public ImapRequestStreamLineReader(InputStream input, OutputStream output) {
+        this.input = input;
+        this.output = output;
+    }
+
+
+    /**
+     * Reads the next character in the current line. This method will continue
+     * to return the same character until the {@link #consume()} method is
+     * called.
+     * 
+     * @return The next character TODO: character encoding is variable and
+     *         cannot be determine at the token level; this char is not accurate
+     *         reported; should be an octet
+     * @throws DecodingException
+     *             If the end-of-stream is reached.
+     */
+    public char nextChar() throws DecodingException {
+        if (!nextSeen) {
+            int next = -1;
+
+            try {
+                next = input.read();
+            } catch (IOException e) {
+                throw new DecodingException(HumanReadableText.SOCKET_IO_FAILURE, 
+                        "Error reading from stream.", e);
+            }
+            if (next == -1) {
+                throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, 
+                        "Unexpected end of stream.");
+            }
+
+            nextSeen = true;
+            nextChar = (char) next;
+        }
+        return nextChar;
+    }
+
+
+    /**
+     * Reads and consumes a number of characters from the underlying reader,
+     * filling the char array provided. TODO: remove unnecessary copying of
+     * bits; line reader should maintain an internal ByteBuffer;
+     * 
+     * @param holder
+     *            A char array which will be filled with chars read from the
+     *            underlying reader.
+     * @throws DecodingException
+     *             If a char can't be read into each array element.
+     */
+    public InputStream read(int size) throws DecodingException {
+
+        // Unset the next char.
+        nextSeen = false;
+        nextChar = 0;
+        return new FixedLengthInputStream(input, size);
+
+    }
+    
+    /**
+     * Sends a server command continuation request '+' back to the client,
+     * requesting more data to be sent.
+     */
+    public void commandContinuationRequest() throws DecodingException {
+        try {
+            output.write('+');
+            output.write('\r');
+            output.write('\n');
+            output.flush();
+        } catch (IOException e) {
+            throw new DecodingException(
+                    HumanReadableText.SOCKET_IO_FAILURE, 
+                    "Unexpected exception in sending command continuation request.",
+                    e);
+        }
+    }
+
+}

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java Sun Apr 18 15:26:55 2010
@@ -30,6 +30,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.apache.james.imap.decode.parser.FetchCommandParser;
 import org.junit.Before;
 import org.junit.Test;
@@ -82,7 +83,7 @@ public class FetchCommandParserPartialFe
     @Test
     public void testShouldNotParseZeroLength() throws Exception {
         try {
-            ImapRequestLineReader reader = new ImapRequestLineReader(
+            ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                     new ByteArrayInputStream("1 (BODY[]<20.0>)\r\n"
                             .getBytes("US-ASCII")), new ByteArrayOutputStream());
             parser.decode(command, reader, "A01", false, new MockLogger());                
@@ -95,7 +96,7 @@ public class FetchCommandParserPartialFe
 
     private void check(String input, final IdRange[] idSet,
             final boolean useUids, final FetchData data, final String tag) throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
         context.checking(new Expectations() {{

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java Sun Apr 18 15:26:55 2010
@@ -35,6 +35,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -194,7 +195,7 @@ public class SearchCommandParserAndParen
     private void check(Input in) throws UnsupportedEncodingException,
             DecodingException {
         String input = in.input + "\r\n";
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java Sun Apr 18 15:26:55 2010
@@ -37,6 +37,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -108,7 +109,7 @@ public class SearchCommandParserCharsetT
                     with(equal(HumanReadableText.BAD_CHARSET)),
                     with(equal(StatusResponse.ResponseCode.badCharset(charsetNames))));
         }});
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
         parser.decode(command, reader, TAG, false, new MockLogger());
@@ -179,7 +180,7 @@ public class SearchCommandParserCharsetT
 
     private void checkUTF8Valid(byte[] term, final SearchKey key)
             throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(NioUtils.add(NioUtils.add(CHARSET,
                         term), BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
                 new ByteArrayOutputStream());
@@ -189,7 +190,7 @@ public class SearchCommandParserCharsetT
 
     private void checkValid(String input, final SearchKey key, boolean isFirst,
             String charset) throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes(charset)),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java Sun Apr 18 15:26:55 2010
@@ -31,6 +31,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.DayMonthYear;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -118,7 +119,7 @@ public class SearchCommandParserNotTest 
     }
 
     private void checkValid(String input, final SearchKey key) throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java Sun Apr 18 15:26:55 2010
@@ -31,6 +31,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.DayMonthYear;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -179,7 +180,7 @@ public class SearchCommandParserOrTest {
     private void checkValid(Input one, Input two) throws Exception {
         String input = "OR " + one.input + " " + two.input + "\r\n";
         SearchKey key = SearchKey.buildOr(one.key, two.key);
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java Sun Apr 18 15:26:55 2010
@@ -38,6 +38,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -158,7 +159,7 @@ public class SearchCommandParserQuotedCh
     @Test
     public void testShouldDecoderLengthyQuotedCharset() throws Exception {
         SearchKey key = SearchKey.buildBcc(LENGTHY_NON_ASCII_SEARCH_TERM);
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(add(add(CHARSET, "BCC"
                         .getBytes("US-ASCII")),
                         BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM)),
@@ -170,7 +171,7 @@ public class SearchCommandParserQuotedCh
     @Test
     public void testShouldDecoderQuotedCharset() throws Exception {
         SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(add(add(CHARSET, "BCC"
                         .getBytes("US-ASCII")),
                         BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM)),
@@ -195,7 +196,7 @@ public class SearchCommandParserQuotedCh
                     with(equal(HumanReadableText.BAD_CHARSET)),
                     with(equal(StatusResponse.ResponseCode.badCharset(charsetNames))));
         }});
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
         parser.decode(command, reader, TAG, false, new MockLogger());
@@ -205,7 +206,7 @@ public class SearchCommandParserQuotedCh
     public void testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset()
             throws Exception {
         try {
-            ImapRequestLineReader reader = new ImapRequestLineReader(
+            ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                     new ByteArrayInputStream(add("CHARSET US-ASCII BCC "
                             .getBytes("US-ASCII"), BYTES_NON_ASCII_SEARCH_TERM)),
                     new ByteArrayOutputStream());
@@ -281,7 +282,7 @@ public class SearchCommandParserQuotedCh
 
     private void checkUTF8Valid(byte[] term, final SearchKey key)
             throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(add(add(CHARSET, term),
                         BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
                 new ByteArrayOutputStream());
@@ -291,7 +292,7 @@ public class SearchCommandParserQuotedCh
 
     private void checkValid(String input, final SearchKey key, boolean isFirst,
             String charset) throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes(charset)),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java Sun Apr 18 15:26:55 2010
@@ -30,6 +30,7 @@ import org.apache.james.imap.api.ImapMes
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -105,7 +106,7 @@ public class SearchCommandParserSearchKe
 
     private void checkValid(String input, final SearchKey key) throws Exception {
         input = input + "\r\n";
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java Sun Apr 18 15:26:55 2010
@@ -32,6 +32,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -386,7 +387,7 @@ public class SearchCommandParserSearchKe
 
    
     private void checkValid(String input, final SearchKey key) throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 
@@ -739,7 +740,7 @@ public class SearchCommandParserSearchKe
 
     private void checkInvalid(String input, final SearchKey key)
             throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java Sun Apr 18 15:26:55 2010
@@ -35,6 +35,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -197,7 +198,7 @@ public class SearchCommandParserTopLevel
         buffer.append("\r\n");
         String input = buffer.toString();
         SearchKey key = SearchKey.buildAnd(keys);
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java (original)
+++ james/imap/trunk/decode/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java Sun Apr 18 15:26:55 2010
@@ -29,6 +29,7 @@ import org.apache.james.imap.api.ImapCom
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -73,7 +74,7 @@ public class StoreCommandParserTest {
     private void check(String input, final IdRange[] idSet,final boolean silent,
             final Boolean sign, final Flags flags, final boolean useUids, final String tag)
             throws Exception {
-        ImapRequestLineReader reader = new ImapRequestLineReader(
+        ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes("US-ASCII")),
                 new ByteArrayOutputStream());
 

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ImapHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ImapHostSystem.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ImapHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ImapHostSystem.java Sun Apr 18 15:26:55 2010
@@ -33,7 +33,7 @@ import org.apache.james.imap.api.process
 import org.apache.james.imap.decode.ImapDecoder;
 import org.apache.james.imap.encode.ImapEncoder;
 import org.apache.james.imap.mailbox.MailboxSession.User;
-import org.apache.james.imap.main.ImapRequestHandler;
+import org.apache.james.imap.main.ImapRequestStreamHandler;
 import org.apache.james.imap.main.ImapSessionImpl;
 import org.apache.james.test.functional.HostSystem;
 
@@ -105,7 +105,7 @@ public abstract class ImapHostSystem imp
 
         ByteBufferInputStream in;
 
-        ImapRequestHandler handler;
+        ImapRequestStreamHandler handler;
 
         ImapSessionImpl session;
 
@@ -114,7 +114,7 @@ public abstract class ImapHostSystem imp
         public Session(Continuation continuation) {
             out = new ByteBufferOutputStream(continuation);
             in = new ByteBufferInputStream();
-            handler = new ImapRequestHandler(decoder, processor, encoder);
+            handler = new ImapRequestStreamHandler(decoder, processor, encoder);
             session = new ImapSessionImpl();
             session.setLog(new SilentLog());
         }

Added: james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java?rev=935355&view=auto
==============================================================================
--- james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java (added)
+++ james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java Sun Apr 18 15:26:55 2010
@@ -0,0 +1,139 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.main;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.response.ImapResponseMessage;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.api.process.ImapProcessor.Responder;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.imap.encode.ImapResponseComposer;
+
+public abstract class AbstractImapRequestHandler {
+
+
+    protected static final byte[] ABANDON_SIGNOFF = { '*', ' ', 'B', 'Y', 'E',
+            ' ', 'A', 'b', 'a', 'n', 'd', 'o', 'n', 'e', 'd', '\r', '\n' };
+
+    protected static final byte[] MAILBOX_DELETED_SIGNOFF = { '*', ' ', 'B', 'Y',
+            'E', ' ', 'S', 'e', 'l', 'e', 'c', 't', 'e', 'd', ' ', 'm', 'a',
+            'i', 'l', 'b', 'o', 'x', ' ', 'h', 'a', 's', ' ', 'b', 'e', 'e',
+            'n', ' ', 'd', 'e', 'l', 'e', 't', 'e', 'd', '\r', '\n' };
+    
+
+    
+    private final ImapDecoder decoder;
+    protected final ImapProcessor processor;
+    private final ImapEncoder encoder;
+
+    public AbstractImapRequestHandler(final ImapDecoder decoder,
+            final ImapProcessor processor, final ImapEncoder encoder) {
+        this.decoder = decoder;
+        this.processor = processor;
+        this.encoder = encoder;
+    }
+    
+    protected boolean doProcessRequest(ImapRequestLineReader request,
+            ImapResponseComposer response, ImapSession session) {
+        ImapMessage message = decoder.decode(request, session);
+        final ResponseEncoder responseEncoder = new ResponseEncoder(encoder,
+                response, session);
+        processor.process(message, responseEncoder, session);
+        
+        final boolean result;
+        final IOException failure = responseEncoder.getFailure();
+        if (failure == null) {
+            result = true;
+        } else {
+            result = false;
+            final Log logger = session.getLog();
+            logger.info(failure.getMessage());
+            if (logger.isDebugEnabled()) {
+                logger.debug("Failed to write " + message, failure);
+            }
+        }
+        return result;
+    }
+
+
+    protected boolean isSelectedMailboxDeleted(ImapSession session) {
+        final boolean selectedMailboxIsDeleted;
+        final SelectedMailbox mailbox = session.getSelected();
+        if (mailbox != null) {
+            selectedMailboxIsDeleted = mailbox.isDeletedByOtherSession();
+        } else {
+            selectedMailboxIsDeleted = false;
+        }
+        return selectedMailboxIsDeleted;
+    }
+
+    
+    /**
+     * Silents swallows all responses.
+     */
+    static final class SilentResponder implements Responder {
+
+        public void respond(ImapResponseMessage message) {
+            // Swallow
+        }
+    }
+    
+    private static final class ResponseEncoder implements Responder {
+        private final ImapEncoder encoder;
+        private final ImapSession session;
+        private final ImapResponseComposer composer;
+
+        private IOException failure;
+        
+
+        public ResponseEncoder(final ImapEncoder encoder,
+                final ImapResponseComposer composer, final ImapSession session) {
+            super();
+            this.encoder = encoder;
+            this.composer = composer;
+            this.session = session;
+        }
+
+        public void respond(final ImapResponseMessage message) {
+            try {
+                encoder.encode(message, composer, session);
+            } catch (IOException failure) {
+                this.failure = failure;
+            }
+        }
+
+        /**
+         * Gets the recorded failure.
+         * 
+         * @return the failure, or null when no failure has occurred
+         */
+        public final IOException getFailure() {
+            return failure;
+        }
+
+    }
+}

Copied: james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestStreamHandler.java (from r934483, james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java)
URL: http://svn.apache.org/viewvc/james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestStreamHandler.java?p2=james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestStreamHandler.java&p1=james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java&r1=934483&r2=935355&rev=935355&view=diff
==============================================================================
--- james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java (original)
+++ james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestStreamHandler.java Sun Apr 18 15:26:55 2010
@@ -24,45 +24,25 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.commons.logging.Log;
-import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
-import org.apache.james.imap.api.process.SelectedMailbox;
-import org.apache.james.imap.api.process.ImapProcessor.Responder;
+import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapDecoder;
 import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
 import org.apache.james.imap.encode.ImapEncoder;
-import org.apache.james.imap.encode.ImapResponseComposer;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.request.SystemMessage;
 
 /**
  * @version $Revision: 109034 $
  */
-public final class ImapRequestHandler  {
-
-    private static final byte[] ABANDON_SIGNOFF = { '*', ' ', 'B', 'Y', 'E',
-            ' ', 'A', 'b', 'a', 'n', 'd', 'o', 'n', 'e', 'd', '\r', '\n' };
-
-    private static final byte[] MAILBOX_DELETED_SIGNOFF = { '*', ' ', 'B', 'Y',
-            'E', ' ', 'S', 'e', 'l', 'e', 'c', 't', 'e', 'd', ' ', 'm', 'a',
-            'i', 'l', 'b', 'o', 'x', ' ', 'h', 'a', 's', ' ', 'b', 'e', 'e',
-            'n', ' ', 'd', 'e', 'l', 'e', 't', 'e', 'd', '\r', '\n' };
-    
-    private final ImapDecoder decoder;
+public final class ImapRequestStreamHandler extends AbstractImapRequestHandler{
 
-    private final ImapProcessor processor;
-
-    private final ImapEncoder encoder;
-
-    public ImapRequestHandler(final ImapDecoder decoder,
+    public ImapRequestStreamHandler(final ImapDecoder decoder,
             final ImapProcessor processor, final ImapEncoder encoder) {
-        this.decoder = decoder;
-        this.processor = processor;
-        this.encoder = encoder;
+        super(decoder, processor, encoder);
     }
 
     /**
@@ -83,7 +63,7 @@ public final class ImapRequestHandler  {
             writeSignoff(output, session);
             result = false;
         } else {
-            ImapRequestLineReader request = new ImapRequestLineReader(input,
+            ImapRequestLineReader request = new ImapRequestStreamLineReader(input,
                     output);
 
             final Log logger = session.getLog();
@@ -136,17 +116,6 @@ public final class ImapRequestHandler  {
         }
     }
 
-    private boolean isSelectedMailboxDeleted(ImapSession session) {
-        final boolean selectedMailboxIsDeleted;
-        final SelectedMailbox mailbox = session.getSelected();
-        if (mailbox != null) {
-            selectedMailboxIsDeleted = mailbox.isDeletedByOtherSession();
-        } else {
-            selectedMailboxIsDeleted = false;
-        }
-        return selectedMailboxIsDeleted;
-    }
-
     private void abandon(OutputStream out, ImapSession session) {
         if (session != null){
             try {
@@ -163,70 +132,5 @@ public final class ImapRequestHandler  {
         processor.process(SystemMessage.FORCE_LOGOUT, new SilentResponder(), session);
     }
 
-    private boolean doProcessRequest(ImapRequestLineReader request,
-            ImapResponseComposer response, ImapSession session) {
-        ImapMessage message = decoder.decode(request, session);
-        final ResponseEncoder responseEncoder = new ResponseEncoder(encoder,
-                response, session);
-        processor.process(message, responseEncoder, session);
-        
-        final boolean result;
-        final IOException failure = responseEncoder.getFailure();
-        if (failure == null) {
-            result = true;
-        } else {
-            result = false;
-            final Log logger = session.getLog();
-            logger.info(failure.getMessage());
-            if (logger.isDebugEnabled()) {
-                logger.debug("Failed to write " + message, failure);
-            }
-        }
-        return result;
-    }
-
-    /**
-     * Silents swallows all responses.
-     */
-    private static final class SilentResponder implements Responder {
-
-        public void respond(ImapResponseMessage message) {
-            // Swallow
-        }
-    }
-    
-    private static final class ResponseEncoder implements Responder {
-        private final ImapEncoder encoder;
-        private final ImapSession session;
-        private final ImapResponseComposer composer;
-
-        private IOException failure;
-        
-
-        public ResponseEncoder(final ImapEncoder encoder,
-                final ImapResponseComposer composer, final ImapSession session) {
-            super();
-            this.encoder = encoder;
-            this.composer = composer;
-            this.session = session;
-        }
-
-        public void respond(final ImapResponseMessage message) {
-            try {
-                encoder.encode(message, composer, session);
-            } catch (IOException failure) {
-                this.failure = failure;
-            }
-        }
-
-        /**
-         * Gets the recorded failure.
-         * 
-         * @return the failure, or null when no failure has occurred
-         */
-        public final IOException getFailure() {
-            return failure;
-        }
 
-    }
 }

Modified: james/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java (original)
+++ james/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java Sun Apr 18 15:26:55 2010
@@ -39,7 +39,7 @@ import org.junit.runner.RunWith;
 public class ImapRequestHandlerAdandonConnectionTest {
 
     /** System under test */
-    ImapRequestHandler subject;
+    ImapRequestStreamHandler subject;
     
     // Fakes
     /** Stores output */
@@ -64,7 +64,7 @@ public class ImapRequestHandlerAdandonCo
         encoderStub = mockery.mock(ImapEncoder.class);
         sessionStub = mockery.mock(ImapSession.class);
         // System under test
-        subject = new ImapRequestHandler(decoderStub, processorStub, encoderStub);
+        subject = new ImapRequestStreamHandler(decoderStub, processorStub, encoderStub);
     }
     
     @Test

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java Sun Apr 18 15:26:55 2010
@@ -20,7 +20,6 @@ package org.apache.james.imap.store;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=935355&r1=935354&r2=935355&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Sun Apr 18 15:26:55 2010
@@ -636,6 +636,7 @@ public abstract class StoreMailbox<Id> i
             toMailbox.copy(originalRows, session);
 
         } catch (MessagingException e) {
+            e.printStackTrace();
             throw new MailboxException(HumanReadableText.FAILURE_MAIL_PARSE, e);
         }
     }



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