Repository: james-project Updated Branches: refs/heads/master 088870ebb -> f9bcbf907
JAMES-2409 JMAP download should position Content-Length header before download starts Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/52413375 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/52413375 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/52413375 Branch: refs/heads/master Commit: 52413375164589fa02276762fa3835d42d82157c Parents: 8b422da Author: benwa <[email protected]> Authored: Tue Jun 5 11:47:46 2018 +0700 Committer: benwa <[email protected]> Committed: Tue Jun 5 11:48:55 2018 +0700 ---------------------------------------------------------------------- .../integration/cucumber/DownloadStepdefs.java | 14 ++++++++++++++ .../src/test/resources/cucumber/DownloadGet.feature | 5 +++++ .../java/org/apache/james/jmap/DownloadServlet.java | 5 ++--- 3 files changed, 21 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/52413375/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java index 2abf00b..a2aedfc 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java @@ -22,6 +22,7 @@ package org.apache.james.jmap.methods.integration.cucumber; import static org.apache.james.jmap.JmapURIBuilder.baseUri; import static org.assertj.core.api.Assertions.assertThat; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -52,6 +53,7 @@ import org.apache.james.mime4j.codec.DecoderUtil; import com.google.common.base.CharMatcher; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import com.google.common.base.Strings; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; @@ -102,6 +104,18 @@ public class DownloadStepdefs { inputToMessageId.put(messageId, composedMessageId.getMessageId()); } + @Given("^\"([^\"]*)\" mailbox \"([^\"]*)\" contains a big message \"([^\"]*)\"$") + public void appendBigMessageToMailbox(String user, String mailbox, String messageId) throws Throwable { + MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox); + + ComposedMessageId composedMessageId = mainStepdefs.mailboxProbe.appendMessage(user, mailboxPath, + AppendCommand.from(new ByteArrayInputStream( + Strings.repeat("header: 0123456789\r\n", 1024 * 1024) + .getBytes(StandardCharsets.UTF_8)))); + + inputToMessageId.put(messageId, composedMessageId.getMessageId()); + } + @Given("^\"([^\"]*)\" mailbox \"([^\"]*)\" contains a message \"([^\"]*)\" with an attachment \"([^\"]*)\"$") public void appendMessageWithAttachmentToMailbox(String user, String mailbox, String messageId, String attachmentId) throws Throwable { MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox); http://git-wip-us.apache.org/repos/asf/james-project/blob/52413375/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature index 6b8155f..6a11038 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature @@ -55,6 +55,11 @@ Feature: Download GET Then she can read that blob And the blob size is 4963 + Scenario: Getting a message blob previously stored + Given "[email protected]" mailbox "INBOX" contains a big message "1" + When "[email protected]" downloads "1" + Then the blob size is 20971520 + Scenario: Getting a message then getting its blob Given "[email protected]" has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail" And "[email protected]" ask for messages "m1" http://git-wip-us.apache.org/repos/asf/james-project/blob/52413375/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 d9a6296..0c7f085 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 @@ -123,13 +123,12 @@ public class DownloadServlet extends HttpServlet { @VisibleForTesting void download(MailboxSession mailboxSession, DownloadPath downloadPath, HttpServletResponse resp) { String blobId = downloadPath.getBlobId(); try { - addContentDispositionHeader(downloadPath.getName(), resp); - Blob blob = blobManager.retrieve(BlobId.fromString(blobId), mailboxSession); - IOUtils.copy(blob.getStream(), resp.getOutputStream()); + addContentDispositionHeader(downloadPath.getName(), resp); resp.setHeader("Content-Length", String.valueOf(blob.getSize())); resp.setStatus(SC_OK); + IOUtils.copy(blob.getStream(), resp.getOutputStream()); } catch (BlobNotFoundException e) { LOGGER.info("Attachment '{}' not found", blobId, e); resp.setStatus(SC_NOT_FOUND); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
