diff --git a/java-private-catalog/README.md b/java-private-catalog/README.md index a9ae7ca7b408..109be5a3be7b 100644 --- a/java-private-catalog/README.md +++ b/java-private-catalog/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-private-catalog - 0.4.0 + 0.4.1 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-private-catalog:0.4.0' +implementation 'com.google.cloud:google-cloud-private-catalog:0.4.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-private-catalog" % "0.4.0" +libraryDependencies += "com.google.cloud" % "google-cloud-private-catalog" % "0.4.1" ``` ## Authentication diff --git a/java-private-catalog/google-cloud-private-catalog/pom.xml b/java-private-catalog/google-cloud-private-catalog/pom.xml index 41b2d61b7d79..96043fd64fba 100644 --- a/java-private-catalog/google-cloud-private-catalog/pom.xml +++ b/java-private-catalog/google-cloud-private-catalog/pom.xml @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + @@ -73,12 +77,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClient.java b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClient.java index d432b2a7aa38..d3347847649e 100644 --- a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClient.java +++ b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClient.java @@ -120,6 +120,20 @@ * PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create(privateCatalogSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * PrivateCatalogSettings privateCatalogSettings =
+ *     PrivateCatalogSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             PrivateCatalogSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create(privateCatalogSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogSettings.java b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogSettings.java index e4ceb0f4c87c..09549b53d887 100644 --- a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogSettings.java +++ b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogSettings.java @@ -25,6 +25,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -121,11 +122,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return PrivateCatalogStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return PrivateCatalogStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return PrivateCatalogStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return PrivateCatalogStubSettings.defaultTransportChannelProvider(); } @@ -135,11 +143,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return PrivateCatalogStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -177,6 +191,11 @@ private static Builder createDefault() { return new Builder(PrivateCatalogStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(PrivateCatalogStubSettings.newHttpJsonBuilder()); + } + public PrivateCatalogStubSettings.Builder getStubSettingsBuilder() { return ((PrivateCatalogStubSettings.Builder) getStubSettings()); } diff --git a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogCallableFactory.java b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogCallableFactory.java new file mode 100644 index 000000000000..ece8c7f7da47 --- /dev/null +++ b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the PrivateCatalog service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPrivateCatalogCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogStub.java b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogStub.java new file mode 100644 index 000000000000..05a7e51a436d --- /dev/null +++ b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/HttpJsonPrivateCatalogStub.java @@ -0,0 +1,352 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.stub; + +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchCatalogsPagedResponse; +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchProductsPagedResponse; +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchVersionsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsResponse; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsResponse; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the PrivateCatalog service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPrivateCatalogStub extends PrivateCatalogStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + searchCatalogsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchCatalogs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=projects/*}/catalogs:search", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=organizations/*}/catalogs:search", + "/v1beta1/{resource=folders/*}/catalogs:search") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchCatalogsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + searchProductsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchProducts") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=projects/*}/products:search", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=organizations/*}/products:search", + "/v1beta1/{resource=folders/*}/products:search") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchProductsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + searchVersionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchVersions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=projects/*}/versions:search", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=organizations/*}/versions:search", + "/v1beta1/{resource=folders/*}/versions:search") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchVersionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable searchCatalogsCallable; + private final UnaryCallable + searchCatalogsPagedCallable; + private final UnaryCallable searchProductsCallable; + private final UnaryCallable + searchProductsPagedCallable; + private final UnaryCallable searchVersionsCallable; + private final UnaryCallable + searchVersionsPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonPrivateCatalogStub create(PrivateCatalogStubSettings settings) + throws IOException { + return new HttpJsonPrivateCatalogStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonPrivateCatalogStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonPrivateCatalogStub( + PrivateCatalogStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonPrivateCatalogStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonPrivateCatalogStub( + PrivateCatalogStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonPrivateCatalogStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonPrivateCatalogStub( + PrivateCatalogStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonPrivateCatalogCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonPrivateCatalogStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonPrivateCatalogStub( + PrivateCatalogStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + searchCatalogsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchCatalogsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + searchProductsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchProductsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + searchVersionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchVersionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.searchCatalogsCallable = + callableFactory.createUnaryCallable( + searchCatalogsTransportSettings, settings.searchCatalogsSettings(), clientContext); + this.searchCatalogsPagedCallable = + callableFactory.createPagedCallable( + searchCatalogsTransportSettings, settings.searchCatalogsSettings(), clientContext); + this.searchProductsCallable = + callableFactory.createUnaryCallable( + searchProductsTransportSettings, settings.searchProductsSettings(), clientContext); + this.searchProductsPagedCallable = + callableFactory.createPagedCallable( + searchProductsTransportSettings, settings.searchProductsSettings(), clientContext); + this.searchVersionsCallable = + callableFactory.createUnaryCallable( + searchVersionsTransportSettings, settings.searchVersionsSettings(), clientContext); + this.searchVersionsPagedCallable = + callableFactory.createPagedCallable( + searchVersionsTransportSettings, settings.searchVersionsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(searchCatalogsMethodDescriptor); + methodDescriptors.add(searchProductsMethodDescriptor); + methodDescriptors.add(searchVersionsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable searchCatalogsCallable() { + return searchCatalogsCallable; + } + + @Override + public UnaryCallable + searchCatalogsPagedCallable() { + return searchCatalogsPagedCallable; + } + + @Override + public UnaryCallable searchProductsCallable() { + return searchProductsCallable; + } + + @Override + public UnaryCallable + searchProductsPagedCallable() { + return searchProductsPagedCallable; + } + + @Override + public UnaryCallable searchVersionsCallable() { + return searchVersionsCallable; + } + + @Override + public UnaryCallable + searchVersionsPagedCallable() { + return searchVersionsPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/PrivateCatalogStubSettings.java b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/PrivateCatalogStubSettings.java index 37c3e9b7a9fb..de9586969e51 100644 --- a/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/PrivateCatalogStubSettings.java +++ b/java-private-catalog/google-cloud-private-catalog/src/main/java/com/google/cloud/privatecatalog/v1beta1/stub/PrivateCatalogStubSettings.java @@ -29,6 +29,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -300,6 +303,11 @@ public PrivateCatalogStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcPrivateCatalogStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonPrivateCatalogStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -332,18 +340,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(PrivateCatalogStubSettings.class)) @@ -351,11 +366,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(PrivateCatalogStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return PrivateCatalogStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -448,6 +482,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .searchCatalogsSettings() diff --git a/java-private-catalog/google-cloud-private-catalog/src/test/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClientHttpJsonTest.java b/java-private-catalog/google-cloud-private-catalog/src/test/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClientHttpJsonTest.java new file mode 100644 index 000000000000..5f39faa2855f --- /dev/null +++ b/java-private-catalog/google-cloud-private-catalog/src/test/java/com/google/cloud/privatecatalog/v1beta1/PrivateCatalogClientHttpJsonTest.java @@ -0,0 +1,265 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1; + +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchCatalogsPagedResponse; +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchProductsPagedResponse; +import static com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient.SearchVersionsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.privatecatalog.v1beta1.stub.HttpJsonPrivateCatalogStub; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class PrivateCatalogClientHttpJsonTest { + private static MockHttpService mockService; + private static PrivateCatalogClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonPrivateCatalogStub.getMethodDescriptors(), + PrivateCatalogSettings.getDefaultEndpoint()); + PrivateCatalogSettings settings = + PrivateCatalogSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + PrivateCatalogSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = PrivateCatalogClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void searchCatalogsTest() throws Exception { + Catalog responsesElement = Catalog.newBuilder().build(); + SearchCatalogsResponse expectedResponse = + SearchCatalogsResponse.newBuilder() + .setNextPageToken("") + .addAllCatalogs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + SearchCatalogsRequest request = + SearchCatalogsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + SearchCatalogsPagedResponse pagedListResponse = client.searchCatalogs(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCatalogsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchCatalogsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SearchCatalogsRequest request = + SearchCatalogsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.searchCatalogs(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchProductsTest() throws Exception { + Product responsesElement = Product.newBuilder().build(); + SearchProductsResponse expectedResponse = + SearchProductsResponse.newBuilder() + .setNextPageToken("") + .addAllProducts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + SearchProductsRequest request = + SearchProductsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + SearchProductsPagedResponse pagedListResponse = client.searchProducts(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchProductsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SearchProductsRequest request = + SearchProductsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.searchProducts(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchVersionsTest() throws Exception { + Version responsesElement = Version.newBuilder().build(); + SearchVersionsResponse expectedResponse = + SearchVersionsResponse.newBuilder() + .setNextPageToken("") + .addAllVersions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + SearchVersionsRequest request = + SearchVersionsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + SearchVersionsPagedResponse pagedListResponse = client.searchVersions(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchVersionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SearchVersionsRequest request = + SearchVersionsRequest.newBuilder() + .setResource("projects/project-4963") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.searchVersions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..bae32f187ab4 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogSettings; +import com.google.cloud.privatecatalog.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PrivateCatalogSettings privateCatalogSettings = + PrivateCatalogSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create(privateCatalogSettings); + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_create_setcredentialsprovider_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider1.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..eea1dea4c579 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_create_setcredentialsprovider1_sync] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PrivateCatalogSettings privateCatalogSettings = + PrivateCatalogSettings.newBuilder() + .setTransportChannelProvider( + PrivateCatalogSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create(privateCatalogSettings); + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_create_setcredentialsprovider1_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetEndpoint.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..4c3ab29042f4 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_create_setendpoint_sync] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogSettings; +import com.google.cloud.privatecatalog.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PrivateCatalogSettings privateCatalogSettings = + PrivateCatalogSettings.newBuilder().setEndpoint(myEndpoint).build(); + PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create(privateCatalogSettings); + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_create_setendpoint_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogs.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogs.java new file mode 100644 index 000000000000..2d31d6d4b052 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogs.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.privatecatalog.v1beta1.Catalog; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsRequest; + +public class AsyncSearchCatalogs { + + public static void main(String[] args) throws Exception { + asyncSearchCatalogs(); + } + + public static void asyncSearchCatalogs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchCatalogsRequest request = + SearchCatalogsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + privateCatalogClient.searchCatalogsPagedCallable().futureCall(request); + // Do something. + for (Catalog element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogsPaged.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogsPaged.java new file mode 100644 index 000000000000..83ef240bb1eb --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/AsyncSearchCatalogsPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_paged_async] +import com.google.cloud.privatecatalog.v1beta1.Catalog; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsResponse; +import com.google.common.base.Strings; + +public class AsyncSearchCatalogsPaged { + + public static void main(String[] args) throws Exception { + asyncSearchCatalogsPaged(); + } + + public static void asyncSearchCatalogsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchCatalogsRequest request = + SearchCatalogsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + SearchCatalogsResponse response = + privateCatalogClient.searchCatalogsCallable().call(request); + for (Catalog element : response.getCatalogsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_paged_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/SyncSearchCatalogs.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/SyncSearchCatalogs.java new file mode 100644 index 000000000000..48bb573d25f8 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchcatalogs/SyncSearchCatalogs.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_sync] +import com.google.cloud.privatecatalog.v1beta1.Catalog; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchCatalogsRequest; + +public class SyncSearchCatalogs { + + public static void main(String[] args) throws Exception { + syncSearchCatalogs(); + } + + public static void syncSearchCatalogs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchCatalogsRequest request = + SearchCatalogsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Catalog element : privateCatalogClient.searchCatalogs(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchcatalogs_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProducts.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProducts.java new file mode 100644 index 000000000000..81e38b718f9c --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProducts.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.Product; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsRequest; + +public class AsyncSearchProducts { + + public static void main(String[] args) throws Exception { + asyncSearchProducts(); + } + + public static void asyncSearchProducts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchProductsRequest request = + SearchProductsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + privateCatalogClient.searchProductsPagedCallable().futureCall(request); + // Do something. + for (Product element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProductsPaged.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProductsPaged.java new file mode 100644 index 000000000000..518887e4a401 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/AsyncSearchProductsPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_paged_async] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.Product; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsResponse; +import com.google.common.base.Strings; + +public class AsyncSearchProductsPaged { + + public static void main(String[] args) throws Exception { + asyncSearchProductsPaged(); + } + + public static void asyncSearchProductsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchProductsRequest request = + SearchProductsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + SearchProductsResponse response = + privateCatalogClient.searchProductsCallable().call(request); + for (Product element : response.getProductsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_paged_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/SyncSearchProducts.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/SyncSearchProducts.java new file mode 100644 index 000000000000..dd4b2a6d5ea3 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchproducts/SyncSearchProducts.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_sync] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.Product; +import com.google.cloud.privatecatalog.v1beta1.SearchProductsRequest; + +public class SyncSearchProducts { + + public static void main(String[] args) throws Exception { + syncSearchProducts(); + } + + public static void syncSearchProducts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchProductsRequest request = + SearchProductsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Product element : privateCatalogClient.searchProducts(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchproducts_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersions.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersions.java new file mode 100644 index 000000000000..81c7ab1b044e --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersions.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsRequest; +import com.google.cloud.privatecatalog.v1beta1.Version; + +public class AsyncSearchVersions { + + public static void main(String[] args) throws Exception { + asyncSearchVersions(); + } + + public static void asyncSearchVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchVersionsRequest request = + SearchVersionsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + privateCatalogClient.searchVersionsPagedCallable().futureCall(request); + // Do something. + for (Version element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersionsPaged.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersionsPaged.java new file mode 100644 index 000000000000..8ce7cb4fa92a --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/AsyncSearchVersionsPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_paged_async] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsRequest; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsResponse; +import com.google.cloud.privatecatalog.v1beta1.Version; +import com.google.common.base.Strings; + +public class AsyncSearchVersionsPaged { + + public static void main(String[] args) throws Exception { + asyncSearchVersionsPaged(); + } + + public static void asyncSearchVersionsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchVersionsRequest request = + SearchVersionsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + SearchVersionsResponse response = + privateCatalogClient.searchVersionsCallable().call(request); + for (Version element : response.getVersionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_paged_async] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/SyncSearchVersions.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/SyncSearchVersions.java new file mode 100644 index 000000000000..dd2946223ebe --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogclient/searchversions/SyncSearchVersions.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_sync] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogClient; +import com.google.cloud.privatecatalog.v1beta1.SearchVersionsRequest; +import com.google.cloud.privatecatalog.v1beta1.Version; + +public class SyncSearchVersions { + + public static void main(String[] args) throws Exception { + syncSearchVersions(); + } + + public static void syncSearchVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PrivateCatalogClient privateCatalogClient = PrivateCatalogClient.create()) { + SearchVersionsRequest request = + SearchVersionsRequest.newBuilder() + .setResource("resource-341064690") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Version element : privateCatalogClient.searchVersions(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogclient_searchversions_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogsettings/searchcatalogs/SyncSearchCatalogs.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogsettings/searchcatalogs/SyncSearchCatalogs.java new file mode 100644 index 000000000000..56f9b77e0641 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/privatecatalogsettings/searchcatalogs/SyncSearchCatalogs.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogsettings_searchcatalogs_sync] +import com.google.cloud.privatecatalog.v1beta1.PrivateCatalogSettings; +import java.time.Duration; + +public class SyncSearchCatalogs { + + public static void main(String[] args) throws Exception { + syncSearchCatalogs(); + } + + public static void syncSearchCatalogs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PrivateCatalogSettings.Builder privateCatalogSettingsBuilder = + PrivateCatalogSettings.newBuilder(); + privateCatalogSettingsBuilder + .searchCatalogsSettings() + .setRetrySettings( + privateCatalogSettingsBuilder + .searchCatalogsSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PrivateCatalogSettings privateCatalogSettings = privateCatalogSettingsBuilder.build(); + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogsettings_searchcatalogs_sync] diff --git a/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/stub/privatecatalogstubsettings/searchcatalogs/SyncSearchCatalogs.java b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/stub/privatecatalogstubsettings/searchcatalogs/SyncSearchCatalogs.java new file mode 100644 index 000000000000..ab4f94c04f30 --- /dev/null +++ b/java-private-catalog/samples/snippets/generated/com/google/cloud/privatecatalog/v1beta1/stub/privatecatalogstubsettings/searchcatalogs/SyncSearchCatalogs.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * 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 + * + * https://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.cloud.privatecatalog.v1beta1.stub.samples; + +// [START privatecatalog_v1beta1_generated_privatecatalogstubsettings_searchcatalogs_sync] +import com.google.cloud.privatecatalog.v1beta1.stub.PrivateCatalogStubSettings; +import java.time.Duration; + +public class SyncSearchCatalogs { + + public static void main(String[] args) throws Exception { + syncSearchCatalogs(); + } + + public static void syncSearchCatalogs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PrivateCatalogStubSettings.Builder privateCatalogSettingsBuilder = + PrivateCatalogStubSettings.newBuilder(); + privateCatalogSettingsBuilder + .searchCatalogsSettings() + .setRetrySettings( + privateCatalogSettingsBuilder + .searchCatalogsSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PrivateCatalogStubSettings privateCatalogSettings = privateCatalogSettingsBuilder.build(); + } +} +// [END privatecatalog_v1beta1_generated_privatecatalogstubsettings_searchcatalogs_sync]