@@ -0,0 +1,3411 @@
+/*%0A * Copyright (c) 2012 Google Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License. You may obtain a copy of the License at%0A * http://www.apache.org/licenses/LICENSE-2.0.%0A *%0A * Unless required by applicable law or agreed to in writing, software distributed under the License%0A * is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express%0A * or implied. See the License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Apackage com.google.api.client.sample.storage.appengine.serviceaccount;%0A%0Aimport com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;%0Aimport com.google.api.client.http.GenericUrl;%0Aimport com.google.api.client.http.HttpRequest;%0Aimport com.google.api.client.http.HttpRequestFactory;%0Aimport com.google.api.client.http.HttpResponse;%0Aimport com.google.api.client.http.HttpTransport;%0Aimport com.google.api.client.http.javanet.NetHttpTransport;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.IOException;%0Aimport java.io.OutputStreamWriter;%0Aimport java.util.Arrays;%0A%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/**%0A * Google Cloud Storage Service Account App Engine sample.%0A *%0A * @author Marc Cohen%0A */%0Apublic class StorageSample extends HttpServlet %7B%0A%0A  private static final long serialVersionUID = 1L;%0A%0A  private static final String GCS_URI = %22http://commondatastorage.googleapis.com%22;%0A%0A  /** Global configuration of Google Cloud Storage OAuth 2.0 scope. */%0A  private static final String STORAGE_SCOPE =%0A      %22https://www.googleapis.com/auth/devstorage.read_write%22;%0A%0A  /** Global instance of the HTTP transport. */%0A  private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();%0A%0A  /** Global instance of HTML reference to XSL style sheet. */%0A  String XSL = %22%5Cn%3C?xml-stylesheet href=%5C%22/xsl/listing.xsl%5C%22 type=%5C%22text/xsl%5C%22?%3E%5Cn%22;%0A%0A  @Override%0A  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException %7B%0A%0A    try %7B%0A      AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(STORAGE_SCOPE));%0A%0A      // Set up and execute Google Cloud Storage request.%0A      String bucketName = req.getRequestURI();%0A      if (bucketName.equals(%22/%22)) %7B%0A        resp.sendError(404, %22No bucket specified - append /bucket-name to the URL and retry.%22);%0A        return;%0A      %7D%0A      // Remove any trailing slashes, if found.%0A      String cleanBucketName = bucketName.replaceAll(%22/$%22, %22%22);%0A      String URI = GCS_URI + cleanBucketName;%0A      HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential);%0A      GenericUrl url = new GenericUrl(URI);%0A      HttpRequest request = requestFactory.buildGetRequest(url);%0A      HttpResponse response = request.execute();%0A      String content = response.parseAsString();%0A%0A      // Display the output XML.%0A      resp.setContentType(%22text/xml%22);%0A      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));%0A      String formattedContent = content.replaceAll(%22(%3CListBucketResult)%22, XSL + %22$1%22);%0A      writer.append(formattedContent);%0A      writer.flush();%0A      resp.setStatus(200);%0A    %7D catch (Throwable e) %7B%0A      resp.sendError(404, e.getMessage());%0A    %7D%0A  %7D%0A%7D%0A

Create StorageSample.java