Skip to content

Commit 83ba79c

Browse files
authored
Merge branch 'master' into finks/corretto-user-agent
2 parents 9c4521c + 67d70c3 commit 83ba79c

File tree

19 files changed

+990
-114
lines changed

19 files changed

+990
-114
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "Amazon S3",
3+
"type": "feature",
4+
"description": "Add support for getUrl operation. The API can be used to generate a URL that represents an object in Amazon S3. The url can only be used to download the object content if the object has public read permissions. Original issue: https://github.com/aws/aws-sdk-java-v2/issues/860"
5+
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public class CustomizationConfig {
154154
*/
155155
private Map<String, String> paginationCustomization;
156156

157+
/**
158+
* Config to generate a utilities() in the low-level client
159+
*/
160+
private UtilitiesMethod utilitiesMethod;
161+
157162
private CustomizationConfig() {
158163
}
159164

@@ -393,4 +398,12 @@ public Map<String, String> getPaginationCustomization() {
393398
public void setPaginationCustomization(Map<String, String> paginationCustomization) {
394399
this.paginationCustomization = paginationCustomization;
395400
}
401+
402+
public UtilitiesMethod getUtilitiesMethod() {
403+
return utilitiesMethod;
404+
}
405+
406+
public void setUtilitiesMethod(UtilitiesMethod utilitiesMethod) {
407+
this.utilitiesMethod = utilitiesMethod;
408+
}
396409
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.model.config.customization;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
/**
22+
* Config required to generate the utilities method that returns an instance of
23+
* hand-written Utilities class
24+
*/
25+
public class UtilitiesMethod {
26+
27+
public static final String METHOD_NAME = "utilities";
28+
29+
/** Fqcn of the return type of the operation */
30+
private String returnType;
31+
32+
/**
33+
* The utilities method will call a protected create() method in the hand-written Utilities class.
34+
* These the ordered list of parameters that needs to be passed to the create method.
35+
*/
36+
private List<String> createMethodParams = new ArrayList<>();
37+
38+
public String getReturnType() {
39+
return returnType;
40+
}
41+
42+
public void setReturnType(String returnType) {
43+
this.returnType = returnType;
44+
}
45+
46+
public List<String> getCreateMethodParams() {
47+
return createMethodParams;
48+
}
49+
50+
public void setCreateMethodParams(List<String> createMethodParams) {
51+
this.createMethodParams = createMethodParams;
52+
}
53+
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils;
4545
import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller;
4646
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
47+
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
4748
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4849
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
4950
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
@@ -115,6 +116,10 @@ public TypeSpec poetSpec() {
115116
classBuilder.addMethod(applySignerOverrideMethod(poetExtensions, model));
116117
}
117118

119+
if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
120+
classBuilder.addMethod(utilitiesMethod());
121+
}
122+
118123
model.getEndpointOperation().ifPresent(
119124
o -> classBuilder.addField(EndpointDiscoveryRefreshCache.class, "endpointDiscoveryCache", PRIVATE));
120125

@@ -282,4 +287,18 @@ private CodeBlock createEventStreamTaggedUnionJsonMarshaller(ShapeModel eventStr
282287
private TypeName eventStreamType(ShapeModel shapeModel) {
283288
return poetExtensions.getModelClass(shapeModel.getShapeName());
284289
}
290+
291+
private MethodSpec utilitiesMethod() {
292+
UtilitiesMethod config = model.getCustomizationConfig().getUtilitiesMethod();
293+
ClassName returnType = PoetUtils.classNameFromFqcn(config.getReturnType());
294+
295+
return MethodSpec.methodBuilder(UtilitiesMethod.METHOD_NAME)
296+
.returns(returnType)
297+
.addModifiers(Modifier.PUBLIC)
298+
.addAnnotation(Override.class)
299+
.addStatement("return $T.create($L)",
300+
returnType,
301+
config.getCreateMethodParams().stream().collect(Collectors.joining(",")))
302+
.build();
303+
}
285304
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.codegen.docs.ClientType;
3737
import software.amazon.awssdk.codegen.docs.DocConfiguration;
3838
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
39+
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
3940
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4041
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
4142
import software.amazon.awssdk.codegen.poet.ClassSpec;
@@ -87,6 +88,10 @@ public TypeSpec poetSpec() {
8788
result.addMethod(builder())
8889
.addMethods(operationsAndSimpleMethods());
8990

91+
if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
92+
result.addMethod(utilitiesMethod());
93+
}
94+
9095
return result.build();
9196
}
9297

@@ -423,4 +428,18 @@ private ParameterizedTypeName completableFutureType(TypeName typeName) {
423428
private String consumerBuilderJavadoc(OperationModel opModel, SimpleMethodOverload overload) {
424429
return opModel.getDocs(model, ClientType.ASYNC, overload, new DocConfiguration().isConsumerBuilder(true));
425430
}
431+
432+
private MethodSpec utilitiesMethod() {
433+
UtilitiesMethod config = model.getCustomizationConfig().getUtilitiesMethod();
434+
ClassName returnType = PoetUtils.classNameFromFqcn(config.getReturnType());
435+
436+
return MethodSpec.methodBuilder(UtilitiesMethod.METHOD_NAME)
437+
.returns(returnType)
438+
.addModifiers(Modifier.PUBLIC)
439+
.addModifiers(Modifier.DEFAULT)
440+
.addStatement("throw new $T()", UnsupportedOperationException.class)
441+
.addJavadoc("Creates an instance of {@link $T} object with the "
442+
+ "configuration set on this client.", returnType)
443+
.build();
444+
}
426445
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
3535
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
3636
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
37+
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
3738
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
3839
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
3940
import software.amazon.awssdk.codegen.model.intermediate.Protocol;
@@ -99,6 +100,10 @@ public TypeSpec poetSpec() {
99100
classBuilder.addMethod(applySignerOverrideMethod(poetExtensions, model));
100101
}
101102

103+
if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
104+
classBuilder.addMethod(utilitiesMethod());
105+
}
106+
102107
model.getEndpointOperation().ifPresent(
103108
o -> classBuilder.addField(EndpointDiscoveryRefreshCache.class, "endpointDiscoveryCache", PRIVATE));
104109

@@ -219,6 +224,20 @@ private MethodSpec closeMethod() {
219224
.build();
220225
}
221226

227+
private MethodSpec utilitiesMethod() {
228+
UtilitiesMethod config = model.getCustomizationConfig().getUtilitiesMethod();
229+
ClassName returnType = PoetUtils.classNameFromFqcn(config.getReturnType());
230+
231+
return MethodSpec.methodBuilder(UtilitiesMethod.METHOD_NAME)
232+
.returns(returnType)
233+
.addModifiers(Modifier.PUBLIC)
234+
.addAnnotation(Override.class)
235+
.addStatement("return $T.create($L)",
236+
returnType,
237+
config.getCreateMethodParams().stream().collect(Collectors.joining(",")))
238+
.build();
239+
}
240+
222241
static ProtocolSpec getProtocolSpecs(PoetExtensions poetExtensions, IntermediateModel model) {
223242
Protocol protocol = model.getMetadata().getProtocol();
224243
switch (protocol) {

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.codegen.docs.ClientType;
3737
import software.amazon.awssdk.codegen.docs.DocConfiguration;
3838
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
39+
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
3940
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4041
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
4142
import software.amazon.awssdk.codegen.poet.ClassSpec;
@@ -85,9 +86,14 @@ public TypeSpec poetSpec() {
8586
.addMethods(operations())
8687
.addMethod(serviceMetadata());
8788

89+
if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
90+
result.addMethod(utilitiesMethod());
91+
}
92+
8893
return result.build();
8994
}
9095

96+
9197
@Override
9298
public ClassName className() {
9399
return className;
@@ -436,4 +442,18 @@ private static List<ClassName> getExceptionClasses(IntermediateModel model, Oper
436442
private String consumerBuilderJavadoc(OperationModel opModel, SimpleMethodOverload overload) {
437443
return opModel.getDocs(model, ClientType.SYNC, overload, new DocConfiguration().isConsumerBuilder(true));
438444
}
445+
446+
private MethodSpec utilitiesMethod() {
447+
UtilitiesMethod config = model.getCustomizationConfig().getUtilitiesMethod();
448+
ClassName returnType = PoetUtils.classNameFromFqcn(config.getReturnType());
449+
450+
return MethodSpec.methodBuilder(UtilitiesMethod.METHOD_NAME)
451+
.returns(returnType)
452+
.addModifiers(Modifier.PUBLIC)
453+
.addModifiers(Modifier.DEFAULT)
454+
.addStatement("throw new $T()", UnsupportedOperationException.class)
455+
.addJavadoc("Creates an instance of {@link $T} object with the "
456+
+ "configuration set on this client.", returnType)
457+
.build();
458+
}
439459
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/json/customization.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
99
"blacklistedSimpleMethods" : [
1010
"eventStreamOperation"
11-
]
11+
],
12+
"utilitiesMethod": {
13+
"returnType": "software.amazon.awssdk.services.json.JsonUtilities",
14+
"createMethodParams": ["param1", "param2", "param3"]
15+
}
1216
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-async-client-class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,11 @@ private <T extends JsonRequest> T applySignerOverride(T request, Signer signer)
847847
return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
848848
}
849849

850+
@Override
851+
public JsonUtilities utilities() {
852+
return JsonUtilities.create(param1, param2, param3);
853+
}
854+
850855
private HttpResponseHandler<AwsServiceException> createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
851856
JsonOperationMetadata operationMetadata) {
852857
return protocolFactory.createErrorResponseHandler(operationMetadata);

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,4 +1291,11 @@ default CompletableFuture<StreamingOutputOperationResponse> streamingOutputOpera
12911291
return streamingOutputOperation(StreamingOutputOperationRequest.builder().applyMutation(streamingOutputOperationRequest)
12921292
.build(), destinationPath);
12931293
}
1294+
1295+
/**
1296+
* Creates an instance of {@link JsonUtilities} object with the configuration set on this client.
1297+
*/
1298+
default JsonUtilities utilities() {
1299+
throw new UnsupportedOperationException();
1300+
}
12941301
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,4 +623,9 @@ private <T extends JsonRequest> T applySignerOverride(T request, Signer signer)
623623
.orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build()));
624624
return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
625625
}
626+
627+
@Override
628+
public JsonUtilities utilities() {
629+
return JsonUtilities.create(param1, param2, param3);
630+
}
626631
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,4 +1287,11 @@ default ResponseBytes<StreamingOutputOperationResponse> streamingOutputOperation
12871287
static ServiceMetadata serviceMetadata() {
12881288
return ServiceMetadata.of("json-service");
12891289
}
1290+
1291+
/**
1292+
* Creates an instance of {@link JsonUtilities} object with the configuration set on this client.
1293+
*/
1294+
default JsonUtilities utilities() {
1295+
throw new UnsupportedOperationException();
1296+
}
12901297
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/exception/SdkException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ protected SdkException(Builder builder) {
3333
super(builder.message(), builder.cause());
3434
}
3535

36+
public static SdkException create(String message, Throwable cause) {
37+
return SdkException.builder().message(message).cause(cause).build();
38+
}
39+
3640
/**
3741
* Specifies whether or not an exception can be expected to succeed on a retry.
3842
*/

0 commit comments

Comments
 (0)