Skip to content

Expose the metadata key on client interfaces #2327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-b5091ac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Expose the metadata key on SDK client interfaces for use with `ServiceMetadataProvider`"
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import software.amazon.awssdk.core.SdkClient;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.regions.ServiceMetadataProvider;
import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain;

public class AsyncClientInterface implements ClassSpec {
Expand Down Expand Up @@ -78,6 +79,12 @@ public TypeSpec poetSpec() {
.addField(FieldSpec.builder(String.class, "SERVICE_NAME")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", model.getMetadata().getSigningName())
.build())
.addField(FieldSpec.builder(String.class, "SERVICE_METADATA_ID")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", model.getMetadata().getEndpointPrefix())
.addJavadoc("Value for looking up the service's metadata from the {@link $T}.",
ServiceMetadataProvider.class)
.build());

PoetUtils.addJavadoc(result::addJavadoc, getJavadoc());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.core.sync.ResponseTransformer;
import software.amazon.awssdk.regions.ServiceMetadata;
import software.amazon.awssdk.regions.ServiceMetadataProvider;
import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain;

public final class SyncClientInterface implements ClassSpec {
Expand All @@ -78,7 +79,13 @@ public TypeSpec poetSpec() {
.addField(FieldSpec.builder(String.class, "SERVICE_NAME")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", model.getMetadata().getSigningName())
.build());
.build())
.addField(FieldSpec.builder(String.class, "SERVICE_METADATA_ID")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", model.getMetadata().getEndpointPrefix())
.addJavadoc("Value for looking up the service's metadata from the {@link $T}.",
ServiceMetadataProvider.class)
.build());

PoetUtils.addJavadoc(result::addJavadoc, getJavadoc());

Expand Down Expand Up @@ -148,7 +155,7 @@ private MethodSpec serviceMetadata() {
return MethodSpec.methodBuilder("serviceMetadata")
.returns(ServiceMetadata.class)
.addModifiers(Modifier.STATIC, Modifier.PUBLIC)
.addStatement("return $T.of($S)", ServiceMetadata.class, model.getMetadata().getEndpointPrefix())
.addStatement("return $T.of(SERVICE_METADATA_ID)", ServiceMetadata.class)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
abstract class DefaultJsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends AwsDefaultClientBuilder<B, C> {
@Override
protected final String serviceEndpointPrefix() {
return "json-service";
return "json-service-endpoint";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"version": "2.0",
"metadata": {
"apiVersion": "2010-05-08",
"endpointPrefix": "json-service",
"endpointPrefix": "json-service-endpoint",
"globalEndpoint": "json-service.amazonaws.com",
"protocol": "rest-json",
"serviceAbbreviation": "Json Service",
"serviceFullName": "Some Service That Uses Json Protocol",
"serviceId":"Json Service",
"serviceId": "Json Service",
"signingName": "json-service",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added so it tests when singing name != endpoint prefix

"signatureVersion": "v4",
"uid": "json-service-2010-05-08",
"xmlNamespace": "https://json-service.amazonaws.com/doc/2010-05-08/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
public interface JsonAsyncClient extends SdkClient {
String SERVICE_NAME = "json-service";

/**
* Value for looking up the service's metadata from the
* {@link software.amazon.awssdk.regions.ServiceMetadataProvider}.
*/
String SERVICE_METADATA_ID = "json-service-endpoint";

/**
* Create a {@link JsonAsyncClient} with the region loaded from the
* {@link software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain} and credentials loaded from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
public interface JsonClient extends SdkClient {
String SERVICE_NAME = "json-service";

/**
* Value for looking up the service's metadata from the
* {@link software.amazon.awssdk.regions.ServiceMetadataProvider}.
*/
String SERVICE_METADATA_ID = "json-service-endpoint";

/**
* Create a {@link JsonClient} with the region loaded from the
* {@link software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain} and credentials loaded from the
Expand Down Expand Up @@ -1358,7 +1364,7 @@ default ResponseBytes<StreamingOutputOperationResponse> streamingOutputOperation
}

static ServiceMetadata serviceMetadata() {
return ServiceMetadata.of("json-service");
return ServiceMetadata.of(SERVICE_METADATA_ID);
}

/**
Expand Down