Skip to content

Commit a034ddb

Browse files
committed
Fix style errors in the App Identity samples.
I checked for style errors using the following command: mvn checkstyle:checkstyle \ -Dcheckstyle.config.location=google_checks.xml \ -Dcheckstyle.consoleOutput=true
1 parent 6c41c88 commit a034ddb

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

appengine/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package com.example.appengine.appidentity;
1718

1819
import com.google.apphosting.api.ApiProxy;

appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortener.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package com.example.appengine.appidentity;
1718

1819
import com.google.appengine.api.appidentity.AppIdentityService;
@@ -41,8 +42,8 @@ class UrlShortener {
4142
public String createShortUrl(String longUrl) throws Exception {
4243
ArrayList<String> scopes = new ArrayList<String>();
4344
scopes.add("https://www.googleapis.com/auth/urlshortener");
44-
AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
45-
AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes);
45+
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
46+
final AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes);
4647
// The token asserts the identity reported by appIdentity.getServiceAccountName()
4748
JSONObject request = new JSONObject();
4849
request.put("longUrl", longUrl);
@@ -61,7 +62,7 @@ public String createShortUrl(String longUrl) throws Exception {
6162
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
6263
// Note: Should check the content-encoding.
6364
// Any JSON parser can be used; this one is used for illustrative purposes.
64-
JSONTokener response_tokens = new JSONTokener(connection.getInputStream());
65+
JSONTokener responseTokens = new JSONTokener(connection.getInputStream());
6566
JSONObject response = new JSONObject(response_tokens);
6667
return (String) response.get("id");
6768
} else {

appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package com.example.appengine.appidentity;
1718

1819
import com.google.appengine.api.users.UserService;
@@ -36,15 +37,16 @@ public UrlShortenerServlet() {
3637

3738
@Override
3839
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
39-
PrintWriter w = resp.getWriter();
40-
w.println("<!DOCTYPE html>");
41-
w.println("<meta charset=\"utf-8\">");
42-
w.println("<title>Asserting Identity to Google APIs - App Engine App Identity Example</title>");
43-
w.println("<form method=\"post\">");
44-
w.println("<label for=\"longUrl\">URL:</label>");
45-
w.println("<input id=\"longUrl\" name=\"longUrl\" type=\"text\">");
46-
w.println("<input type=\"submit\" value=\"Shorten\">");
47-
w.println("</form>");
40+
PrintWriter writer = resp.getWriter();
41+
writer.println("<!DOCTYPE html>");
42+
writer.println("<meta charset=\"utf-8\">");
43+
writer.println(
44+
"<title>Asserting Identity to Google APIs - App Engine App Identity Example</title>");
45+
writer.println("<form method=\"post\">");
46+
writer.println("<label for=\"longUrl\">URL:</label>");
47+
writer.println("<input id=\"longUrl\" name=\"longUrl\" type=\"text\">");
48+
writer.println("<input type=\"submit\" value=\"Shorten\">");
49+
writer.println("</form>");
4850
}
4951

5052
@Override
@@ -57,19 +59,19 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx
5759
}
5860

5961
String shortUrl;
60-
PrintWriter w = resp.getWriter();
62+
PrintWriter writer = resp.getWriter();
6163
try {
6264
shortUrl = shortener.createShortUrl(longUrl);
6365
} catch (Exception e) {
6466
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
65-
w.println("error shortening URL: " + longUrl);
67+
writer.println("error shortening URL: " + longUrl);
6668
e.printStackTrace(w);
6769
return;
6870
}
6971

70-
w.print("long URL: ");
71-
w.println(longUrl);
72-
w.print("short URL: ");
73-
w.println(shortUrl);
72+
writer.print("long URL: ");
73+
writer.println(longUrl);
74+
writer.print("short URL: ");
75+
writer.println(shortUrl);
7476
}
7577
}

0 commit comments

Comments
 (0)