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 fe...@apache.org on 2011/04/04 16:59:14 UTC
svn commit: r1088657 [7/9] - in /james/server/trunk:
container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/
core/src/main/java/org/apache/james/core/
data-api/src/main/java/org/apache/james/domainlist/api/ da...
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java Mon Apr 4 14:59:11 2011
@@ -43,9 +43,8 @@ import org.jboss.netty.handler.codec.fra
/**
* {@link FrameDecoder} which will decode via and {@link ImapDecoder} instance
- *
*/
-public class ImapRequestFrameDecoder extends FrameDecoder implements ChannelAttributeSupport{
+public class ImapRequestFrameDecoder extends FrameDecoder implements ChannelAttributeSupport {
private final ImapDecoder decoder;
private final int inMemorySizeLimit;
@@ -57,7 +56,7 @@ public class ImapRequestFrameDecoder ext
this.decoder = decoder;
this.inMemorySizeLimit = inMemorySizeLimit;
}
-
+
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
ctx.setAttachment(new HashMap<String, Object>());
@@ -66,31 +65,39 @@ public class ImapRequestFrameDecoder ext
/*
* (non-Javadoc)
- * @see org.jboss.netty.handler.codec.frame.FrameDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, org.jboss.netty.buffer.ChannelBuffer)
+ *
+ * @see
+ * org.jboss.netty.handler.codec.frame.FrameDecoder#decode(org.jboss.netty
+ * .channel.ChannelHandlerContext, org.jboss.netty.channel.Channel,
+ * org.jboss.netty.buffer.ChannelBuffer)
*/
@SuppressWarnings("unchecked")
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
buffer.markReaderIndex();
boolean retry = false;
-
+
ImapRequestLineReader reader;
- // check if we failed before and if we already know how much data we need to sucess next run
- Map<String,Object> attachment = (Map<String, Object>) ctx.getAttachment();
+ // check if we failed before and if we already know how much data we
+ // need to sucess next run
+ Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment();
int size = -1;
if (attachment.containsKey(NEEDED_DATA)) {
retry = true;
- size = (Integer) attachment.get(NEEDED_DATA);
+ size = (Integer) attachment.get(NEEDED_DATA);
// now see if the buffer hold enough data to process.
if (size != NettyImapRequestLineReader.NotEnoughDataException.UNKNOWN_SIZE && size > buffer.readableBytes()) {
-
- // check if we have a inMemorySize limit and if so if the expected size will fit into it
+
+ // check if we have a inMemorySize limit and if so if the
+ // expected size will fit into it
if (inMemorySizeLimit > 0 && inMemorySizeLimit < size) {
-
- // ok seems like it will not fit in the memory limit so we need to store it in a temporary file
+
+ // ok seems like it will not fit in the memory limit so we
+ // need to store it in a temporary file
final File f;
int written;
-
- // check if we have created a temporary file already or if we need to create a new one
+
+ // check if we have created a temporary file already or if
+ // we need to create a new one
if (attachment.containsKey(STORED_DATA)) {
f = (File) attachment.get(STORED_DATA);
written = (Integer) attachment.get(WRITTEN_DATA);
@@ -101,28 +108,25 @@ public class ImapRequestFrameDecoder ext
attachment.put(WRITTEN_DATA, written);
}
-
-
- InputStream bufferIn = null;
+
+ InputStream bufferIn = null;
OutputStream out = null;
try {
bufferIn = new ChannelBufferInputStream(buffer);
out = new FileOutputStream(f, true);
-
+
// write the needed data to the file
int i = -1;
while (written < size && (i = bufferIn.read()) != -1) {
- out.write(i);
- written++;
+ out.write(i);
+ written++;
}
-
-
-
+
} finally {
- IOUtils.closeQuietly(bufferIn);
- IOUtils.closeQuietly(out);
- }
- // Check if all needed data was streamed to the file.
+ IOUtils.closeQuietly(bufferIn);
+ IOUtils.closeQuietly(out);
+ }
+ // Check if all needed data was streamed to the file.
if (written == size) {
reader = new NettyStreamImapRequestLineReader(channel, new FileInputStream(f) {
/**
@@ -133,30 +137,31 @@ public class ImapRequestFrameDecoder ext
super.close();
f.delete();
}
-
- }, retry);
+
+ }, retry);
} else {
attachment.put(WRITTEN_DATA, written);
return null;
}
-
+
} else {
buffer.resetReaderIndex();
return null;
}
-
+
} else {
-
+
reader = new NettyImapRequestLineReader(channel, buffer, retry);
}
} else {
reader = new NettyImapRequestLineReader(channel, buffer, retry);
}
-
- try {
+
+ try {
ImapMessage message = decoder.decode(reader, (ImapSession) attributes.get(channel));
-
- // if size is != -1 the case was a literal. if thats the case we should not consume the line
+
+ // if size is != -1 the case was a literal. if thats the case we
+ // should not consume the line
// See JAMES-1199
if (size == -1) {
reader.consumeLine();
@@ -164,7 +169,7 @@ public class ImapRequestFrameDecoder ext
attachment.clear();
return message;
} catch (NettyImapRequestLineReader.NotEnoughDataException e) {
- // this exception was thrown because we don't have enough data yet
+ // this exception was thrown because we don't have enough data yet
int neededData = e.getNeededSize();
// store the needed data size for later usage
attachment.put(NEEDED_DATA, neededData);
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java Mon Apr 4 14:59:11 2011
@@ -20,8 +20,6 @@ package org.apache.james.imapserver.nett
/**
* Just some constants which are used with the Netty implementation
- *
- *
*/
public interface NettyConstants {
final static String ZLIB_DECODER = "zlibDecoder";
@@ -34,7 +32,7 @@ public interface NettyConstants {
final static String GROUP_HANDLER = "groupHandler";
final static String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
final static String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
- final static String CONNECTION_COUNT_HANDLER= "connectionCountHandler";
- final static String CHUNK_WRITE_HANDLER= "chunkWriteHandler";
+ final static String CONNECTION_COUNT_HANDLER = "connectionCountHandler";
+ final static String CHUNK_WRITE_HANDLER = "chunkWriteHandler";
}
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapProcessorFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapProcessorFactory.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapProcessorFactory.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapProcessorFactory.java Mon Apr 4 14:59:11 2011
@@ -38,22 +38,18 @@ public class NettyImapProcessorFactory {
public static final ImapProcessor createDefaultProcessor(final MailboxManager mailboxManager, final SubscriptionManager subscriptionManager, int batchSize) {
return createXListSupportingProcessor(mailboxManager, subscriptionManager, null, batchSize);
}
-
+
public static final ImapProcessor createXListSupportingProcessor(final MailboxManager mailboxManager, final SubscriptionManager subscriptionManager, MailboxTyper mailboxTyper) {
return createXListSupportingProcessor(mailboxManager, subscriptionManager, mailboxTyper, ImapConstants.DEFAULT_BATCH_SIZE);
}
-
+
public static final ImapProcessor createXListSupportingProcessor(final MailboxManager mailboxManager, final SubscriptionManager subscriptionManager, MailboxTyper mailboxTyper, int batchSize) {
final StatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
- final UnknownRequestProcessor unknownRequestImapProcessor = new UnknownRequestProcessor(
- statusResponseFactory);
- final ImapProcessor imap4rev1Chain = DefaultProcessorChain
- .createDefaultChain(unknownRequestImapProcessor,
- mailboxManager, subscriptionManager, statusResponseFactory, mailboxTyper, batchSize);
+ final UnknownRequestProcessor unknownRequestImapProcessor = new UnknownRequestProcessor(statusResponseFactory);
+ final ImapProcessor imap4rev1Chain = DefaultProcessorChain.createDefaultChain(unknownRequestImapProcessor, mailboxManager, subscriptionManager, statusResponseFactory, mailboxTyper, batchSize);
ChunkFetchProcessor fetchProcessor = new ChunkFetchProcessor(imap4rev1Chain, mailboxManager, statusResponseFactory, batchSize);
- final ImapProcessor result = new ImapResponseMessageProcessor(
- fetchProcessor);
+ final ImapProcessor result = new ImapResponseMessageProcessor(fetchProcessor);
return result;
}
-
+
}
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java Mon Apr 4 14:59:11 2011
@@ -29,27 +29,29 @@ import org.jboss.netty.buffer.ChannelBuf
import org.jboss.netty.channel.Channel;
/**
- * {@link ImapRequestLineReader} implementation which will write to a {@link Channel} and read from a {@link ChannelBuffer}. Please
- * see the docs on {@link #nextChar()} and {@link #read(int)} to understand the special behavior of this implementation
- *
+ * {@link ImapRequestLineReader} implementation which will write to a
+ * {@link Channel} and read from a {@link ChannelBuffer}. Please see the docs on
+ * {@link #nextChar()} and {@link #read(int)} to understand the special behavior
+ * of this implementation
*/
-public class NettyImapRequestLineReader extends AbstractNettyImapRequestLineReader{
+public class NettyImapRequestLineReader extends AbstractNettyImapRequestLineReader {
private ChannelBuffer buffer;
private int read = 0;
-
+
public NettyImapRequestLineReader(Channel channel, ChannelBuffer buffer, boolean retry) {
super(channel, retry);
this.buffer = buffer;
-
- }
+ }
/**
- * Return the next char to read. This will return the same char on every call till {@link #consume()} was called.
+ * Return the next char to read. This will return the same char on every
+ * call till {@link #consume()} was called.
*
- * This implementation will throw a {@link NotEnoughDataException} if the wrapped {@link ChannelBuffer} contains not enough
- * data to read the next char
+ * This implementation will throw a {@link NotEnoughDataException} if the
+ * wrapped {@link ChannelBuffer} contains not enough data to read the next
+ * char
*/
public char nextChar() throws DecodingException {
if (!nextSeen) {
@@ -68,8 +70,9 @@ public class NettyImapRequestLineReader
}
/**
- * Return a {@link ChannelBufferInputStream} if the wrapped {@link ChannelBuffer} contains enough data. If not
- * it will throw a {@link NotEnoughDataException}
+ * Return a {@link ChannelBufferInputStream} if the wrapped
+ * {@link ChannelBuffer} contains enough data. If not it will throw a
+ * {@link NotEnoughDataException}
*/
public InputStream read(int size, boolean extraCRLF) throws DecodingException {
int crlf = 0;
@@ -77,15 +80,16 @@ public class NettyImapRequestLineReader
crlf = 2;
}
// Check if we have enough data
- if (size + crlf> buffer.readableBytes()) {
- // ok let us throw a exception which till the decoder how many more bytes we need
+ if (size + crlf > buffer.readableBytes()) {
+ // ok let us throw a exception which till the decoder how many more
+ // bytes we need
throw new NotEnoughDataException(size + read + crlf);
}
-
+
// Unset the next char.
nextSeen = false;
nextChar = 0;
-
+
ChannelBufferInputStream in = new ChannelBufferInputStream(buffer, size);
if (extraCRLF) {
return new EolInputStream(this, in);
@@ -94,14 +98,14 @@ public class NettyImapRequestLineReader
}
}
-
/**
- * {@link RuntimeException} which will get thrown by {@link NettyImapRequestLineReader#nextChar()} and {@link NettyImapRequestLineReader#read(int)} if not
- * enough data is readable in the underlying {@link ChannelBuffer}
- *
+ * {@link RuntimeException} which will get thrown by
+ * {@link NettyImapRequestLineReader#nextChar()} and
+ * {@link NettyImapRequestLineReader#read(int)} if not enough data is
+ * readable in the underlying {@link ChannelBuffer}
*/
@SuppressWarnings("serial")
- public final class NotEnoughDataException extends RuntimeException{
+ public final class NotEnoughDataException extends RuntimeException {
public final static int UNKNOWN_SIZE = -1;
private int size;
@@ -109,11 +113,11 @@ public class NettyImapRequestLineReader
public NotEnoughDataException(int size) {
this.size = size;
}
-
+
public NotEnoughDataException() {
this(UNKNOWN_SIZE);
}
-
+
/**
* Return the size of the data which is needed
*
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java Mon Apr 4 14:59:11 2011
@@ -36,7 +36,7 @@ import org.jboss.netty.handler.codec.com
import org.jboss.netty.handler.ssl.SslHandler;
import org.slf4j.Logger;
-public class NettyImapSession implements ImapSession, NettyConstants{
+public class NettyImapSession implements ImapSession, NettyConstants {
private ImapSessionState state = ImapSessionState.NON_AUTHENTICATED;
private SelectedMailbox selectedMailbox;
@@ -48,7 +48,6 @@ public class NettyImapSession implements
private ChannelHandlerContext context;
private int handlerCount;
-
public NettyImapSession(ChannelHandlerContext context, Logger log, SSLContext sslContext, String[] enabledCipherSuites, boolean compress) {
this.context = context;
this.log = new SessionLog(context.getChannel().getId() + "", log);
@@ -58,16 +57,18 @@ public class NettyImapSession implements
}
/**
- * Return the wrapped {@link Channel} which this {@link ImapSession} is bound to
+ * Return the wrapped {@link Channel} which this {@link ImapSession} is
+ * bound to
*
* @return channel
*/
public Channel getChannel() {
return context.getChannel();
}
-
+
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#logout()
*/
public void logout() {
@@ -77,6 +78,7 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#authenticated()
*/
public void authenticated() {
@@ -85,6 +87,7 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#deselect()
*/
public void deselect() {
@@ -94,7 +97,10 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
- * @see org.apache.james.imap.api.process.ImapSession#selected(org.apache.james.imap.api.process.SelectedMailbox)
+ *
+ * @see
+ * org.apache.james.imap.api.process.ImapSession#selected(org.apache.james
+ * .imap.api.process.SelectedMailbox)
*/
public void selected(SelectedMailbox mailbox) {
this.state = ImapSessionState.SELECTED;
@@ -104,6 +110,7 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#getSelected()
*/
public SelectedMailbox getSelected() {
@@ -112,6 +119,7 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#getState()
*/
public ImapSessionState getState() {
@@ -127,16 +135,22 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
- * @see org.apache.james.imap.api.process.ImapSession#getAttribute(java.lang.String)
+ *
+ * @see
+ * org.apache.james.imap.api.process.ImapSession#getAttribute(java.lang.
+ * String)
*/
public Object getAttribute(String key) {
- final Object result = attributesByKey .get(key);
+ final Object result = attributesByKey.get(key);
return result;
}
/*
* (non-Javadoc)
- * @see org.apache.james.imap.api.process.ImapSession#setAttribute(java.lang.String, java.lang.Object)
+ *
+ * @see
+ * org.apache.james.imap.api.process.ImapSession#setAttribute(java.lang.
+ * String, java.lang.Object)
*/
public void setAttribute(String key, Object value) {
if (value == null) {
@@ -148,11 +162,13 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#startTLS()
*/
public boolean startTLS() {
- if (supportStartTLS() == false) return false;
- context.getChannel().setReadable(false);
+ if (supportStartTLS() == false)
+ return false;
+ context.getChannel().setReadable(false);
SslHandler filter = new SslHandler(sslContext.createSSLEngine(), false);
filter.getEngine().setUseClientMode(false);
@@ -160,14 +176,15 @@ public class NettyImapSession implements
filter.getEngine().setEnabledCipherSuites(enabledCipherSuites);
}
context.getPipeline().addFirst(SSL_HANDLER, filter);
-
- context.getChannel().setReadable(true);
+
+ context.getChannel().setReadable(true);
return true;
}
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#supportStartTLS()
*/
public boolean supportStartTLS() {
@@ -176,7 +193,9 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
- * @see org.apache.james.imap.api.process.ImapSession#isCompressionSupported()
+ *
+ * @see
+ * org.apache.james.imap.api.process.ImapSession#isCompressionSupported()
*/
public boolean isCompressionSupported() {
return compress;
@@ -184,15 +203,17 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#startCompression()
*/
public boolean startCompression() {
- if (isCompressionSupported() == false) return false;
-
- context.getChannel().setReadable(false);
+ if (isCompressionSupported() == false)
+ return false;
+
+ context.getChannel().setReadable(false);
ZlibDecoder decoder = new ZlibDecoder(ZlibWrapper.NONE);
ZlibEncoder encoder = new ZlibEncoder(ZlibWrapper.NONE, 5);
-
+
// Check if we have the SslHandler in the pipeline already
// if so we need to move the compress encoder and decoder
// behind it in the chain
@@ -201,11 +222,10 @@ public class NettyImapSession implements
context.getPipeline().addFirst(ZLIB_DECODER, decoder);
context.getPipeline().addFirst(ZLIB_ENCODER, encoder);
} else {
- context.getPipeline().addAfter(SSL_HANDLER, ZLIB_DECODER,decoder);
- context.getPipeline().addAfter(SSL_HANDLER, ZLIB_ENCODER,encoder);
+ context.getPipeline().addAfter(SSL_HANDLER, ZLIB_DECODER, decoder);
+ context.getPipeline().addAfter(SSL_HANDLER, ZLIB_ENCODER, encoder);
}
-
context.getChannel().setReadable(true);
return true;
@@ -213,7 +233,10 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
- * @see org.apache.james.imap.api.process.ImapSession#pushLineHandler(org.apache.james.imap.api.process.ImapLineHandler)
+ *
+ * @see
+ * org.apache.james.imap.api.process.ImapSession#pushLineHandler(org.apache
+ * .james.imap.api.process.ImapLineHandler)
*/
public void pushLineHandler(ImapLineHandler lineHandler) {
context.getPipeline().addBefore("requestDecoder", "lineHandler" + handlerCount++, new ImapLineHandlerAdapter(lineHandler));
@@ -221,14 +244,16 @@ public class NettyImapSession implements
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#popLineHandler()
*/
public void popLineHandler() {
context.getPipeline().remove("lineHandler" + --handlerCount);
}
-
+
/*
* (non-Javadoc)
+ *
* @see org.apache.james.imap.api.process.ImapSession#getLog()
*/
public Logger getLog() {
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyStreamImapRequestLineReader.java Mon Apr 4 14:59:11 2011
@@ -27,7 +27,7 @@ import org.apache.james.imap.decode.base
import org.apache.james.imap.decode.base.FixedLengthInputStream;
import org.jboss.netty.channel.Channel;
-public class NettyStreamImapRequestLineReader extends AbstractNettyImapRequestLineReader{
+public class NettyStreamImapRequestLineReader extends AbstractNettyImapRequestLineReader {
private InputStream in;
@@ -54,12 +54,10 @@ public class NettyStreamImapRequestLineR
try {
next = in.read();
} catch (IOException e) {
- throw new DecodingException(HumanReadableText.SOCKET_IO_FAILURE,
- "Error reading from stream.", 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.");
+ throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Unexpected end of stream.");
}
nextSeen = true;
@@ -68,7 +66,6 @@ public class NettyStreamImapRequestLineR
return nextChar;
}
-
/**
* Reads and consumes a number of characters from the underlying reader,
* filling the char array provided. TODO: remove unnecessary copying of
@@ -87,15 +84,14 @@ public class NettyStreamImapRequestLineR
nextChar = 0;
FixedLengthInputStream fin = new FixedLengthInputStream(this.in, size);
if (extraCRLF) {
- return new EolInputStream(this, fin);
+ return new EolInputStream(this, fin);
} else {
return fin;
}
}
-
+
public void dispose() throws IOException {
in.close();
}
-
}
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java Mon Apr 4 14:59:11 2011
@@ -22,11 +22,10 @@ import org.jboss.netty.channel.socket.Se
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
/**
- * IMAPServer which use old IO and not NIO. If you want to use NIO you should use {@link IMAPServer}
- *
- *
+ * IMAPServer which use old IO and not NIO. If you want to use NIO you should
+ * use {@link IMAPServer}
*/
-public class OioIMAPServer extends IMAPServer{
+public class OioIMAPServer extends IMAPServer {
@Override
protected ServerSocketChannelFactory createSocketChannelFactory() {
@@ -35,13 +34,10 @@ public class OioIMAPServer extends IMAPS
/**
* Return -1 as it is not known
- *
- *
*/
@Override
public int getIoWorkerCount() {
return -1;
}
-
}
Modified: james/server/trunk/jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java (original)
+++ james/server/trunk/jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java Mon Apr 4 14:59:11 2011
@@ -69,61 +69,58 @@ import org.slf4j.Logger;
*/
public class JCRMailRepository extends AbstractMailRepository implements MailRepository {
- private final static String MAIL_PATH = "mailrepository";
+ private final static String MAIL_PATH = "mailrepository";
+ private Repository repository;
+ private SimpleCredentials creds;
+ private String workspace;
- private Repository repository;
- private SimpleCredentials creds;
- private String workspace;
+ private Logger logger;
- private Logger logger;
-
- @Resource(name="jcrRepository")
+ @Resource(name = "jcrRepository")
public void setRepository(Repository repository) {
- this.repository = repository;
+ this.repository = repository;
}
-
+
@PostConstruct
public void init() throws Exception {
- // register the nodetype
- CndImporter.registerNodeTypes(new InputStreamReader(Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("org/apache/james/imap/jcr/james.cnd")), login());
+ // register the nodetype
+ CndImporter.registerNodeTypes(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/apache/james/imap/jcr/james.cnd")), login());
}
-
+
/*
* (non-Javadoc)
- * @see org.apache.james.mailrepository.AbstractMailRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
- */
- public void doConfigure(HierarchicalConfiguration config)
- throws ConfigurationException {
- this.workspace = config.getString("workspace",null);
- String username = config.getString("username", null);
- String password = config.getString("password",null);
-
- if (username != null && password != null) {
- this.creds = new SimpleCredentials(username, password.toCharArray());
- }
- }
+ *
+ * @see
+ * org.apache.james.mailrepository.AbstractMailRepository#doConfigure(org
+ * .apache.commons.configuration.HierarchicalConfiguration)
+ */
+ public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
+ this.workspace = config.getString("workspace", null);
+ String username = config.getString("username", null);
+ String password = config.getString("password", null);
+
+ if (username != null && password != null) {
+ this.creds = new SimpleCredentials(username, password.toCharArray());
+ }
+ }
-
protected String toSafeName(String key) {
String name = ISO9075.encode(Text.escapeIllegalJcrChars(key));
return name;
}
-
- private Session login() throws RepositoryException{
- return repository.login(creds, workspace);
+
+ private Session login() throws RepositoryException {
+ return repository.login(creds, workspace);
}
-
+
public Iterator<String> list() throws MessagingException {
try {
Session session = login();
try {
Collection<String> keys = new ArrayList<String>();
QueryManager manager = session.getWorkspace().getQueryManager();
- Query query = manager.createQuery(
- "/jcr:root/" + MAIL_PATH + "//element(*,james:mail)",
- Query.XPATH);
+ Query query = manager.createQuery("/jcr:root/" + MAIL_PATH + "//element(*,james:mail)", Query.XPATH);
NodeIterator iterator = query.execute().getNodes();
while (iterator.hasNext()) {
String name = iterator.nextNode().getName();
@@ -144,9 +141,7 @@ public class JCRMailRepository extends A
try {
String name = toSafeName(key);
QueryManager manager = session.getWorkspace().getQueryManager();
- Query query = manager.createQuery(
- "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)",
- Query.XPATH);
+ Query query = manager.createQuery("/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)", Query.XPATH);
NodeIterator iterator = query.execute().getNodes();
if (iterator.hasNext()) {
return getMail(iterator.nextNode());
@@ -157,32 +152,30 @@ public class JCRMailRepository extends A
session.logout();
}
} catch (IOException e) {
- throw new MessagingException(
- "Unable to retrieve message: " + key, e);
+ throw new MessagingException("Unable to retrieve message: " + key, e);
} catch (RepositoryException e) {
- throw new MessagingException(
- "Unable to retrieve message: " + key, e);
- }
+ throw new MessagingException("Unable to retrieve message: " + key, e);
+ }
}
-
- //-------------------------------------------------------------< private >
+ // -------------------------------------------------------------< private >
/**
* Reads a mail message from the given mail node.
- *
- * @param node mail node
+ *
+ * @param node
+ * mail node
* @return mail message
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private Mail getMail(Node node)
- throws MessagingException, RepositoryException, IOException {
+ private Mail getMail(Node node) throws MessagingException, RepositoryException, IOException {
String name = Text.unescapeIllegalJcrChars(node.getName());
- MailImpl mail = new MailImpl(
- name, getSender(node), getRecipients(node),
- getMessage(node));
+ MailImpl mail = new MailImpl(name, getSender(node), getRecipients(node), getMessage(node));
mail.setState(getState(node));
mail.setLastUpdated(getLastUpdated(node));
mail.setErrorMessage(getError(node));
@@ -194,15 +187,19 @@ public class JCRMailRepository extends A
/**
* Writes the mail message to the given mail node.
- *
- * @param node mail node
- * @param mail mail message
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ *
+ * @param node
+ * mail node
+ * @param mail
+ * mail message
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private void setMail(Node node, Mail mail)
- throws MessagingException, RepositoryException, IOException {
+ private void setMail(Node node, Mail mail) throws MessagingException, RepositoryException, IOException {
setState(node, mail.getState());
setLastUpdated(node, mail.getLastUpdated());
setError(node, mail.getErrorMessage());
@@ -215,11 +212,13 @@ public class JCRMailRepository extends A
}
/**
- * Reads the message state from the james:state property.
- *
- * @param node mail node
+ * Reads the message state from the <code>james:state</code> property.
+ *
+ * @param node
+ * mail node
* @return message state, or {@link Mail#DEFAULT} if not set
- * @throws RepositoryException if a repository error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private String getState(Node node) throws RepositoryException {
try {
@@ -230,22 +229,28 @@ public class JCRMailRepository extends A
}
/**
- * Writes the message state to the james:state property.
- *
- * @param node mail node
- * @param state message state
- * @throws RepositoryException if a repository error occurs
+ * Writes the message state to the <code>james:state</code> property.
+ *
+ * @param node
+ * mail node
+ * @param state
+ * message state
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private void setState(Node node, String state) throws RepositoryException {
node.setProperty("james:state", state);
}
/**
- * Reads the update timestamp from the jcr:content/jcr:lastModified property.
- *
- * @param node mail node
+ * Reads the update timestamp from the
+ * <code>jcr:content/jcr:lastModified</code> property.
+ *
+ * @param node
+ * mail node
* @return update timestamp
- * @throws RepositoryException if a repository error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private Date getLastUpdated(Node node) throws RepositoryException {
try {
@@ -257,14 +262,17 @@ public class JCRMailRepository extends A
}
/**
- * Writes the update timestamp to the jcr:content/jcr:lastModified property.
- *
- * @param node mail node
- * @param updated update timestamp, or <code>null</code> if not set
- * @throws RepositoryException if a repository error occurs
+ * Writes the update timestamp to the
+ * <code>jcr:content/jcr:lastModified</code> property.
+ *
+ * @param node
+ * mail node
+ * @param updated
+ * update timestamp, or <code>null</code> if not set
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private void setLastUpdated(Node node, Date updated)
- throws RepositoryException {
+ private void setLastUpdated(Node node, Date updated) throws RepositoryException {
try {
node = node.getNode("jcr:content");
} catch (PathNotFoundException e) {
@@ -278,11 +286,13 @@ public class JCRMailRepository extends A
}
/**
- * Reads the error message from the james:error property.
- *
- * @param node mail node
+ * Reads the error message from the <code>james:error</code> property.
+ *
+ * @param node
+ * mail node
* @return error message, or <code>null</code> if not set
- * @throws RepositoryException if a repository error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private String getError(Node node) throws RepositoryException {
try {
@@ -293,22 +303,28 @@ public class JCRMailRepository extends A
}
/**
- * Writes the error message to the james:error property.
- *
- * @param node mail node
- * @param error error message
- * @throws RepositoryException if a repository error occurs
+ * Writes the error message to the <code>james:error</code> property.
+ *
+ * @param node
+ * mail node
+ * @param error
+ * error message
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private void setError(Node node, String error) throws RepositoryException {
node.setProperty("james:error", error);
}
/**
- * Reads the remote host name from the james:remotehost property.
- *
- * @param node mail node
+ * Reads the remote host name from the <code>james:remotehost</code>
+ * property.
+ *
+ * @param node
+ * mail node
* @return remote host name, or <code>null</code> if not set
- * @throws RepositoryException if a repository error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private String getRemoteHost(Node node) throws RepositoryException {
try {
@@ -319,23 +335,28 @@ public class JCRMailRepository extends A
}
/**
- * Writes the remote host name to the james:remotehost property.
- *
- * @param node mail node
- * @param host remote host name
- * @throws RepositoryException if a repository error occurs
+ * Writes the remote host name to the <code>james:remotehost</code>
+ * property.
+ *
+ * @param node
+ * mail node
+ * @param host
+ * remote host name
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private void setRemoteHost(Node node, String host)
- throws RepositoryException {
+ private void setRemoteHost(Node node, String host) throws RepositoryException {
node.setProperty("james:remotehost", host);
}
/**
- * Reads the remote address from the james:remoteaddr property.
- *
- * @param node mail node
+ * Reads the remote address from the <code>james:remoteaddr</code> property.
+ *
+ * @param node
+ * mail node
* @return remote address, or <code>null</code> if not set
- * @throws RepositoryException if a repository error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
private String getRemoteAddr(Node node) throws RepositoryException {
try {
@@ -346,27 +367,31 @@ public class JCRMailRepository extends A
}
/**
- * Writes the remote address to the james:remoteaddr property.
- *
- * @param node mail node
- * @param addr remote address
- * @throws RepositoryException if a repository error occurs
+ * Writes the remote address to the <code>james:remoteaddr</code> property.
+ *
+ * @param node
+ * mail node
+ * @param addr
+ * remote address
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private void setRemoteAddr(Node node, String addr)
- throws RepositoryException {
+ private void setRemoteAddr(Node node, String addr) throws RepositoryException {
node.setProperty("james:remoteaddr", addr);
}
/**
- * Reads the envelope sender from the james:sender property.
- *
- * @param node mail node
+ * Reads the envelope sender from the <code>james:sender</code> property.
+ *
+ * @param node
+ * mail node
* @return envelope sender, or <code>null</code> if not set
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private MailAddress getSender(Node node)
- throws MessagingException, RepositoryException {
+ private MailAddress getSender(Node node) throws MessagingException, RepositoryException {
try {
String sender = node.getProperty("james:sender").getString();
return new MailAddress(sender);
@@ -376,29 +401,35 @@ public class JCRMailRepository extends A
}
/**
- * Writes the envelope sender to the james:sender property.
- *
- * @param node mail node
- * @param sender envelope sender
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
+ * Writes the envelope sender to the <code>james:sender</code> property.
+ *
+ * @param node
+ * mail node
+ * @param sender
+ * envelope sender
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private void setSender(Node node, MailAddress sender)
- throws MessagingException, RepositoryException {
+ private void setSender(Node node, MailAddress sender) throws MessagingException, RepositoryException {
node.setProperty("james:sender", sender.toString());
}
/**
- * Reads the list of recipients from the james:recipients property.
- *
- * @param node mail node
+ * Reads the list of recipients from the <code>james:recipients</code>
+ * property.
+ *
+ * @param node
+ * mail node
* @return list of recipient, or an empty list if not set
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
@SuppressWarnings("unchecked")
- private Collection<MailAddress> getRecipients(Node node)
- throws MessagingException, RepositoryException {
+ private Collection<MailAddress> getRecipients(Node node) throws MessagingException, RepositoryException {
try {
Value[] values = node.getProperty("james:recipients").getValues();
Collection<MailAddress> recipients = new ArrayList<MailAddress>(values.length);
@@ -412,15 +443,19 @@ public class JCRMailRepository extends A
}
/**
- * Writes the list of recipients to the james:recipients property.
- *
- * @param node mail node
- * @param recipients list of recipient
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
+ * Writes the list of recipients to the <code>james:recipients</code>
+ * property.
+ *
+ * @param node
+ * mail node
+ * @param recipients
+ * list of recipient
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
*/
- private void setRecipients(Node node, Collection<MailAddress> recipients)
- throws MessagingException, RepositoryException {
+ private void setRecipients(Node node, Collection<MailAddress> recipients) throws MessagingException, RepositoryException {
String[] values = new String[recipients.size()];
Iterator<MailAddress> iterator = recipients.iterator();
for (int i = 0; iterator.hasNext(); i++) {
@@ -430,16 +465,20 @@ public class JCRMailRepository extends A
}
/**
- * Reads the message content from the jcr:content/jcr:data binary property.
- *
- * @param node mail node
+ * Reads the message content from the <code>jcr:content/jcr:data</code>
+ * binary property.
+ *
+ * @param node
+ * mail node
* @return mail message
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private MimeMessage getMessage(Node node)
- throws MessagingException, RepositoryException, IOException {
+ private MimeMessage getMessage(Node node) throws MessagingException, RepositoryException, IOException {
try {
node = node.getNode("jcr:content");
} catch (PathNotFoundException e) {
@@ -449,25 +488,28 @@ public class JCRMailRepository extends A
InputStream stream = node.getProperty("jcr:data").getStream();
try {
Properties properties = System.getProperties();
- return new MimeMessage(
- javax.mail.Session.getDefaultInstance(properties),
- stream);
+ return new MimeMessage(javax.mail.Session.getDefaultInstance(properties), stream);
} finally {
stream.close();
}
}
/**
- * Writes the message content to the jcr:content/jcr:data binary property.
- *
- * @param node mail node
- * @param message mail message
- * @throws MessagingException if a messaging error occurs
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ * Writes the message content to the <code>jcr:content/jcr:data</code>
+ * binary property.
+ *
+ * @param node
+ * mail node
+ * @param message
+ * mail message
+ * @throws MessagingException
+ * if a messaging error occurs
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private void setMessage(Node node, final MimeMessage message)
- throws MessagingException, RepositoryException, IOException {
+ private void setMessage(Node node, final MimeMessage message) throws MessagingException, RepositoryException, IOException {
try {
node = node.getNode("jcr:content");
} catch (PathNotFoundException e) {
@@ -493,20 +535,22 @@ public class JCRMailRepository extends A
}
/**
- * Writes the mail attributes from the jamesattr:* property.
- *
- * @param node mail node
- * @param mail mail message
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ * Writes the mail attributes from the <code>jamesattr:*</code> property.
+ *
+ * @param node
+ * mail node
+ * @param mail
+ * mail message
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private void getAttributes(Node node, Mail mail)
- throws RepositoryException, IOException {
+ private void getAttributes(Node node, Mail mail) throws RepositoryException, IOException {
PropertyIterator iterator = node.getProperties("jamesattr:*");
while (iterator.hasNext()) {
Property property = iterator.nextProperty();
- String name = Text.unescapeIllegalJcrChars(
- property.getName().substring("jamesattr:".length()));
+ String name = Text.unescapeIllegalJcrChars(property.getName().substring("jamesattr:".length()));
if (property.getType() == PropertyType.BINARY) {
InputStream input = property.getStream();
try {
@@ -522,17 +566,20 @@ public class JCRMailRepository extends A
}
}
}
-
+
/**
- * Writes the mail attributes to the jamesattr:* property.
- *
- * @param node mail node
- * @param mail mail message
- * @throws RepositoryException if a repository error occurs
- * @throws IOException if an IO error occurs
+ * Writes the mail attributes to the <code>jamesattr:*</code> property.
+ *
+ * @param node
+ * mail node
+ * @param mail
+ * mail message
+ * @throws RepositoryException
+ * if a repository error occurs
+ * @throws IOException
+ * if an IO error occurs
*/
- private void setAttributes(Node node, Mail mail)
- throws RepositoryException, IOException {
+ private void setAttributes(Node node, Mail mail) throws RepositoryException, IOException {
Iterator<String> iterator = mail.getAttributeNames();
while (iterator.hasNext()) {
String name = (String) iterator.next();
@@ -545,23 +592,19 @@ public class JCRMailRepository extends A
ObjectOutputStream output = new ObjectOutputStream(buffer);
output.writeObject(value);
output.close();
- node.setProperty(
- name,
- new ByteArrayInputStream(buffer.toByteArray()));
+ node.setProperty(name, new ByteArrayInputStream(buffer.toByteArray()));
}
}
}
- @Override
- protected void internalRemove(String key) throws MessagingException {
- try {
+ @Override
+ protected void internalRemove(String key) throws MessagingException {
+ try {
Session session = login();
try {
String name = ISO9075.encode(Text.escapeIllegalJcrChars(key));
QueryManager manager = session.getWorkspace().getQueryManager();
- Query query = manager.createQuery(
- "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)",
- Query.XPATH);
+ Query query = manager.createQuery("/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)", Query.XPATH);
NodeIterator nodes = query.execute().getNodes();
if (nodes.hasNext()) {
while (nodes.hasNext()) {
@@ -577,22 +620,21 @@ public class JCRMailRepository extends A
}
} catch (RepositoryException e) {
throw new MessagingException("Unable to remove message: " + key, e);
- }
- }
+ }
+ }
- @Override
- protected void internalStore(Mail mail) throws MessagingException,
- IOException {
- try {
+ @Override
+ protected void internalStore(Mail mail) throws MessagingException, IOException {
+ try {
Session session = login();
try {
String name = Text.escapeIllegalJcrChars(mail.getName());
final String xpath = "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)";
-
+
QueryManager manager = session.getWorkspace().getQueryManager();
Query query = manager.createQuery(xpath, Query.XPATH);
NodeIterator iterator = query.execute().getNodes();
-
+
if (iterator.hasNext()) {
while (iterator.hasNext()) {
setMail(iterator.nextNode(), mail);
@@ -610,12 +652,10 @@ public class JCRMailRepository extends A
session.logout();
}
} catch (IOException e) {
- throw new MessagingException(
- "Unable to store message: " + mail.getName(), e);
+ throw new MessagingException("Unable to store message: " + mail.getName(), e);
} catch (RepositoryException e) {
- throw new MessagingException(
- "Unable to store message: " + mail.getName(), e);
- }
- }
+ throw new MessagingException("Unable to store message: " + mail.getName(), e);
+ }
+ }
}
Modified: james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java (original)
+++ james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java Mon Apr 4 14:59:11 2011
@@ -43,12 +43,12 @@ import org.apache.james.user.jcr.model.J
import org.apache.james.user.lib.AbstractUsersRepository;
/**
- * {@link UsersRepository} implementation which stores users to a JCR {@link Repository}
- *
+ * {@link UsersRepository} implementation which stores users to a JCR
+ * {@link Repository}
*/
public class JCRUsersRepository extends AbstractUsersRepository {
-
- //TODO: Add namespacing
+
+ // TODO: Add namespacing
private static final String PASSWD_PROPERTY = "passwd";
private static final String USERNAME_PROPERTY = "username";
@@ -58,9 +58,9 @@ public class JCRUsersRepository extends
private SimpleCredentials creds;
private String workspace;
- @Resource(name="jcrRepository")
+ @Resource(name = "jcrRepository")
public void setRepository(Repository repository) {
- this.repository = repository;
+ this.repository = repository;
}
public void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
@@ -77,18 +77,19 @@ public class JCRUsersRepository extends
String name = ISO9075.encode(Text.escapeIllegalJcrChars(key));
return name;
}
-
- private Session login() throws RepositoryException{
- return repository.login(creds, workspace);
+
+ private Session login() throws RepositoryException {
+ return repository.login(creds, workspace);
}
-
+
/**
- * Get the user object with the specified user name. Return null if no
- * such user.
- *
- * @param name the name of the user to retrieve
+ * Get the user object with the specified user name. Return null if no such
+ * user.
+ *
+ * @param name
+ * the name of the user to retrieve
* @return the user being retrieved, null if the user doesn't exist
- *
+ *
*/
public User getUserByName(String username) {
User user;
@@ -98,11 +99,10 @@ public class JCRUsersRepository extends
final String name = toSafeName(username);
final String path = USERS_PATH + "/" + name;
final Node rootNode = session.getRootNode();
-
+
try {
final Node node = rootNode.getNode(path);
- user = new JCRUser(node.getProperty(USERNAME_PROPERTY).getString(),
- node.getProperty(PASSWD_PROPERTY).getString());
+ user = new JCRUser(node.getProperty(USERNAME_PROPERTY).getString(), node.getProperty(PASSWD_PROPERTY).getString());
} catch (PathNotFoundException e) {
// user not found
user = null;
@@ -110,7 +110,7 @@ public class JCRUsersRepository extends
} finally {
session.logout();
}
-
+
} catch (RepositoryException e) {
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to add user: " + username, e);
@@ -120,12 +120,12 @@ public class JCRUsersRepository extends
return user;
}
-
/**
* Returns the user name of the user matching name on an equalsIgnoreCase
* basis. Returns null if no match.
- *
- * @param name the name to case-correct
+ *
+ * @param name
+ * the name to case-correct
* @return the case-correct name of the user, null if the user doesn't exist
*/
public String getRealName(String name) {
@@ -133,14 +133,13 @@ public class JCRUsersRepository extends
}
/**
- * Update the repository with the specified user object. A user object
- * with this username must already exist.
- *
+ * Update the repository with the specified user object. A user object with
+ * this username must already exist.
+ *
* @return true if successful.
*/
- public void updateUser(final User user) throws UsersRepositoryException{
- if (user != null && user instanceof JCRUser)
- {
+ public void updateUser(final User user) throws UsersRepositoryException {
+ if (user != null && user instanceof JCRUser) {
final JCRUser jcrUser = (JCRUser) user;
final String userName = jcrUser.getUserName();
try {
@@ -149,7 +148,7 @@ public class JCRUsersRepository extends
final String name = toSafeName(userName);
final String path = USERS_PATH + "/" + name;
final Node rootNode = session.getRootNode();
-
+
try {
final String hashedSaltedPassword = jcrUser.getHashedSaltedPassword();
rootNode.getNode(path).setProperty(PASSWD_PROPERTY, hashedSaltedPassword);
@@ -163,7 +162,7 @@ public class JCRUsersRepository extends
} finally {
session.logout();
}
-
+
} catch (RepositoryException e) {
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to add user: " + userName, e);
@@ -176,9 +175,10 @@ public class JCRUsersRepository extends
/**
* Removes a user from the repository
- *
- * @param name the user to remove from the repository
- * @throws UsersRepositoryException
+ *
+ * @param name
+ * the user to remove from the repository
+ * @throws UsersRepositoryException
*/
public void removeUser(String username) throws UsersRepositoryException {
try {
@@ -196,7 +196,7 @@ public class JCRUsersRepository extends
} finally {
session.logout();
}
-
+
} catch (RepositoryException e) {
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to remove user: " + username, e);
@@ -208,17 +208,18 @@ public class JCRUsersRepository extends
/**
* Returns whether or not this user is in the repository
- *
- * @param name the name to check in the repository
+ *
+ * @param name
+ * the name to check in the repository
* @return whether the user is in the repository
- * @throws UsersRepositoryException
+ * @throws UsersRepositoryException
*/
public boolean contains(String name) throws UsersRepositoryException {
try {
final Session session = login();
try {
final Node rootNode = session.getRootNode();
- final String path = USERS_PATH + "/" + toSafeName(name);
+ final String path = USERS_PATH + "/" + toSafeName(name);
rootNode.getNode(path);
return true;
} finally {
@@ -236,17 +237,18 @@ public class JCRUsersRepository extends
return false;
}
-
/**
* Test if user with name 'name' has password 'password'.
- *
- * @param name the name of the user to be tested
- * @param password the password to be tested
- *
- * @return true if the test is successful, false if the user
- * doesn't exist or if the password is incorrect
- * @throws UsersRepositoryException
- *
+ *
+ * @param name
+ * the name of the user to be tested
+ * @param password
+ * the password to be tested
+ *
+ * @return true if the test is successful, false if the user doesn't exist
+ * or if the password is incorrect
+ * @throws UsersRepositoryException
+ *
* @since James 1.2.2
*/
public boolean test(String username, String password) throws UsersRepositoryException {
@@ -256,12 +258,11 @@ public class JCRUsersRepository extends
final String name = toSafeName(username);
final String path = USERS_PATH + "/" + name;
final Node rootNode = session.getRootNode();
-
+
try {
final Node node = rootNode.getNode(path);
final String current = node.getProperty(PASSWD_PROPERTY).getString();
- if (current == null || current == "")
- {
+ if (current == null || current == "") {
return password == null || password == "";
}
final String hashPassword = JCRUser.hashPassword(username, password);
@@ -274,7 +275,7 @@ public class JCRUsersRepository extends
} finally {
session.logout();
}
-
+
} catch (RepositoryException e) {
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to search user: " + username, e);
@@ -287,9 +288,9 @@ public class JCRUsersRepository extends
/**
* Returns a count of the users in the repository.
- *
+ *
* @return the number of users in the repository
- * @throws UsersRepositoryException
+ * @throws UsersRepositoryException
*/
public int countUsers() throws UsersRepositoryException {
try {
@@ -298,8 +299,8 @@ public class JCRUsersRepository extends
final Node rootNode = session.getRootNode();
try {
final Node node = rootNode.getNode(USERS_PATH);
- //TODO: Use query
- //TODO: Use namespacing to avoid unwanted nodes
+ // TODO: Use query
+ // TODO: Use namespacing to avoid unwanted nodes
NodeIterator it = node.getNodes();
return (int) it.getSize();
} catch (PathNotFoundException e) {
@@ -319,9 +320,10 @@ public class JCRUsersRepository extends
/**
* List users in repository.
- *
- * @return Iterator over a collection of Strings, each being one user in the repository.
- * @throws UsersRepositoryException
+ *
+ * @return Iterator over a collection of Strings, each being one user in the
+ * repository.
+ * @throws UsersRepositoryException
*/
public Iterator<String> list() throws UsersRepositoryException {
final Collection<String> userNames = new ArrayList<String>();
@@ -331,9 +333,9 @@ public class JCRUsersRepository extends
final Node rootNode = session.getRootNode();
try {
final Node baseNode = rootNode.getNode(USERS_PATH);
- //TODO: Use query
+ // TODO: Use query
final NodeIterator it = baseNode.getNodes();
- while(it.hasNext()) {
+ while (it.hasNext()) {
final Node node = it.nextNode();
try {
final String userName = node.getProperty(USERNAME_PROPERTY).getString();
@@ -352,12 +354,11 @@ public class JCRUsersRepository extends
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to list users", e);
}
- throw new UsersRepositoryException("Failed to list users",e );
+ throw new UsersRepositoryException("Failed to list users", e);
}
return userNames.iterator();
}
-
@Override
protected void doAddUser(String username, String password) throws UsersRepositoryException {
try {
@@ -381,17 +382,14 @@ public class JCRUsersRepository extends
// TODO: path exists.
parent = rootNode.addNode(USERS_PATH);
}
-
+
Node node = parent.addNode(name);
node.setProperty(USERNAME_PROPERTY, username);
final String hashedPassword;
- if (password == null)
- {
+ if (password == null) {
// Support easy password reset
hashedPassword = "";
- }
- else
- {
+ } else {
hashedPassword = JCRUser.hashPassword(username, password);
}
node.setProperty(PASSWD_PROPERTY, hashedPassword);
@@ -399,7 +397,7 @@ public class JCRUsersRepository extends
} finally {
session.logout();
}
-
+
} catch (RepositoryException e) {
if (getLogger().isInfoEnabled()) {
getLogger().info("Failed to add user: " + username, e);
Modified: james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/model/JCRUser.java
URL: http://svn.apache.org/viewvc/james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/model/JCRUser.java?rev=1088657&r1=1088656&r2=1088657&view=diff
==============================================================================
--- james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/model/JCRUser.java (original)
+++ james/server/trunk/jcr/src/main/java/org/apache/james/user/jcr/model/JCRUser.java Mon Apr 4 14:59:11 2011
@@ -23,22 +23,24 @@ import org.apache.jackrabbit.util.Text;
import org.apache.james.user.api.model.User;
/**
- * User backed by JCR data.
- * Differs from standard James by improved hash.
- * TODO: think about improving DefaultUser.
+ * User backed by JCR data. Differs from standard James by improved hash. TODO:
+ * think about improving DefaultUser.
*/
public class JCRUser implements User {
- /**
- * Static salt for hashing password.
- * Modifying this value will render all passwords unrecognizable.
+ /**
+ * Static salt for hashing password. Modifying this value will render all
+ * passwords unrecognizable.
*/
public static final String SALT = "JCRUsersRepository";
-
+
/**
* Hashes salted password.
- * @param username not null
- * @param password not null
+ *
+ * @param username
+ * not null
+ * @param password
+ * not null
* @return not null
*/
public static String hashPassword(String username, String password) {
@@ -46,10 +48,10 @@ public class JCRUser implements User {
final String hashedSaltedPassword = Text.md5(Text.md5(username + password) + SALT);
return hashedSaltedPassword;
}
-
+
private final String userName;
private String hashedSaltedPassword;
-
+
public JCRUser(final String userName, String hashedSaltedPassword) {
super();
this.userName = userName;
@@ -59,9 +61,10 @@ public class JCRUser implements User {
public String getUserName() {
return userName;
}
-
+
/**
* Gets salted, hashed password.
+ *
* @return the hashedSaltedPassword
*/
public final String getHashedSaltedPassword() {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org