9_3_HW8_webapp_attach · JavaWebinar/masterjava@0f0ca9a · GitHub
Skip to content

Commit 0f0ca9a

Browse files
committed
9_3_HW8_webapp_attach
1 parent 855d7b3 commit 0f0ca9a

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

Lines changed: 47 additions & 0 deletions

web/webapp/src/main/java/ru/javaops/masterjava/webapp/SendServlet.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package ru.javaops.masterjava.webapp;
22

3+
import com.google.common.collect.ImmutableList;
34
import lombok.extern.slf4j.Slf4j;
45
import ru.javaops.masterjava.service.mail.GroupResult;
56
import ru.javaops.masterjava.service.mail.MailWSClient;
7+
import ru.javaops.masterjava.service.mail.util.Attachments;
68

79
import javax.servlet.ServletException;
10+
import javax.servlet.annotation.MultipartConfig;
811
import javax.servlet.annotation.WebServlet;
912
import javax.servlet.http.HttpServlet;
1013
import javax.servlet.http.HttpServletRequest;
1114
import javax.servlet.http.HttpServletResponse;
15+
import javax.servlet.http.Part;
1216
import java.io.IOException;
1317

1418
@WebServlet("/send")
1519
@Slf4j
20+
@MultipartConfig
1621
public class SendServlet extends HttpServlet {
1722
@Override
1823
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@@ -24,7 +29,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
2429
String users = req.getParameter("users");
2530
String subject = req.getParameter("subject");
2631
String body = req.getParameter("body");
27-
GroupResult groupResult = MailWSClient.sendBulk(MailWSClient.split(users), subject, body, null);
32+
Part filePart = req.getPart("attach");
33+
GroupResult groupResult = MailWSClient.sendBulk(MailWSClient.split(users), subject, body,
34+
filePart == null ? null :
35+
ImmutableList.of(Attachments.getAttachment(filePart.getSubmittedFileName(), filePart.getInputStream())));
2836
result = groupResult.toString();
2937
log.info("Processing finished with result: {}", result);
3038
} catch (Exception e) {

web/webapp/src/main/webapp/WEB-INF/templates/users.html

Lines changed: 22 additions & 7 deletions

0 commit comments

Comments
 (0)