com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential Java Examples
The following examples show how to use
com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StorageSample.java From java-docs-samples with Apache License 2.0 | 5 votes |
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { try { AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(STORAGE_SCOPE)); // Set up and execute Google Cloud Storage request. String bucketName = req.getRequestURI(); if (bucketName.equals("/")) { resp.sendError( HTTP_NOT_FOUND, "No bucket specified - append /bucket-name to the URL and retry."); return; } // Remove any trailing slashes, if found. // [START snippet] String cleanBucketName = bucketName.replaceAll("/$", ""); String uri = GCS_URI + cleanBucketName; HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential); GenericUrl url = new GenericUrl(uri); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); // [END snippet] // Display the output XML. resp.setContentType("text/xml"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream())); String formattedContent = content.replaceAll("(<ListBucketResult)", XSL + "$1"); writer.append(formattedContent); writer.flush(); resp.setStatus(HTTP_OK); } catch (Throwable e) { resp.sendError(HTTP_NOT_FOUND, e.getMessage()); } }
Example #2
Source File: StorageSample.java From cloud-storage-docs-xml-api-examples with Apache License 2.0 | 5 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(STORAGE_SCOPE)); // Set up and execute Google Cloud Storage request. String bucketName = req.getRequestURI(); if (bucketName.equals("/")) { resp.sendError(404, "No bucket specified - append /bucket-name to the URL and retry."); return; } // Remove any trailing slashes, if found. //[START snippet] String cleanBucketName = bucketName.replaceAll("/$", ""); String URI = GCS_URI + cleanBucketName; HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential); GenericUrl url = new GenericUrl(URI); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); //[END snippet] // Display the output XML. resp.setContentType("text/xml"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream())); String formattedContent = content.replaceAll("(<ListBucketResult)", XSL + "$1"); writer.append(formattedContent); writer.flush(); resp.setStatus(200); } catch (Throwable e) { resp.sendError(404, e.getMessage()); } }
Example #3
Source File: OauthRawGcsService.java From appengine-gcs-client with Apache License 2.0 | 5 votes |
OauthRawGcsService(OAuthURLFetchService urlfetch, ImmutableSet<HTTPHeader> headers) { this.urlfetch = checkNotNull(urlfetch, "Null urlfetch"); this.headers = checkNotNull(headers, "Null headers"); AppIdentityCredential cred = new AppIdentityCredential(OAUTH_SCOPES); storage = new Storage.Builder(new UrlFetchTransport(), new JacksonFactory(), cred) .setApplicationName(SystemProperty.applicationId.get()).build(); }