Skip to content

Commit 6acd3af

Browse files
committed
Merge pull request #59 from GoogleCloudPlatform/checkstyle
Fix style errors in the App Identity samples.
2 parents 6c41c88 + 4f6fc48 commit 6acd3af

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

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

+2-1
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

+6-5
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,8 +62,8 @@ 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-
JSONObject response = new JSONObject(response_tokens);
65+
JSONTokener responseTokens = new JSONTokener(connection.getInputStream());
66+
JSONObject response = new JSONObject(responseTokens);
6667
return (String) response.get("id");
6768
} else {
6869
try (InputStream s = connection.getErrorStream();
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,14 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.example.appengine.appidentity;
1716

18-
import com.google.appengine.api.users.UserService;
19-
import com.google.appengine.api.users.UserServiceFactory;
17+
package com.example.appengine.appidentity;
2018

2119
import java.io.IOException;
2220
import java.io.PrintWriter;
23-
import java.net.URLDecoder;
2421

2522
import javax.servlet.http.HttpServlet;
2623
import javax.servlet.http.HttpServletRequest;
@@ -36,15 +33,16 @@ public UrlShortenerServlet() {
3633

3734
@Override
3835
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>");
36+
PrintWriter writer = resp.getWriter();
37+
writer.println("<!DOCTYPE html>");
38+
writer.println("<meta charset=\"utf-8\">");
39+
writer.println(
40+
"<title>Asserting Identity to Google APIs - App Engine App Identity Example</title>");
41+
writer.println("<form method=\"post\">");
42+
writer.println("<label for=\"longUrl\">URL:</label>");
43+
writer.println("<input id=\"longUrl\" name=\"longUrl\" type=\"text\">");
44+
writer.println("<input type=\"submit\" value=\"Shorten\">");
45+
writer.println("</form>");
4846
}
4947

5048
@Override
@@ -57,19 +55,19 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx
5755
}
5856

5957
String shortUrl;
60-
PrintWriter w = resp.getWriter();
58+
PrintWriter writer = resp.getWriter();
6159
try {
6260
shortUrl = shortener.createShortUrl(longUrl);
6361
} catch (Exception e) {
6462
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
65-
w.println("error shortening URL: " + longUrl);
66-
e.printStackTrace(w);
63+
writer.println("error shortening URL: " + longUrl);
64+
e.printStackTrace(writer);
6765
return;
6866
}
6967

70-
w.print("long URL: ");
71-
w.println(longUrl);
72-
w.print("short URL: ");
73-
w.println(shortUrl);
68+
writer.print("long URL: ");
69+
writer.println(longUrl);
70+
writer.print("short URL: ");
71+
writer.println(shortUrl);
7472
}
7573
}

0 commit comments

Comments
 (0)