Skip to content

Commit 7ce1a32

Browse files
committed
Merge pull request #91 from GoogleCloudPlatform/checkstyle
Fix checkstyle in twilio and sendgrid samples.
2 parents 97968e6 + d4a8de9 commit 7ce1a32

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

managed_vms/sendgrid/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
<target>1.8</target>
4949
</configuration>
5050
</plugin>
51-
<!--
52-
The sendgrid sample currently (2016-01-22) fails the Google Style
53-
checks. We can uncomment this block when it is fixed.
5451
<plugin>
5552
<groupId>org.apache.maven.plugins</groupId>
5653
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -65,7 +62,6 @@
6562
<execution><goals><goal>check</goal></goals></execution>
6663
</executions>
6764
</plugin>
68-
-->
6965
<plugin>
7066
<groupId>org.eclipse.jetty</groupId>
7167
<artifactId>jetty-maven-plugin</artifactId>

managed_vms/sendgrid/src/main/java/com/example/managedvms/sendgrid/SendEmailServlet.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public class SendEmailServlet extends HttpServlet {
3535
@Override
3636
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
3737
ServletException {
38-
final String SENDGRID_API_KEY = System.getenv("SENDGRID_API_KEY");
39-
final String SENDGRID_SENDER = System.getenv("SENDGRID_SENDER");
40-
final String TO_EMAIL = req.getParameter("to");
41-
if (TO_EMAIL == null) {
42-
resp.getWriter().print("Please provide an email address in the \"to\" query string"
43-
+ " parameter.");
38+
final String sendgridApiKey = System.getenv("SENDGRID_API_KEY");
39+
final String sendgridSender = System.getenv("SENDGRID_SENDER");
40+
final String toEmail = req.getParameter("to");
41+
if (toEmail == null) {
42+
resp.getWriter()
43+
.print("Please provide an email address in the \"to\" query string parameter.");
4444
return;
4545
}
4646

47-
SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY);
47+
SendGrid sendgrid = new SendGrid(sendgridApiKey);
4848
SendGrid.Email email = new SendGrid.Email();
49-
email.addTo(TO_EMAIL);
50-
email.setFrom(SENDGRID_SENDER);
49+
email.addTo(toEmail);
50+
email.setFrom(sendgridSender);
5151
email.setSubject("This is a test email");
5252
email.setText("Example text body.");
5353

@@ -58,8 +58,7 @@ public void service(HttpServletRequest req, HttpServletResponse resp) throws IOE
5858
return;
5959
}
6060
resp.getWriter().print("Email sent.");
61-
}
62-
catch (SendGridException e) {
61+
} catch (SendGridException e) {
6362
throw new ServletException("SendGrid error", e);
6463
}
6564
}

managed_vms/twilio/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
<target>1.8</target>
4949
</configuration>
5050
</plugin>
51-
<!--
52-
The twilio sample currently (2016-01-22) fails the Google Style
53-
checks. We can uncomment this block when it is fixed.
5451
<plugin>
5552
<groupId>org.apache.maven.plugins</groupId>
5653
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -65,7 +62,6 @@
6562
<execution><goals><goal>check</goal></goals></execution>
6663
</executions>
6764
</plugin>
68-
-->
6965
<plugin>
7066
<groupId>org.eclipse.jetty</groupId>
7167
<artifactId>jetty-maven-plugin</artifactId>

managed_vms/twilio/src/main/java/com/example/managedvms/twilio/SendSmsServlet.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,21 @@ public class SendSmsServlet extends HttpServlet {
4242
@Override
4343
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
4444
ServletException {
45-
final String TWILIO_ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
46-
final String TWILIO_AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
47-
final String TWILIO_NUMBER = System.getenv("TWILIO_NUMBER");
48-
final String TO_NUMBER = (String) req.getParameter("to");
49-
if (TO_NUMBER == null) {
50-
resp.getWriter().print("Please provide the number to message in the \"to\" query string"
51-
+ " parameter.");
45+
final String twilioAccountSid = System.getenv("TWILIO_ACCOUNT_SID");
46+
final String twilioAuthToken = System.getenv("TWILIO_AUTH_TOKEN");
47+
final String twilioNumber = System.getenv("TWILIO_NUMBER");
48+
final String toNumber = (String) req.getParameter("to");
49+
if (toNumber == null) {
50+
resp.getWriter()
51+
.print("Please provide the number to message in the \"to\" query string parameter.");
5252
return;
5353
}
54-
TwilioRestClient client = new TwilioRestClient(TWILIO_ACCOUNT_SID,
55-
TWILIO_AUTH_TOKEN);
54+
TwilioRestClient client = new TwilioRestClient(twilioAccountSid, twilioAuthToken);
5655
Account account = client.getAccount();
5756
MessageFactory messageFactory = account.getMessageFactory();
5857
List<NameValuePair> params = new ArrayList<NameValuePair>();
59-
params.add(new BasicNameValuePair("To", TO_NUMBER));
60-
params.add(new BasicNameValuePair("From", TWILIO_NUMBER));
58+
params.add(new BasicNameValuePair("To", toNumber));
59+
params.add(new BasicNameValuePair("From", twilioNumber));
6160
params.add(new BasicNameValuePair("Body", "Hello from Twilio!"));
6261
try {
6362
Message sms = messageFactory.create(params);

0 commit comments

Comments
 (0)