From a034ddbdff1194a88d74c0439cbac872baaab3a2 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 21 Jan 2016 17:06:24 -0800 Subject: [PATCH] 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 --- .../appidentity/IdentityServlet.java | 3 +- .../appengine/appidentity/UrlShortener.java | 9 ++--- .../appidentity/UrlShortenerServlet.java | 34 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java index 3464ed47e17..d10cf3efed5 100644 --- a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java +++ b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.example.appengine.appidentity; import com.google.apphosting.api.ApiProxy; diff --git a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortener.java b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortener.java index cecebe82d6a..94f08768948 100644 --- a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortener.java +++ b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortener.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.example.appengine.appidentity; import com.google.appengine.api.appidentity.AppIdentityService; @@ -41,8 +42,8 @@ class UrlShortener { public String createShortUrl(String longUrl) throws Exception { ArrayList scopes = new ArrayList(); scopes.add("https://www.googleapis.com/auth/urlshortener"); - AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); - AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes); + final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); + final AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes); // The token asserts the identity reported by appIdentity.getServiceAccountName() JSONObject request = new JSONObject(); request.put("longUrl", longUrl); @@ -61,7 +62,7 @@ public String createShortUrl(String longUrl) throws Exception { if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { // Note: Should check the content-encoding. // Any JSON parser can be used; this one is used for illustrative purposes. - JSONTokener response_tokens = new JSONTokener(connection.getInputStream()); + JSONTokener responseTokens = new JSONTokener(connection.getInputStream()); JSONObject response = new JSONObject(response_tokens); return (String) response.get("id"); } else { diff --git a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java index 8bab40e8115..2778ed2f325 100644 --- a/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java +++ b/appengine/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.example.appengine.appidentity; import com.google.appengine.api.users.UserService; @@ -36,15 +37,16 @@ public UrlShortenerServlet() { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - PrintWriter w = resp.getWriter(); - w.println(""); - w.println(""); - w.println("Asserting Identity to Google APIs - App Engine App Identity Example"); - w.println("
"); - w.println(""); - w.println(""); - w.println(""); - w.println("
"); + PrintWriter writer = resp.getWriter(); + writer.println(""); + writer.println(""); + writer.println( + "Asserting Identity to Google APIs - App Engine App Identity Example"); + writer.println("
"); + writer.println(""); + writer.println(""); + writer.println(""); + writer.println("
"); } @Override @@ -57,19 +59,19 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx } String shortUrl; - PrintWriter w = resp.getWriter(); + PrintWriter writer = resp.getWriter(); try { shortUrl = shortener.createShortUrl(longUrl); } catch (Exception e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - w.println("error shortening URL: " + longUrl); + writer.println("error shortening URL: " + longUrl); e.printStackTrace(w); return; } - w.print("long URL: "); - w.println(longUrl); - w.print("short URL: "); - w.println(shortUrl); + writer.print("long URL: "); + writer.println(longUrl); + writer.print("short URL: "); + writer.println(shortUrl); } }