diff --git a/storage/xml-api/README.md b/storage/xml-api/README.md deleted file mode 100644 index 356910c7a78..00000000000 --- a/storage/xml-api/README.md +++ /dev/null @@ -1,11 +0,0 @@ -java-docs-samples/storage XML API Examples -=================================== - -Samples used in Google Cloud Storage documentation: - -- [XML API Overview](https://cloud.google.com/storage/docs/xml-api/overview) -- [Java samples](https://cloud.google.com/storage/docs/xml-api/java-samples) - -- **cmdline-sample** - Uses a [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials) to access a specified bucket. - -- **serviceaccount-appengine-sample** - Uses Google App Engine credentials to access a specified bucket. You must add the App Engine Service Account Name to the Permissions of the project that contains the bucket. diff --git a/storage/xml-api/cmdline-sample/README.md b/storage/xml-api/cmdline-sample/README.md deleted file mode 100644 index 091452cbfb3..00000000000 --- a/storage/xml-api/cmdline-sample/README.md +++ /dev/null @@ -1,93 +0,0 @@ -This is the sample used in the [Cloud Storage Java -documentation](https://cloud.google.com/storage/docs/xml-api-java-samples). - - -Open in Cloud Shell - -Using the Command Line Sample -============================================================== - -Browse Online --------------- - -The main file is -[StorageSample.java](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java). - -Setup ------ - -* [Create](https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets) - a Google Cloud Storage bucket -* This module uses [Application Default - Credentials](https://developers.google.com/accounts/docs/application-default-credentials). - If you are running it outside of [Google Compute - Engine](https://cloud.google.com/compute/), you'll need to - * Download the json private key for a [Service - Account](https://cloud.google.com/storage/docs/authentication#service_accounts) - and have it available. - * Set an environment variable: `export - GOOGLE_APPLICATION_CREDENTIALS=path/to/your-key.json` -* You must also be able to work with - [GitHub](https://help.github.com/articles/set-up-git) repositories. -* Clone repository. - - git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git - -Command-line Instructions -------------------------- - -* **Prerequisites:** - * Install the latest version of [Java](https://java.com) and - [Maven](https://maven.apache.org/download.html). - * Set the environment variable: `export - GOOGLE_APPLICATION_CREDENTIALS=your-key-filename.json` - * You may need to set your `JAVA_HOME`. - -```bash -cd java-docs-samples/storage/xml-api/cmdline-sample -# Compile and run -mvn compile install -mvn -q exec:java -Dexec.args="your-bucket-name" -``` - -To enable logging of HTTP requests and responses (highly recommended when -developing), please take a look at logging.properties. - -Eclipse Instructions --------------------- - -* **Prerequisites:** - * Install [Eclipse](http://www.eclipse.org/downloads/), the [Maven - plugin](http://eclipse.org/m2e/), and optionally the [GitHub - plugin](http://eclipse.github.com/). - -* Set up Eclipse Preferences - - * Window > Preferences... (or on Mac, Eclipse > Preferences...) - * Select Maven - - * check on "Download Artifact Sources" - * check on "Download Artifact JavaDoc" - -* Create a new project using `storage/xml-api/cmdline-sample` - - * Create a new Java Project. - * Choose the **Location** of the project to be the location of - `cmdline-sample` - * Select the project and **Convert to Maven Project** to add Maven - Dependencies. - * Click on Run > Run configurations - * Navigate to your **Java Application**'s configuration section - * In the **Arguments** tab, add the name of the bucket you created above as - a **Program argument** - * In the **Environment** tab, create a variable - `GOOGLE_APPLICATION_CREDENTIALS` and set it to the path to your json - private key file. - -* Run - - * Right-click on project - * Run As > Java Application - * If asked, type "StorageSample" and click OK diff --git a/storage/xml-api/cmdline-sample/logging.properties b/storage/xml-api/cmdline-sample/logging.properties deleted file mode 100644 index faec34876e0..00000000000 --- a/storage/xml-api/cmdline-sample/logging.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Properties file which configures the operation of the JDK logging facility. -# The system will look for this config file to be specified as a system property: -# -Djava.util.logging.config.file=${project_loc:cmdline-sample}/logging.properties - -# Set up the console handler (uncomment "level" to show more fine-grained messages) -handlers = java.util.logging.ConsoleHandler -#java.util.logging.ConsoleHandler.level = CONFIG - -# Set up logging of HTTP requests and responses (uncomment "level" to show) -#com.google.api.client.http.level = CONFIG diff --git a/storage/xml-api/cmdline-sample/pom.xml b/storage/xml-api/cmdline-sample/pom.xml deleted file mode 100644 index e5b672e448e..00000000000 --- a/storage/xml-api/cmdline-sample/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - com.example.storage - storage-xml-cmdline-sample - 1 - - - - com.google.cloud.samples - shared-configuration - 1.2.0 - - - - 1.43.1 - UTF-8 - 1.6.0 - 1.8 - 1.8 - - - - - - com.google.cloud - libraries-bom - 26.32.0 - pom - import - - - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.1 - - - - java - - - - - StorageSample - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - 7 - 7 - - - - ${project.artifactId}-${project.version} - - - - com.google.auth - google-auth-library-oauth2-http - - - com.google.api-client - google-api-client - - - - com.google.truth - truth - 1.4.0 - test - - - diff --git a/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java b/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java deleted file mode 100644 index 593656f3c4d..00000000000 --- a/storage/xml-api/cmdline-sample/src/main/java/StorageSample.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; -import com.google.api.client.http.GenericUrl; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestFactory; -import com.google.api.client.http.HttpResponse; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.util.Preconditions; -import com.google.auth.http.HttpCredentialsAdapter; -import com.google.auth.oauth2.GoogleCredentials; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URLEncoder; -import java.security.GeneralSecurityException; -import java.util.Collections; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -/** - * Sample code used in the Cloud Storage Java documentation. - * https://cloud.google.com/storage/docs/xml-api-java-samples - */ -public final class StorageSample { - - /** This class is never instantiated. */ - private StorageSample() {} - - /** Global configuration of Google Cloud Storage OAuth 2.0 scope. */ - private static final String STORAGE_SCOPE = - "https://www.googleapis.com/auth/devstorage.read_write"; - - /** - * Fetches the listing of the given bucket. - * - * @param bucketName the name of the bucket to list. - * @return the raw XML containing the listing of the bucket. - * @throws IOException if there's an error communicating with Cloud Storage. - * @throws GeneralSecurityException for errors creating https connection. - */ - public static String listBucket(final String bucketName) - throws IOException, GeneralSecurityException { - // [START snippet] - // Build an account credential. - GoogleCredentials credential = - GoogleCredentials.getApplicationDefault() - .createScoped(Collections.singleton(STORAGE_SCOPE)); - - // Set up and execute a Google Cloud Storage request. - String uri = "https://storage.googleapis.com/" + URLEncoder.encode(bucketName, "UTF-8"); - - HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); - HttpRequestFactory requestFactory = - httpTransport.createRequestFactory(new HttpCredentialsAdapter(credential)); - GenericUrl url = new GenericUrl(uri); - - HttpRequest request = requestFactory.buildGetRequest(url); - HttpResponse response = request.execute(); - String content = response.parseAsString(); - // [END snippet] - - return content; - } - - /** - * Prints out the contents of the given xml, in a more readable form. - * - * @param bucketName the name of the bucket you're listing. - * @param content the raw XML string. - */ - private static void prettyPrintXml(final String bucketName, final String content) { - // Instantiate transformer input. - Source xmlInput = new StreamSource(new StringReader(content)); - StreamResult xmlOutput = new StreamResult(new StringWriter()); - - // Configure transformer. - try { - Transformer transformer = - TransformerFactory.newInstance().newTransformer(); // An identity transformer - transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd"); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - transformer.transform(xmlInput, xmlOutput); - - // Pretty print the output XML. - System.out.println("\nBucket listing for " + bucketName + ":\n"); - System.out.println(xmlOutput.getWriter().toString()); - } catch (TransformerException e) { - e.printStackTrace(); - } - } - - /** - * A command-line handler to display the bucket passed in as an argument. - * - * @param args the array of command-line arguments. - */ - public static void main(final String[] args) { - try { - // Check for valid setup. - Preconditions.checkArgument( - args.length == 1, "Please pass in the Google Cloud Storage bucket name to display"); - String bucketName = args[0]; - - String content = listBucket(bucketName); - - prettyPrintXml(bucketName, content); - System.exit(0); - - } catch (IOException e) { - System.err.println(e.getMessage()); - } catch (Throwable t) { - t.printStackTrace(); - } - System.exit(1); - } -} diff --git a/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java b/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java deleted file mode 100644 index 0537f8bd08a..00000000000 --- a/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [START StorageSampleTest] -import static com.google.common.truth.Truth.assertThat; - -import org.junit.Test; - -public class StorageSampleTest { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - - @Test - public void testListBucket() throws Exception { - String listing = StorageSample.listBucket(PROJECT_ID); - assertThat(listing) - .containsMatch( - ".*" + PROJECT_ID + ".*" - + ".*"); - } -} - -// [END StorageSampleTest] diff --git a/storage/xml-api/serviceaccount-appengine-sample/README.md b/storage/xml-api/serviceaccount-appengine-sample/README.md deleted file mode 100644 index cf2750463b3..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/README.md +++ /dev/null @@ -1,63 +0,0 @@ -Using the Service Account App Engine Sample -============================================== - -Browse Online -------------- - -The main code file is -[StorageSample.java](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/storage/xml-api/serviceaccount-appengine-sample/src/main/java/StorageServiceAccountSample.java). - -Add Your App Engine Service Account Name to the Project Team ------------------------------------------------------------- - -See the instructions at - for getting -your App Engine Service Account Name and adding it to your project team. - -Checkout Instructions ---------------------- - -**Prerequisites:** install the latest version of [Java](https://java.com) and -[Maven](https://maven.apache.org/download.html). You may need to set your -`JAVA_HOME`. - -You must also be able to work with a GitHub repository (see e.g., -). - - cd [someDirectory] - git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git - cd java-docs-samples/storage/xml-api/serviceaccount-appengine-sample - mvn clean package - -To enable logging of HTTP requests and responses (highly recommended when -developing), please take a look at logging.properties. - -Running and Deploying Your Application from the Command Line ------------------------------------------------------------- - -To run your application locally on a development server: - - mvn appengine:run - -To deploy your application to appspot.com: - -If this is the first time you are deploying your application to appspot.com, you -will to perform the following steps first. - -- Go to and create an application. -- Edit src/main/webapp/WEB-INF/appengine-web.xml, and enter the unique - application identifier (you chose it in the prior step) between the - tags. - -If you've done the above, you can deploy at any time: - - mvn appengine:update - -If this is the first time you have run "update" on the project, a browser window -will open prompting you to log in. Log in with the same Google account the app -is registered with. - -Set Up a Project in Eclipse ---------------------------- - -...coming soon... diff --git a/storage/xml-api/serviceaccount-appengine-sample/pom.xml b/storage/xml-api/serviceaccount-appengine-sample/pom.xml deleted file mode 100644 index 7a6df602fbc..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/pom.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - 4.0.0 - - - - com.google.cloud.samples - shared-configuration - 1.2.0 - - - com.example.storage - storage-xml-serviceaccounts-appengine-sample - 1.0.0 - Example for Google Cloud Storage using OAuth 2.0 Service Accounts on Google App Engine - war - - - 1.8 - 1.8 - ${project.build.directory}/${project.build.finalName} - - UTF-8 - 3.4.0 - - - - war - ${webappDirectory}/WEB-INF/classes - - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin-version} - - - compile - - exploded - - - - - ${webappDirectory} - - - - - - com.google.cloud.tools - appengine-maven-plugin - 2.8.0 - - GCLOUD_CONFIG - gaeinfo - 8888 - - - - - - maven-release-plugin - - gae:deploy - - - - - - - - - - libraries-bom - com.google.cloud - import - pom - 26.32.0 - - - - - - - - - com.google.api-client - google-api-client-appengine - - - - diff --git a/storage/xml-api/serviceaccount-appengine-sample/src/main/java/com/google/api/client/sample/storage/appengine/serviceaccount/StorageSample.java b/storage/xml-api/serviceaccount-appengine-sample/src/main/java/com/google/api/client/sample/storage/appengine/serviceaccount/StorageSample.java deleted file mode 100644 index 41796b7824d..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/src/main/java/com/google/api/client/sample/storage/appengine/serviceaccount/StorageSample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.api.client.sample.storage.appengine.serviceaccount; - -import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; // SUPPRESS CHECKSTYLE LineLength -import com.google.api.client.http.GenericUrl; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestFactory; -import com.google.api.client.http.HttpResponse; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.javanet.NetHttpTransport; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.Arrays; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Google Cloud Storage Service Account App Engine sample. - * - * @author Marc Cohen - */ -public class StorageSample extends HttpServlet { - - /** HTTP status code for a resource that wasn't found. */ - private static final int HTTP_NOT_FOUND = 404; - /** HTTP status code for a resource that was found. */ - private static final int HTTP_OK = 200; - - /** The base endpoint for Google Cloud Storage api calls. */ - private static final String GCS_URI = "http://commondatastorage.googleapis.com"; - - /** Global configuration of Google Cloud Storage OAuth 2.0 scope. */ - private static final String STORAGE_SCOPE = - "https://www.googleapis.com/auth/devstorage.read_write"; - - /** Global instance of the HTTP transport. */ - private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); - - /** Global instance of HTML reference to XSL style sheet. */ - private static final String XSL = - "\n\n"; - - @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("( - - bucket-list-java - 1 - true - - - - - - - - diff --git a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/logging.properties b/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/logging.properties deleted file mode 100644 index 519738e8a0d..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/logging.properties +++ /dev/null @@ -1,17 +0,0 @@ -# A default java.util.logging configuration. -# (All App Engine logging is through java.util.logging by default). -# -# To use this configuration, copy it into your application's WEB-INF -# folder and add the following to your appengine-web.xml: -# -# -# -# -# - -# Set the default logging level for all loggers to WARNING -.level = WARNING - -# Set the logging level for the Google APIs Java Client -# Uncomment this to debug the Google API Client Library for Java -#com.google.api.client.level = CONFIG diff --git a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/web.xml b/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 98f20cd8ebb..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - app - com.google.api.client.sample.storage.appengine.serviceaccount.StorageSample - - - - app - / - - - - xsl - text/xsl - - - diff --git a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/xsl/listing.xsl b/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/xsl/listing.xsl deleted file mode 100644 index ba12ba4f721..00000000000 --- a/storage/xml-api/serviceaccount-appengine-sample/src/main/webapp/xsl/listing.xsl +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - -

Google Cloud Storage Content Listing for Bucket -

- - - - - - - - - - - - - - - - - -
Object NameModification TimeETagSizeStorage Class
- - -
-