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 ro...@apache.org on 2016/08/29 13:27:59 UTC
[02/17] james-project git commit: JAMES-1818 Use AttachmentManager in
download servlet
JAMES-1818 Use AttachmentManager in download servlet
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6e81f25a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6e81f25a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6e81f25a
Branch: refs/heads/master
Commit: 6e81f25ac2da71f9b218c71e00df362a18fe1da0
Parents: f2d46ab
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 15:44:39 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/james/jmap/JMAPCommonModule.java | 4 ++++
.../java/org/apache/james/jmap/DownloadServlet.java | 15 ++++++---------
.../org/apache/james/jmap/DownloadServletTest.java | 12 +++++++-----
3 files changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index 5a9b6a4..77cfe0f 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -35,6 +35,8 @@ import org.apache.james.jmap.model.MessagePreviewGenerator;
import org.apache.james.jmap.send.MailFactory;
import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
+import org.apache.james.mailbox.AttachmentManager;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
import org.apache.james.util.date.DefaultZonedDateTimeProvider;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.apache.mailet.base.AutomaticallySentMailDetector;
@@ -62,6 +64,7 @@ public class JMAPCommonModule extends AbstractModule {
bind(MessageFactory.class).in(Scopes.SINGLETON);
bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
+ bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
bind(SignatureHandler.class).to(JamesSignatureHandler.class);
bind(ZonedDateTimeProvider.class).to(DefaultZonedDateTimeProvider.class);
@@ -71,6 +74,7 @@ public class JMAPCommonModule extends AbstractModule {
bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
bind(AccessTokenManager.class).to(AccessTokenManagerImpl.class);
+ bind(AttachmentManager.class).to(StoreAttachmentManager.class);
}
@Provides
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
index 35f283a..0d140e6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -35,13 +35,12 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.james.jmap.api.SimpleTokenFactory;
import org.apache.james.jmap.utils.DownloadPath;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,12 +51,12 @@ public class DownloadServlet extends HttpServlet {
private static final Logger LOGGER = LoggerFactory.getLogger(DownloadServlet.class);
private static final String TEXT_PLAIN_CONTENT_TYPE = "text/plain";
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private final AttachmentManager attachmentManager;
private final SimpleTokenFactory simpleTokenFactory;
@Inject
- @VisibleForTesting DownloadServlet(MailboxSessionMapperFactory mailboxSessionMapperFactory, SimpleTokenFactory simpleTokenFactory) {
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+ @VisibleForTesting DownloadServlet(AttachmentManager attachmentManager, SimpleTokenFactory simpleTokenFactory) {
+ this.attachmentManager = attachmentManager;
this.simpleTokenFactory = simpleTokenFactory;
}
@@ -89,9 +88,8 @@ public class DownloadServlet extends HttpServlet {
}
private boolean attachmentExists(MailboxSession mailboxSession, String blobId) throws MailboxException {
- AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession);
try {
- attachmentMapper.getAttachment(AttachmentId.from(blobId));
+ attachmentManager.getAttachment(AttachmentId.from(blobId), mailboxSession);
return true;
} catch (AttachmentNotFoundException e) {
return false;
@@ -114,8 +112,7 @@ public class DownloadServlet extends HttpServlet {
try {
addContentDispositionHeader(downloadPath.getName(), resp);
- AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession);
- Attachment attachment = attachmentMapper.getAttachment(AttachmentId.from(blobId));
+ Attachment attachment = attachmentManager.getAttachment(AttachmentId.from(blobId), mailboxSession);
IOUtils.copy(attachment.getStream(), resp.getOutputStream());
resp.setStatus(SC_OK);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
index 79302b7..eea5090 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
@@ -19,6 +19,8 @@
package org.apache.james.jmap;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,22 +29,22 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.james.jmap.api.SimpleTokenFactory;
import org.apache.james.jmap.utils.DownloadPath;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.junit.Test;
public class DownloadServletTest {
@Test
- public void downloadMayFailWhenUnableToCreateAttachmentMapper() throws Exception {
+ public void downloadMayFailWhenUnknownErrorOnAttachmentManager() throws Exception {
MailboxSession mailboxSession = mock(MailboxSession.class);
- MailboxSessionMapperFactory mailboxSessionMapperFactory = mock(MailboxSessionMapperFactory.class);
- when(mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession))
+ AttachmentManager mockedAttachmentManager = mock(AttachmentManager.class);
+ when(mockedAttachmentManager.getAttachment(any(), eq(mailboxSession)))
.thenThrow(new MailboxException());
SimpleTokenFactory nullSimpleTokenFactory = null;
- DownloadServlet testee = new DownloadServlet(mailboxSessionMapperFactory, nullSimpleTokenFactory);
+ DownloadServlet testee = new DownloadServlet(mockedAttachmentManager, nullSimpleTokenFactory);
HttpServletResponse resp = mock(HttpServletResponse.class);
testee.download(mailboxSession, DownloadPath.from("/blobId"), resp);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org