Skip to content

Commit 890af88

Browse files
authored
Fix pom structure for appengine-java8/mail. (GoogleCloudPlatform#1333)
* Correct parent in appengine-java8/mail. * Run google-java-format and update license format.
1 parent 7bfc2ff commit 890af88

File tree

8 files changed

+83
-75
lines changed

8 files changed

+83
-75
lines changed

appengine-java8/mail/pom.xml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ Copyright 2016 Google Inc.
2020
<groupId>com.example.appengine</groupId>
2121
<artifactId>appengine-mail</artifactId>
2222

23-
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
23+
<!--
24+
The parent pom defines common style checks and testing strategies for our samples.
25+
Removing or replacing it should not affect the execution of the samples in anyway.
26+
-->
2427
<parent>
25-
<groupId>com.google.cloud</groupId>
26-
<artifactId>appengine-doc-samples</artifactId>
27-
<version>1.0.0</version>
28-
<relativePath>..</relativePath>
28+
<groupId>com.google.cloud.samples</groupId>
29+
<artifactId>shared-configuration</artifactId>
30+
<version>1.0.10</version>
2931
</parent>
3032

33+
<properties>
34+
<maven.compiler.target>1.8</maven.compiler.target>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
</properties>
37+
3138
<dependencies>
3239
<dependency>
3340
<groupId>javax.servlet</groupId>
@@ -40,6 +47,7 @@ Copyright 2016 Google Inc.
4047
<dependency>
4148
<groupId>com.google.appengine</groupId>
4249
<artifactId>appengine-api-1.0-sdk</artifactId>
50+
<version>1.9.63</version>
4351
</dependency>
4452
<dependency>
4553
<groupId>javax.mail</groupId>

appengine-java8/mail/src/main/java/com/example/appengine/mail/BounceHandlerServlet.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,9 +17,9 @@
1717
package com.example.appengine.mail;
1818

1919
// [START bounce_handler_servlet]
20+
2021
import com.google.appengine.api.mail.BounceNotification;
2122
import com.google.appengine.api.mail.BounceNotificationParser;
22-
2323
import java.io.IOException;
2424
import java.util.logging.Logger;
2525
import javax.mail.MessagingException;
@@ -37,17 +37,17 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx
3737
BounceNotification bounce = BounceNotificationParser.parse(req);
3838
log.warning("Bounced email notification.");
3939
// The following data is available in a BounceNotification object
40-
// bounce.getOriginal().getFrom()
41-
// bounce.getOriginal().getTo()
42-
// bounce.getOriginal().getSubject()
43-
// bounce.getOriginal().getText()
44-
// bounce.getNotification().getFrom()
45-
// bounce.getNotification().getTo()
46-
// bounce.getNotification().getSubject()
47-
// bounce.getNotification().getText()
40+
// bounce.getOriginal().getFrom()
41+
// bounce.getOriginal().getTo()
42+
// bounce.getOriginal().getSubject()
43+
// bounce.getOriginal().getText()
44+
// bounce.getNotification().getFrom()
45+
// bounce.getNotification().getTo()
46+
// bounce.getNotification().getSubject()
47+
// bounce.getNotification().getText()
4848
// ...
4949
} catch (MessagingException e) {
50-
// ...
50+
// ...
5151
}
5252
}
5353
}

appengine-java8/mail/src/main/java/com/example/appengine/mail/HandleDiscussionEmail.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,23 +16,25 @@
1616

1717
package com.example.appengine.mail;
1818

19+
import java.util.logging.Logger;
20+
import java.util.regex.Matcher;
1921
import javax.mail.internet.MimeMessage;
22+
import javax.servlet.ServletException;
2023
import javax.servlet.http.HttpServletRequest;
2124
import javax.servlet.http.HttpServletResponse;
22-
import javax.servlet.ServletException;
23-
import java.util.logging.Logger;
24-
import java.util.regex.Matcher;
2525

2626
// [START example]
2727
public class HandleDiscussionEmail extends MailHandlerBase {
2828

2929
private static final Logger log = Logger.getLogger(HandleDiscussionEmail.class.getName());
30-
public HandleDiscussionEmail() { super("discuss-(.*)@(.*)"); }
30+
31+
public HandleDiscussionEmail() {
32+
super("discuss-(.*)@(.*)");
33+
}
3134

3235
@Override
3336
protected boolean processMessage(HttpServletRequest req, HttpServletResponse res)
34-
throws ServletException
35-
{
37+
throws ServletException {
3638
log.info("Received e-mail sent to discuss list.");
3739
MimeMessage msg = getMessageFromRequest(req);
3840
Matcher match = getMatcherFromRequest(req);

appengine-java8/mail/src/main/java/com/example/appengine/mail/MailHandlerBase.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,54 +16,52 @@
1616

1717
package com.example.appengine.mail;
1818

19-
import javax.mail.internet.MimeMessage;
19+
import java.io.IOException;
20+
import java.util.Properties;
21+
import java.util.regex.Matcher;
22+
import java.util.regex.Pattern;
2023
import javax.mail.MessagingException;
2124
import javax.mail.Session;
25+
import javax.mail.internet.MimeMessage;
2226
import javax.servlet.Filter;
2327
import javax.servlet.FilterChain;
2428
import javax.servlet.FilterConfig;
25-
import javax.servlet.http.HttpServletRequest;
26-
import javax.servlet.http.HttpServletResponse;
2729
import javax.servlet.ServletException;
2830
import javax.servlet.ServletRequest;
2931
import javax.servlet.ServletResponse;
30-
import java.io.IOException;
31-
import java.util.Properties;
32-
import java.util.regex.Matcher;
33-
import java.util.regex.Pattern;
32+
import javax.servlet.http.HttpServletRequest;
33+
import javax.servlet.http.HttpServletResponse;
3434

35-
/**
36-
* Base class for handling the filtering of incoming emails in App Engine.
37-
*/
35+
/** Base class for handling the filtering of incoming emails in App Engine. */
3836
// [START example]
3937
public abstract class MailHandlerBase implements Filter {
4038

4139
private Pattern pattern = null;
4240

4341
protected MailHandlerBase(String pattern) {
44-
if (pattern == null || pattern.trim().length() == 0)
45-
{
42+
if (pattern == null || pattern.trim().length() == 0) {
4643
throw new IllegalArgumentException("Expected non-empty regular expression");
4744
}
48-
this.pattern = Pattern.compile("/_ah/mail/"+pattern);
45+
this.pattern = Pattern.compile("/_ah/mail/" + pattern);
4946
}
5047

51-
@Override public void init(FilterConfig config) throws ServletException { }
48+
@Override
49+
public void init(FilterConfig config) throws ServletException {}
5250

53-
@Override public void destroy() { }
51+
@Override
52+
public void destroy() {}
5453

5554
/**
56-
* Process the message. A message will only be passed to this method
57-
* if the servletPath of the message (typically the recipient for
58-
* appengine) satisfies the pattern passed to the constructor. If
59-
* the implementation returns false, control is passed
60-
* to the next filter in the chain. If the implementation returns
61-
* true, the filter chain is terminated.
55+
* Process the message. A message will only be passed to this method if the servletPath of the
56+
* message (typically the recipient for appengine) satisfies the pattern passed to the
57+
* constructor. If the implementation returns false, control is passed to the next filter in the
58+
* chain. If the implementation returns true, the filter chain is terminated.
6259
*
63-
* The Matcher for the pattern can be retrieved via
64-
* getMatcherFromRequest (e.g. if groups are used in the pattern).
60+
* <p>The Matcher for the pattern can be retrieved via getMatcherFromRequest (e.g. if groups are
61+
* used in the pattern).
6562
*/
66-
protected abstract boolean processMessage(HttpServletRequest req, HttpServletResponse res) throws ServletException;
63+
protected abstract boolean processMessage(HttpServletRequest req, HttpServletResponse res)
64+
throws ServletException;
6765

6866
@Override
6967
public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain chain)
@@ -80,12 +78,13 @@ public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain chai
8078
}
8179

8280
chain.doFilter(req, res); // Try the next one
83-
8481
}
8582

8683
private Matcher applyPattern(HttpServletRequest req) {
8784
Matcher m = pattern.matcher(req.getServletPath());
88-
if (!m.matches()) m = null;
85+
if (!m.matches()) {
86+
m = null;
87+
}
8988

9089
req.setAttribute("matcher", m);
9190
return m;

appengine-java8/mail/src/main/java/com/example/appengine/mail/MailHandlerServlet.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,14 +17,13 @@
1717
package com.example.appengine.mail;
1818

1919
// [START mail_handler_servlet]
20+
2021
import java.io.IOException;
21-
import java.util.logging.Logger;
2222
import java.util.Properties;
23-
23+
import java.util.logging.Logger;
2424
import javax.mail.MessagingException;
2525
import javax.mail.Session;
2626
import javax.mail.internet.MimeMessage;
27-
2827
import javax.servlet.http.HttpServlet;
2928
import javax.servlet.http.HttpServletRequest;
3029
import javax.servlet.http.HttpServletResponse;

appengine-java8/mail/src/main/java/com/example/appengine/mail/MailServlet.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,31 +17,30 @@
1717
package com.example.appengine.mail;
1818

1919
// [START simple_includes]
20+
21+
import java.io.ByteArrayInputStream;
2022
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.UnsupportedEncodingException;
2125
import java.util.Properties;
2226
import javax.mail.Message;
2327
import javax.mail.MessagingException;
28+
import javax.mail.Multipart;
2429
import javax.mail.Session;
2530
import javax.mail.Transport;
2631
import javax.mail.internet.AddressException;
2732
import javax.mail.internet.InternetAddress;
28-
import javax.mail.internet.MimeMessage;
29-
// [END simple_includes]
30-
31-
// [START multipart_includes]
32-
import java.io.InputStream;
33-
import java.io.ByteArrayInputStream;
34-
import java.io.UnsupportedEncodingException;
35-
import javax.activation.DataHandler;
36-
import javax.mail.Multipart;
3733
import javax.mail.internet.MimeBodyPart;
34+
import javax.mail.internet.MimeMessage;
3835
import javax.mail.internet.MimeMultipart;
39-
// [END multipart_includes]
40-
4136
import javax.servlet.http.HttpServlet;
4237
import javax.servlet.http.HttpServletRequest;
4338
import javax.servlet.http.HttpServletResponse;
4439

40+
// [END simple_includes]
41+
// [START multipart_includes]
42+
// [END multipart_includes]
43+
4544
@SuppressWarnings("serial")
4645
public class MailServlet extends HttpServlet {
4746

@@ -65,8 +64,8 @@ private void sendSimpleMail() {
6564
try {
6665
Message msg = new MimeMessage(session);
6766
msg.setFrom(new InternetAddress("admin@example.com", "Example.com Admin"));
68-
msg.addRecipient(Message.RecipientType.TO,
69-
new InternetAddress("user@example.com", "Mr. User"));
67+
msg.addRecipient(
68+
Message.RecipientType.TO, new InternetAddress("user@example.com", "Mr. User"));
7069
msg.setSubject("Your Example.com account has been activated");
7170
msg.setText("This is a test");
7271
Transport.send(msg);
@@ -89,14 +88,14 @@ private void sendMultipartMail() {
8988
try {
9089
Message msg = new MimeMessage(session);
9190
msg.setFrom(new InternetAddress("admin@example.com", "Example.com Admin"));
92-
msg.addRecipient(Message.RecipientType.TO,
93-
new InternetAddress("user@example.com", "Mr. User"));
91+
msg.addRecipient(
92+
Message.RecipientType.TO, new InternetAddress("user@example.com", "Mr. User"));
9493
msg.setSubject("Your Example.com account has been activated");
9594
msg.setText(msgBody);
9695

9796
// [START multipart_example]
98-
String htmlBody = ""; // ...
99-
byte[] attachmentData = null; // ...
97+
String htmlBody = ""; // ...
98+
byte[] attachmentData = null; // ...
10099
Multipart mp = new MimeMultipart();
101100

102101
MimeBodyPart htmlPart = new MimeBodyPart();

appengine-java8/mail/src/main/webapp/WEB-INF/web.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
limitations under the License.
1616
-->
1717
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
18-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19-
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
2020
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
21-
version="3.1">
21+
version="3.1">
2222
<servlet>
2323
<servlet-name>mail</servlet-name>
2424
<servlet-class>com.example.appengine.mail.MailServlet</servlet-class>

appengine-java8/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<module>guestbook-cloud-datastore</module>
5858
<module>guestbook-objectify</module>
5959
<module>images</module>
60+
<module>mail</module>
6061
<module>mailgun</module>
6162
<module>mailjet</module>
6263
<module>memcache</module>

0 commit comments

Comments
 (0)