Author: norman
Date: Fri Jan 14 16:41:15 2011
New Revision: 1059065
URL: http://svn.apache.org/viewvc?rev=1059065&view=rev
Log:
Still work in progress to move to push model
Removed:
james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ContinuationReader.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestStreamLineReader.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
Modified:
james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/IdleCommandParser.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/ListCommandParser.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/stream/ImapRequestStreamHandler.java
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/message/request/IdleRequest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/main/IdRangeParseTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
james/imap/branches/nio-refactoring/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
Modified:
james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ImapConstants.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
(original)
+++
james/imap/branches/nio-refactoring/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
Fri Jan 14 16:41:15 2011
@@ -20,6 +20,10 @@
package org.apache.james.imap.api;
public interface ImapConstants {
+
+ public final static String NEXT_DECODER = "NEXT_DECODER";
+
+
// Basic response types
public static final String OK = "OK";
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
Fri Jan 14 16:41:15 2011
@@ -21,7 +21,6 @@ package org.apache.james.imap.decode;
import java.io.IOException;
-import org.apache.james.imap.api.ContinuationReader;
import org.apache.james.imap.api.display.HumanReadableText;
import org.apache.james.imap.encode.ImapResponseComposer;
@@ -32,7 +31,7 @@ import org.apache.james.imap.encode.Imap
*
* @version $Revision: 109034 $
*/
-public abstract class ImapRequestLineReader implements ContinuationReader {
+public class ImapRequestLineReader {
protected boolean nextSeen = false;
@@ -41,9 +40,45 @@ public abstract class ImapRequestLineRea
private ImapResponseComposer composer;
- public ImapRequestLineReader(ImapResponseComposer composer) {
+ private byte[] data;
+ private int pos = 0;
+
+ public ImapRequestLineReader(byte [] data, ImapResponseComposer composer) {
this.composer = composer;
+ this.data = data;
+ }
+
+
+ /**
+ * 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;
+
+ if (pos == data.length) {
+ throw new
DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS,
+ "Unexpected end of stream.");
+ }
+ next = data[pos++];
+
+
+
+ nextSeen = true;
+ nextChar = (char) next;
+ }
+ return nextChar;
}
+
+
/**
* Reads the next regular, non-space character in the current line. Spaces
* are skipped over, but end-of-line characters will cause a
@@ -68,18 +103,6 @@ public abstract class ImapRequestLineRea
return next;
}
- /**
- * 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 abstract char nextChar() throws DecodingException;
/**
* Moves the request line reader to end of the line, checking that no
@@ -147,7 +170,7 @@ public abstract class ImapRequestLineRea
public String readContinuation() throws IOException {
// Consume the '\n' from the previous line.
- consume();
+ //consume();
StringBuilder sb = new StringBuilder();
char next = nextChar();
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
Fri Jan 14 16:41:15 2011
@@ -19,9 +19,7 @@
package org.apache.james.imap.decode.base;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
@@ -37,7 +35,6 @@ import java.util.List;
import javax.mail.Flags;
-import org.apache.commons.io.IOUtils;
import org.apache.james.imap.api.ImapCommand;
import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.ImapMessage;
@@ -47,10 +44,10 @@ import org.apache.james.imap.api.message
import org.apache.james.imap.api.message.response.StatusResponseFactory;
import org.apache.james.imap.api.process.ImapSession;
import org.apache.james.imap.decode.DecoderUtils;
+import org.apache.james.imap.decode.DecodingException;
import org.apache.james.imap.decode.ImapCommandParser;
import org.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.decode.MessagingImapCommandParser;
-import org.apache.james.imap.decode.DecodingException;
/**
* <p>
@@ -164,7 +161,7 @@ public abstract class AbstractImapComman
case '"':
return consumeQuoted(request, charset);
case '{':
- return consumeLiteral(request, charset);
+ return consumeLiteralLine(request, charset);
default:
return atom(request);
}
@@ -180,7 +177,7 @@ public abstract class AbstractImapComman
case '"':
return consumeQuoted(request);
case '{':
- return consumeLiteral(request, null);
+ return consumeLiteralLine(request, null);
default:
String value = atom(request);
if ("NIL".equals(value)) {
@@ -307,24 +304,31 @@ public abstract class AbstractImapComman
* @param charset ,
* or null for <code>US-ASCII</code>
*/
- protected String consumeLiteral(final ImapRequestLineReader request,
+ protected String consumeLiteralLine(final ImapRequestLineReader request,
final Charset charset) throws DecodingException {
if (charset == null) {
- return consumeLiteral(request, US_ASCII);
+ return consumeLiteralLine(request, US_ASCII);
} else {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
- IOUtils.copy(consumeLiteral(request),out);
+
+ //TODO: This is not really RFC conform
+ int size = consumeLiteralSize(request);
+ byte[] data = new byte[size];
+
+ int read = 0;
+ while( read < size) {
+ data[read++] = (byte) request.nextChar();
+ request.consume();
+ }
+ return new String(data, charset);
+ //IOUtils.copy(consumeLiteral(request),out);
} catch (IOException e) {
throw new DecodingException(HumanReadableText.BAD_IO_ENCODING,
"Bad character encoding", e);
}
- final byte[] bytes = out.toByteArray();
- final ByteBuffer buffer = ByteBuffer.wrap(bytes);
- return decode(charset, buffer);
}
}
- protected int consumeLiteral(final ImapRequestLineReader request) throws
DecodingException {
+ protected int consumeLiteralSize(final ImapRequestLineReader request)
throws DecodingException {
// The 1st character must be '{'
consumeChar(request, '{');
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
Fri Jan 14 16:41:15 2011
@@ -46,7 +46,6 @@ import org.apache.james.imap.message.req
public class AppendCommandParser extends AbstractImapCommandParser {
public final String BYTES_WRITTEN = AppendCommandParser.class.getName() +
"_BYTES_WRITTEN";
- public final static String NEXT_DECODER = "NEXT_DECODER";
public AppendCommandParser() {
super(ImapCommand.authenticatedStateCommand(ImapConstants.APPEND_COMMAND_NAME));
@@ -105,7 +104,7 @@ public class AppendCommandParser extends
try {
final File file = File.createTempFile("imap-append", ".m64");
final FileOutputStream out = new FileOutputStream(file);
- final int size = consumeLiteral(request);
+ final int size = consumeLiteralSize(request);
session.setAttribute(BYTES_WRITTEN, 0);
ImapDecoder nextDecoder = new ImapDecoder() {
@@ -119,7 +118,7 @@ public class AppendCommandParser extends
}
if (bytes == size) {
request.eol();
- session.setAttribute(NEXT_DECODER, null);
+ session.setAttribute(ImapConstants.NEXT_DECODER,
null);
return new AppendRequest(command, mailboxName, f,
dt, new DeleteOnCloseInputStream(new FileInputStream(file), file) , tag);
}
@@ -131,7 +130,7 @@ public class AppendCommandParser extends
return null;
}
};
- session.setAttribute(NEXT_DECODER, nextDecoder);
+ session.setAttribute(ImapConstants.NEXT_DECODER, nextDecoder);
return new ContinuationRequest(command, tag, nextDecoder);
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/IdleCommandParser.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/IdleCommandParser.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/IdleCommandParser.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/IdleCommandParser.java
Fri Jan 14 16:41:15 2011
@@ -46,7 +46,7 @@ public class IdleCommandParser extends A
protected ImapMessage decode(ImapCommand command,
ImapRequestLineReader request, String tag, ImapSession session)
throws DecodingException {
endLine(request);
- final ImapMessage result = new IdleRequest(command, request, tag);
+ final ImapMessage result = new IdleRequest(command, tag);
return result;
}
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/ListCommandParser.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/ListCommandParser.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/ListCommandParser.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/ListCommandParser.java
Fri Jan 14 16:41:15 2011
@@ -55,7 +55,7 @@ public class ListCommandParser extends A
case '"':
return consumeQuoted(request);
case '{':
- return consumeLiteral(request, null);
+ return consumeLiteralLine(request, null);
default:
return consumeWord(request, new ListCharValidator());
}
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/AbstractImapRequestHandler.java
Fri Jan 14 16:41:15 2011
@@ -22,6 +22,7 @@ package org.apache.james.imap.main;
import java.io.IOException;
import org.apache.commons.logging.Log;
+import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.ImapMessage;
import org.apache.james.imap.api.message.response.ImapResponseMessage;
import org.apache.james.imap.api.process.ImapProcessor;
@@ -85,11 +86,11 @@ public abstract class AbstractImapReques
}
private ImapDecoder getDecoder(ImapSession session) {
- ImapDecoder nextDecoder = (ImapDecoder)
session.getAttribute(AppendCommandParser.NEXT_DECODER);
- if (nextDecoder == null) {
+ Object nextDecoder = session.getAttribute(ImapConstants.NEXT_DECODER);
+ if (nextDecoder == null || !(nextDecoder instanceof ImapDecoder)) {
return this.decoder;
} else {
- return nextDecoder;
+ return (ImapDecoder)nextDecoder;
}
}
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/stream/ImapRequestStreamHandler.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/stream/ImapRequestStreamHandler.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/stream/ImapRequestStreamHandler.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/main/stream/ImapRequestStreamHandler.java
Fri Jan 14 16:41:15 2011
@@ -19,8 +19,10 @@
package org.apache.james.imap.main.stream;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import org.apache.commons.logging.Log;
@@ -30,7 +32,6 @@ import org.apache.james.imap.api.process
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.ImapRequestStreamLineReader;
import org.apache.james.imap.encode.ImapEncoder;
import org.apache.james.imap.encode.ImapResponseComposer;
import org.apache.james.imap.main.AbstractImapRequestHandler;
@@ -39,10 +40,9 @@ import org.apache.james.imap.message.req
/**
* @version $Revision: 109034 $
*/
-public final class ImapRequestStreamHandler extends AbstractImapRequestHandler{
+public final class ImapRequestStreamHandler extends AbstractImapRequestHandler
{
- public ImapRequestStreamHandler(final ImapDecoder decoder,
- final ImapProcessor processor, final ImapEncoder encoder) {
+ public ImapRequestStreamHandler(final ImapDecoder decoder, final
ImapProcessor processor, final ImapEncoder encoder) {
super(decoder, processor, encoder);
}
@@ -57,54 +57,62 @@ public final class ImapRequestStreamHand
*
* @return whether additional commands are expected.
*/
- public boolean handleRequest(InputStream input, OutputStream output,
- ImapSession session) {
+ public boolean handleRequest(InputStream input, OutputStream output,
ImapSession session) {
final boolean result;
if (isSelectedMailboxDeleted(session)) {
writeSignoff(output, session);
result = false;
+ return result;
} else {
ImapResponseComposer composer = new
OutputStreamImapResponseComposer(output);
-
- ImapRequestLineReader request = new
ImapRequestStreamLineReader(input,
- composer);
-
final Log logger = session.getLog();
+
try {
- request.nextChar();
- } catch (DecodingException e) {
- logger.debug("Unexpected end of line. Cannot handle request: ",
- e);
- abandon(output, session);
- return false;
- }
- if (doProcessRequest(request, composer, session)) {
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(input));
+ ImapRequestLineReader request = new
ImapRequestLineReader((reader.readLine() + "\r\n").getBytes(), composer);
+
+ System.out.println(request.nextChar());
- try {
- // Consume the rest of the line, throwing away any extras.
- // This allows us
- // to clean up after a protocol error.
- request.consumeLine();
- } catch (DecodingException e) {
- // Cannot clean up. No recovery is therefore possible.
- // Abandon connection.
- if (logger.isInfoEnabled()) {
- logger.info("Fault during clean up: " +
e.getMessage());
+ if (doProcessRequest(request, composer, session)) {
+
+ try {
+ // Consume the rest of the line, throwing away any
+ // extras.
+ // This allows us
+ // to clean up after a protocol error.
+ request.consumeLine();
+ } catch (DecodingException e) {
+ // Cannot clean up. No recovery is therefore possible.
+ // Abandon connection.
+ if (logger.isInfoEnabled()) {
+ logger.info("Fault during clean up: " +
e.getMessage());
+ }
+ logger.debug("Abandoning after fault in clean up", e);
+ abandon(output, session);
+ return false;
}
- logger.debug("Abandoning after fault in clean up", e);
+
+ result = !(ImapSessionState.LOGOUT == session.getState());
+ } else {
+ logger.debug("Connection was abandoned after request
processing failed.");
+ result = false;
abandon(output, session);
- return false;
+
}
- result = !(ImapSessionState.LOGOUT == session.getState());
- } else {
- logger.debug("Connection was abandoned after request
processing failed.");
- result = false;
+ return result;
+ } catch (DecodingException e) {
+ logger.debug("Unexpected end of line. Cannot handle request:
", e);
+ abandon(output, session);
+ return false;
+ } catch (IOException e) {
+ logger.debug("Unexpected end of line. Cannot handle request:
", e);
abandon(output, session);
+ return false;
}
+
}
- return result;
}
private void writeSignoff(OutputStream output, ImapSession session) {
@@ -117,7 +125,7 @@ public final class ImapRequestStreamHand
}
private void abandon(OutputStream out, ImapSession session) {
- if (session != null){
+ if (session != null) {
try {
session.logout();
} catch (Throwable t) {
@@ -132,5 +140,4 @@ public final class ImapRequestStreamHand
processor.process(SystemMessage.FORCE_LOGOUT, new SilentResponder(),
session);
}
-
}
Modified:
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/message/request/IdleRequest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/message/request/IdleRequest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/message/request/IdleRequest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/message/request/IdleRequest.java
Fri Jan 14 16:41:15 2011
@@ -18,19 +18,14 @@
****************************************************************/
package org.apache.james.imap.message.request;
-import org.apache.james.imap.api.ContinuationReader;
import org.apache.james.imap.api.ImapCommand;
public class IdleRequest extends AbstractImapRequest {
- private final ContinuationReader reader;
- public IdleRequest(ImapCommand command, ContinuationReader reader, String
tag) {
+ public IdleRequest(ImapCommand command, String tag) {
super(tag, command);
- this.reader = reader;
}
- public ContinuationReader getContinuationReader() {
- return reader;
- }
+
}
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/main/IdRangeParseTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/main/IdRangeParseTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/main/IdRangeParseTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/main/IdRangeParseTest.java
Fri Jan 14 16:41:15 2011
@@ -19,9 +19,6 @@
package org.apache.james.imap.decode.main;
import static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-
import junit.framework.Assert;
import org.apache.james.imap.api.ImapCommand;
@@ -31,7 +28,6 @@ import org.apache.james.imap.api.message
import org.apache.james.imap.api.process.ImapSession;
import org.apache.james.imap.decode.DecodingException;
import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestStreamLineReader;
import org.apache.james.imap.decode.base.AbstractImapCommandParser;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.junit.Test;
@@ -102,8 +98,7 @@ public class IdRangeParseTest {
private IdRange[] ranges(String rangesAsString) throws
DecodingException {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream((rangesAsString + "\r\n").getBytes()),
+ ImapRequestLineReader reader = new
ImapRequestLineReader((rangesAsString + "\r\n").getBytes(),
new MockImapResponseComposer());
return parser.parseIdRange(reader);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
Fri Jan 14 16:41:15 2011
@@ -19,25 +19,21 @@
package org.apache.james.imap.decode.parser;
-import java.io.ByteArrayInputStream;
-
import org.apache.james.imap.api.ImapCommand;
import org.apache.james.imap.api.ImapMessage;
import org.apache.james.imap.api.message.BodyFetchElement;
import org.apache.james.imap.api.message.FetchData;
import org.apache.james.imap.api.message.IdRange;
import org.apache.james.imap.api.process.ImapSession;
-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.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
@RunWith(JMock.class)
public class FetchCommandParserPartialFetchTest {
@@ -82,9 +78,8 @@ public class FetchCommandParserPartialFe
@Test
public void testShouldNotParseZeroLength() throws Exception {
try {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream("1 (BODY[]<20.0>)\r\n"
- .getBytes("US-ASCII")), new
MockImapResponseComposer());
+ ImapRequestLineReader reader = new ImapRequestLineReader("1
(BODY[]<20.0>)\r\n"
+ .getBytes("US-ASCII"), new
MockImapResponseComposer());
parser.decode(command, reader, "A01", false, session);
throw new Exception("Number of octets must be non-zero");
@@ -95,8 +90,8 @@ 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 ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ input.getBytes("US-ASCII"),
new MockImapResponseComposer());
parser.decode(command, reader, tag, useUids, session);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
Fri Jan 14 16:41:15 2011
@@ -33,7 +33,6 @@ 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.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -191,8 +190,7 @@ public class SearchCommandParserAndParen
private void check(Input in) throws UnsupportedEncodingException,
DecodingException {
String input = in.input + "\r\n";
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(input.getBytes("US-ASCII"),
new MockImapResponseComposer());
final SearchKey result = parser.decode(reader);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
Fri Jan 14 16:41:15 2011
@@ -21,7 +21,6 @@ package org.apache.james.imap.decode.par
import static org.junit.Assert.assertEquals;
-import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashSet;
@@ -36,7 +35,6 @@ import org.apache.james.imap.api.message
import org.apache.james.imap.api.message.response.StatusResponseFactory;
import org.apache.james.imap.api.process.ImapSession;
import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestStreamLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -111,8 +109,7 @@ public class SearchCommandParserCharsetT
with(equal(StatusResponse.ResponseCode.badCharset(charsetNames))));
oneOf (session).getLog(); returnValue(new MockLogger());
}});
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream("CHARSET BOGUS
".getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader("CHARSET
BOGUS ".getBytes("US-ASCII"),
new MockImapResponseComposer());
parser.decode(command, reader, TAG, false, session);
}
@@ -182,9 +179,9 @@ public class SearchCommandParserCharsetT
private void checkUTF8Valid(byte[] term, final SearchKey key)
throws Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(NioUtils.add(NioUtils.add(CHARSET,
- term), BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ NioUtils.add(NioUtils.add(CHARSET,
+ term), BYTES_UTF8_NON_ASCII_SEARCH_TERM),
new MockImapResponseComposer());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
@@ -192,8 +189,7 @@ public class SearchCommandParserCharsetT
private void checkValid(String input, final SearchKey key, boolean isFirst,
String charset) throws Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes(charset)),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(input.getBytes(charset),
new MockImapResponseComposer());
final SearchKey searchKey = parser.searchKey(reader, null, isFirst);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
Fri Jan 14 16:41:15 2011
@@ -29,7 +29,6 @@ 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.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -115,8 +114,7 @@ public class SearchCommandParserNotTest
}
private void checkValid(String input, final SearchKey key) throws
Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(input.getBytes("US-ASCII"),
new MockImapResponseComposer());
assertEquals(key, parser.searchKey(reader, null, false));
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
Fri Jan 14 16:41:15 2011
@@ -29,7 +29,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.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -175,8 +175,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 ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(input.getBytes("US-ASCII"),
new MockImapResponseComposer());
assertEquals(key, parser.searchKey(reader, null, false));
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
Fri Jan 14 16:41:15 2011
@@ -37,7 +37,7 @@ import org.apache.james.imap.api.message
import org.apache.james.imap.api.process.ImapSession;
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.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -159,8 +159,8 @@ public class SearchCommandParserQuotedCh
@Test
public void testShouldDecoderLengthyQuotedCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(LENGTHY_NON_ASCII_SEARCH_TERM);
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(add(add(CHARSET, "BCC"
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ (add(add(CHARSET, "BCC"
.getBytes("US-ASCII")),
BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM)),
new MockImapResponseComposer());
@@ -171,8 +171,8 @@ public class SearchCommandParserQuotedCh
@Test
public void testShouldDecoderQuotedCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(add(add(CHARSET, "BCC"
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ (add(add(CHARSET, "BCC"
.getBytes("US-ASCII")),
BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM)),
new MockImapResponseComposer());
@@ -197,8 +197,7 @@ public class SearchCommandParserQuotedCh
with(equal(StatusResponse.ResponseCode.badCharset(charsetNames))));
oneOf(session).getLog(); returnValue(new MockLogger());
}});
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream("CHARSET BOGUS
".getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader("CHARSET
BOGUS ".getBytes("US-ASCII"),
new MockImapResponseComposer());
parser.decode(command, reader, TAG, false, session);
}
@@ -207,9 +206,8 @@ public class SearchCommandParserQuotedCh
public void
testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset()
throws Exception {
try {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(add("CHARSET US-ASCII BCC "
- .getBytes("US-ASCII"),
BYTES_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(add("CHARSET US-ASCII BCC "
+ .getBytes("US-ASCII"),
BYTES_NON_ASCII_SEARCH_TERM),
new MockImapResponseComposer());
parser.decode(command, reader, TAG, false, session);
fail("A protocol exception should be thrown when charset is
incompatible with input");
@@ -283,9 +281,8 @@ public class SearchCommandParserQuotedCh
private void checkUTF8Valid(byte[] term, final SearchKey key)
throws Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(add(add(CHARSET, term),
- BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(add(add(CHARSET, term),
+ BYTES_UTF8_NON_ASCII_SEARCH_TERM),
new MockImapResponseComposer());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
@@ -293,8 +290,7 @@ public class SearchCommandParserQuotedCh
private void checkValid(String input, final SearchKey key, boolean isFirst,
String charset) throws Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes(charset)),
+ ImapRequestLineReader reader = new
ImapRequestLineReader(input.getBytes(charset),
new MockImapResponseComposer());
final SearchKey searchKey = parser.searchKey(reader, null, isFirst);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
Fri Jan 14 16:41:15 2011
@@ -28,7 +28,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.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -102,8 +102,8 @@ public class SearchCommandParserSearchKe
private void checkValid(String input, final SearchKey key) throws
Exception {
input = input + "\r\n";
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ (input.getBytes("US-ASCII")),
new MockImapResponseComposer());
final SearchKey searchKey = parser.searchKey(reader, null, false);
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
Fri Jan 14 16:41:15 2011
@@ -30,7 +30,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.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -382,8 +382,8 @@ public class SearchCommandParserSearchKe
private void checkValid(String input, final SearchKey key) throws
Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ (input.getBytes("US-ASCII")),
new MockImapResponseComposer());
assertEquals(key, parser.searchKey(reader, null, false));
@@ -735,8 +735,8 @@ public class SearchCommandParserSearchKe
private void checkInvalid(String input, final SearchKey key)
throws Exception {
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ input.getBytes("US-ASCII"),
new MockImapResponseComposer());
try {
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
Fri Jan 14 16:41:15 2011
@@ -33,7 +33,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.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -193,8 +193,8 @@ public class SearchCommandParserTopLevel
buffer.append("\r\n");
String input = buffer.toString();
SearchKey key = SearchKey.buildAnd(keys);
- ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ input.getBytes("US-ASCII"),
new MockImapResponseComposer());
assertEquals(input, key, parser.decode(reader));
Modified:
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
(original)
+++
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
Fri Jan 14 16:41:15 2011
@@ -28,7 +28,7 @@ import org.apache.james.imap.api.ImapMes
import org.apache.james.imap.api.message.IdRange;
import org.apache.james.imap.api.process.ImapSession;
import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.encode.MockImapResponseComposer;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -74,8 +74,8 @@ 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 ImapRequestStreamLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ (input.getBytes("US-ASCII")),
new MockImapResponseComposer());
parser.decode(command, reader, tag, useUids, session);
Modified:
james/imap/branches/nio-refactoring/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
URL:
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java?rev=1059065&r1=1059064&r2=1059065&view=diff
==============================================================================
---
james/imap/branches/nio-refactoring/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
(original)
+++
james/imap/branches/nio-refactoring/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
Fri Jan 14 16:41:15 2011
@@ -26,8 +26,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.james.imap.api.ContinuationReader;
import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.ImapMessage;
import org.apache.james.imap.api.ImapSessionUtils;
import org.apache.james.imap.api.display.HumanReadableText;
@@ -36,6 +36,8 @@ import org.apache.james.imap.api.message
import org.apache.james.imap.api.message.response.StatusResponseFactory;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.decode.ImapRequestLineReader;
import org.apache.james.imap.message.request.IdleRequest;
import org.apache.james.imap.message.response.ContinuationResponse;
import org.apache.james.mailbox.MailboxException;
@@ -58,41 +60,52 @@ public class IdleProcessor extends Abstr
return (message instanceof IdleRequest);
}
- protected void doProcess(ImapRequest message, ImapSession session,
- String tag, ImapCommand command, Responder responder) {
+ protected void doProcess(ImapRequest message, ImapSession session, final
String tag, final ImapCommand command, Responder responder) {
try {
- IdleRequest request = (IdleRequest) message;
- ContinuationReader reader = request.getContinuationReader();
-
responder.respond(new
ContinuationResponse(HumanReadableText.IDLING));
unsolicitedResponses(session, responder, false);
+ final AtomicBoolean closed = new AtomicBoolean(false);
+
+ session.setAttribute(ImapConstants.NEXT_DECODER, new ImapDecoder()
{
+
+ public ImapMessage decode(ImapRequestLineReader request,
ImapSession session) {
+ String line;
+ try {
+ line = request.readContinuation();
+
+ } catch (IOException e) {
+ // TODO: What should we do here?
+ final StatusResponse response = factory.taggedNo(tag,
command, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
+ return response;
+ } finally {
+ synchronized (session) {
+ closed.set(true);
+
+ }
+ }
+
+ if (!"DONE".equals(line.toUpperCase())) {
+
+ StatusResponse response = factory.taggedBad(tag,
command, HumanReadableText.INVALID_COMMAND);
+ session.setAttribute(ImapConstants.NEXT_DECODER, null);
+ return response;
+ } else {
+ final StatusResponse response = factory.taggedOk(tag,
command, HumanReadableText.COMPLETED);
+ return response;
+ }
+ }
+ });
MailboxManager mailboxManager = getMailboxManager();
MailboxSession mailboxSession =
ImapSessionUtils.getMailboxSession(session);
- AtomicBoolean closed = new AtomicBoolean(false);
-
- String line = null;
+
try {
- mailboxManager.addListener(session.getSelected().getPath(),
- new IdleMailboxListener(closed, session, responder),
mailboxSession);
-
- line = reader.readContinuation();
+ mailboxManager.addListener(session.getSelected().getPath(),
new IdleMailboxListener(closed, session, responder), mailboxSession);
+
} finally {
- synchronized (session) {
- closed.set(true);
- }
- }
- if (!"DONE".equals(line.toUpperCase())) {
- StatusResponse response = factory.taggedBad(tag, command,
- HumanReadableText.INVALID_COMMAND);
- responder.respond(response);
- } else {
- okComplete(command, tag, responder);
+
}
- } catch (IOException e) {
- // TODO: What should we do here?
- no(command, tag, responder,
HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
} catch (MailboxException e) {
// TODO: What should we do here?
no(command, tag, responder,
HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]