Skip to content

Commit

Permalink
Merge pull request #59 from GoogleCloudPlatform/checkstyle
Browse files Browse the repository at this point in the history
Fix style errors in the App Identity samples.
  • Loading branch information
tswast committed Jan 22, 2016
2 parents 6c41c88 + 4f6fc48 commit 6acd3af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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;
Expand Down Expand Up @@ -41,8 +42,8 @@ class UrlShortener {
public String createShortUrl(String longUrl) throws Exception {
ArrayList<String> scopes = new ArrayList<String>();
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);
Expand All @@ -61,8 +62,8 @@ 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());
JSONObject response = new JSONObject(response_tokens);
JSONTokener responseTokens = new JSONTokener(connection.getInputStream());
JSONObject response = new JSONObject(responseTokens);
return (String) response.get("id");
} else {
try (InputStream s = connection.getErrorStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,14 +13,11 @@
* 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;
import com.google.appengine.api.users.UserServiceFactory;
package com.example.appengine.appidentity;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

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

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter w = resp.getWriter();
w.println("<!DOCTYPE html>");
w.println("<meta charset=\"utf-8\">");
w.println("<title>Asserting Identity to Google APIs - App Engine App Identity Example</title>");
w.println("<form method=\"post\">");
w.println("<label for=\"longUrl\">URL:</label>");
w.println("<input id=\"longUrl\" name=\"longUrl\" type=\"text\">");
w.println("<input type=\"submit\" value=\"Shorten\">");
w.println("</form>");
PrintWriter writer = resp.getWriter();
writer.println("<!DOCTYPE html>");
writer.println("<meta charset=\"utf-8\">");
writer.println(
"<title>Asserting Identity to Google APIs - App Engine App Identity Example</title>");
writer.println("<form method=\"post\">");
writer.println("<label for=\"longUrl\">URL:</label>");
writer.println("<input id=\"longUrl\" name=\"longUrl\" type=\"text\">");
writer.println("<input type=\"submit\" value=\"Shorten\">");
writer.println("</form>");
}

@Override
Expand All @@ -57,19 +55,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);
e.printStackTrace(w);
writer.println("error shortening URL: " + longUrl);
e.printStackTrace(writer);
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);
}
}

0 comments on commit 6acd3af

Please sign in to comment.