Java Code Examples for software.amazon.awssdk.utils.StringUtils#isNotBlank()

The following examples show how to use software.amazon.awssdk.utils.StringUtils#isNotBlank() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NonCollectionSetters.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<MethodSpec> beanStyle() {
    List<MethodSpec> methods = new ArrayList<>();
    methods.add(beanStyleSetterBuilder()
                    .addCode(beanCopySetterBody())
                    .build());

    if (StringUtils.isNotBlank(memberModel().getDeprecatedBeanStyleSetterMethodName())) {
        methods.add(deprecatedBeanStyleSetterBuilder()
                        .addCode(beanCopySetterBody())
                        .addAnnotation(Deprecated.class)
                        .addJavadoc("@deprecated Use {@link #" + memberModel().getBeanStyleSetterMethodName() + "} instead")
                        .build());
    }

    return methods;
}
 
Example 2
Source File: BaseClientBuilderClass.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private MethodSpec mergeServiceDefaultsMethod() {
    boolean crc32FromCompressedDataEnabled = model.getCustomizationConfig().isCalculateCrc32FromCompressedData();

    MethodSpec.Builder builder = MethodSpec.methodBuilder("mergeServiceDefaults")
                                           .addAnnotation(Override.class)
                                           .addModifiers(PROTECTED, FINAL)
                                           .returns(SdkClientConfiguration.class)
                                           .addParameter(SdkClientConfiguration.class, "config")
                                           .addCode("return config.merge(c -> c.option($T.SIGNER, defaultSigner())\n",
                                                    SdkAdvancedClientOption.class)
                                           .addCode("                          .option($T"
                                                    + ".CRC32_FROM_COMPRESSED_DATA_ENABLED, $L)",
                                                    SdkClientOption.class, crc32FromCompressedDataEnabled);

    String clientConfigClassName = model.getCustomizationConfig().getServiceSpecificClientConfigClass();
    if (StringUtils.isNotBlank(clientConfigClassName)) {
        builder.addCode(".option($T.SERVICE_CONFIGURATION, $T.builder().build())",
                        SdkClientOption.class, ClassName.bestGuess(clientConfigClassName));
    }

    builder.addCode(");");
    return builder.build();
}
 
Example 3
Source File: AddShapes.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private String deriveMarshallerLocationName(Shape memberShape, String memberName, Member member, String protocol) {
    String queryName = member.getQueryName();

    if (StringUtils.isNotBlank(queryName)) {
        return queryName;
    }

    String locationName;

    if (Protocol.EC2.getValue().equalsIgnoreCase(protocol)) {
        locationName = deriveLocationNameForEc2(member);
    } else if (memberShape.getListMember() != null && memberShape.isFlattened()) {
        locationName =  deriveLocationNameForListMember(memberShape, member);
    } else {
        locationName = member.getLocationName();
    }

    if (StringUtils.isNotBlank(locationName)) {
        return locationName;
    }

    return memberName;
}
 
Example 4
Source File: OperationDocProvider.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @return Constructs the Javadoc for this operation method overload.
 */
String getDocs() {
    DocumentationBuilder docBuilder = new DocumentationBuilder();

    String description = StringUtils.isNotBlank(opModel.getDocumentation()) ?
                         opModel.getDocumentation() :
                         getDefaultServiceDocs();

    String appendedDescription = appendToDescription();

    if (config.isConsumerBuilder()) {
        appendedDescription += getConsumerBuilderDocs();
    }

    docBuilder.description(StringUtils.isNotBlank(appendedDescription) ?
                           description + "<br/>" + appendedDescription :
                           description);

    applyParams(docBuilder);
    applyReturns(docBuilder);
    applyThrows(docBuilder);
    docBuilder.tag("sample", getInterfaceName() + "." + opModel.getOperationName());

    String crosslink = createLinkToServiceDocumentation(model.getMetadata(), opModel.getOperationName());
    if (!crosslink.isEmpty()) {
        docBuilder.see(crosslink);
    }
    return docBuilder.build().replace("$", "&#36");
}
 
Example 5
Source File: AbstractAwsConnector.java    From pulsar with Apache License 2.0 5 votes vote down vote up
/**
 * It creates a default credential provider which takes accessKey and secretKey form configuration and creates
 * {@link AWSCredentials}
 *
 * @param awsCredentialPluginParam
 * @return
 */
public AwsCredentialProviderPlugin defaultCredentialProvider(String awsCredentialPluginParam) {
    Map<String, String> credentialMap = new Gson().fromJson(awsCredentialPluginParam,
            new TypeToken<Map<String, String>>() {
            }.getType());
    String accessKey = credentialMap.get(ACCESS_KEY_NAME);
    String secretKey = credentialMap.get(SECRET_KEY_NAME);
    if (!(StringUtils.isNotBlank(accessKey) && StringUtils.isNotBlank(secretKey))) {
        throw new IllegalArgumentException(
                String.format(
                        "Default %s and %s must be present into json-map if AwsCredentialProviderPlugin not provided",
                        ACCESS_KEY_NAME, SECRET_KEY_NAME)
        );
    }
    return new AwsCredentialProviderPlugin() {
        @Override
        public void init(String param) {
            // noop

        }

        @Override
        public AWSCredentialsProvider getCredentialProvider() {
            return defaultCredentialProvider(accessKey, secretKey);
        }

        @Override
        public void close() throws IOException {

        }
    };
}
 
Example 6
Source File: AbstractAwsConnector.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public AwsCredentialProviderPlugin createCredentialProvider(String awsCredentialPluginName,
                                                               String awsCredentialPluginParam) {
    if (StringUtils.isNotBlank(awsCredentialPluginName)) {
        return createCredentialProviderWithPlugin(awsCredentialPluginName, awsCredentialPluginParam);
    } else {
        return defaultCredentialProvider(awsCredentialPluginParam);
    }
}
 
Example 7
Source File: AddShapes.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private String deriveLocationNameForListMember(Shape memberShape, Member member) {
    String locationName = memberShape.getListMember().getLocationName();

    if (StringUtils.isNotBlank(locationName)) {
        return locationName;
    }

    return member.getLocationName();
}
 
Example 8
Source File: AddShapes.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private String deriveLocationNameForEc2(Member member) {
    String locationName = member.getLocationName();

    if (StringUtils.isNotBlank(locationName)) {
        return StringUtils.upperCase(locationName.substring(0, 1)) +
               locationName.substring(1);
    }

    return null;
}
 
Example 9
Source File: AddShapes.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private String deriveUnmarshallerLocationName(Shape memberShape, String memberName, Member member) {
    String locationName;
    if (memberShape.getListMember() != null && memberShape.isFlattened()) {
        locationName = deriveLocationNameForListMember(memberShape, member);
    } else {
        locationName = member.getLocationName();
    }

    if (StringUtils.isNotBlank(locationName)) {
        return locationName;
    }

    return memberName;
}
 
Example 10
Source File: MemberModel.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public String getDefaultConsumerFluentSetterDocumentation() {
    return (StringUtils.isNotBlank(documentation) ? documentation : defaultSetter().replace("%s", name) + "\n")
           + LF
           + "This is a convenience that creates an instance of the {@link "
           + variable.getSimpleType()
           + ".Builder} avoiding the need to create one manually via {@link "
           + variable.getSimpleType()
           + "#builder()}.\n"
           + LF
           + "When the {@link Consumer} completes, {@link "
           + variable.getSimpleType()
           + ".Builder#build()} is called immediately and its result is passed to {@link #"
           + getFluentGetterMethodName()
           + "("
           + variable.getSimpleType()
           + ")}."
           + LF
           + "@param "
           + variable.getVariableName()
           + " a consumer that will call methods on {@link "
           + variable.getSimpleType() + ".Builder}"
           + LF
           + "@return " + stripHtmlTags(defaultFluentReturn())
           + LF
           + "@see #"
           + getFluentSetterMethodName()
           + "("
           + variable.getSimpleType()
           + ")";
}
 
Example 11
Source File: AmazonClientTransportRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void validateProxyEndpoint(String extension, URI endpoint, String clientType) {
    if (StringUtils.isBlank(endpoint.getScheme())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - scheme must be specified",
                        extension, clientType, endpoint.toString()));
    }
    if (StringUtils.isBlank(endpoint.getHost())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - host must be specified",
                        extension, clientType, endpoint.toString()));
    }
    if (StringUtils.isNotBlank(endpoint.getUserInfo())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - user info is not supported.",
                        extension, clientType, endpoint.toString()));
    }
    if (StringUtils.isNotBlank(endpoint.getPath())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - path is not supported.",
                        extension, clientType, endpoint.toString()));
    }
    if (StringUtils.isNotBlank(endpoint.getQuery())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - query is not supported.",
                        extension, clientType, endpoint.toString()));
    }
    if (StringUtils.isNotBlank(endpoint.getFragment())) {
        throw new RuntimeConfigurationError(
                String.format("quarkus.%s.%s-client.proxy.endpoint (%s) - fragment is not supported.",
                        extension, clientType, endpoint.toString()));
    }
}
 
Example 12
Source File: DocumentationBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the Javadoc string with the current configuration.
 *
 * @return Formatted Javadoc string.
 */
public String build() {
    StringBuilder str = new StringBuilder();
    if (StringUtils.isNotBlank(desc)) {
        str.append(desc).append(LF).append(LF);
    }
    params.forEach(p -> p.apply((paramName, paramDoc) -> formatParam(str, paramName, paramDoc)));
    if (hasReturn() || !asyncThrows.isEmpty()) {
        str.append("@return ");
        if (hasReturn()) {
            str.append(returns);
        }
        if (!asyncThrows.isEmpty()) {
            // If no docs were provided for success returns add a generic one.
            if (!hasReturn()) {
                str.append("A CompletableFuture indicating when result will be completed.");
            }
            appendAsyncThrows(str);
        }
        str.append(LF);
    }
    syncThrows.forEach(t -> t.apply((exName, exDoc) -> formatThrows(str, exName, exDoc)));
    tags.forEach(t -> t.apply((tagName, tagVals) -> formatTag(str, tagName, tagVals)));
    see.forEach(s -> str.append("@see ").append(s).append(LF));

    return str.toString();
}
 
Example 13
Source File: QueryMarshallerSpec.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<FieldSpec> memberVariables() {
    List<FieldSpec> fields = new ArrayList<>();

    CodeBlock.Builder initializationCodeBlockBuilder = CodeBlock.builder()
                                                                .add("$T.builder()", OperationInfo.class);
    initializationCodeBlockBuilder.add(".requestUri($S)", shapeModel.getMarshaller().getRequestUri())
                                  .add(".httpMethod($T.$L)", SdkHttpMethod.class, shapeModel.getMarshaller().getVerb())
                                  .add(".hasExplicitPayloadMember($L)", shapeModel.isHasPayloadMember() ||
                                                                        shapeModel.getExplicitEventPayloadMember() != null)
                                  .add(".hasPayloadMembers($L)", shapeModel.hasPayloadMembers());

    if (StringUtils.isNotBlank(shapeModel.getMarshaller().getTarget())) {
        initializationCodeBlockBuilder.add(".operationIdentifier($S)", shapeModel.getMarshaller().getTarget())
                                      .add(".apiVersion($S)", metadata.getApiVersion());
    }

    if (shapeModel.isHasStreamingMember()) {
        initializationCodeBlockBuilder.add(".hasStreamingInput(true)");
    }
    if (metadata.getProtocol() == Protocol.REST_XML) {
        String rootMarshallLocationName = shapeModel.getMarshaller() != null ?
                                          shapeModel.getMarshaller().getLocationName() : null;
        initializationCodeBlockBuilder.add(".putAdditionalMetadata($T.ROOT_MARSHALL_LOCATION_ATTRIBUTE, $S)",
                                           AwsXmlProtocolFactory.class, rootMarshallLocationName);
        initializationCodeBlockBuilder.add(".putAdditionalMetadata($T.XML_NAMESPACE_ATTRIBUTE, $S)",
                                           AwsXmlProtocolFactory.class, xmlNameSpaceUri());
    }

    CodeBlock codeBlock = initializationCodeBlockBuilder.add(".build()").build();

    FieldSpec.Builder instance = FieldSpec.builder(ClassName.get(OperationInfo.class), "SDK_OPERATION_BINDING")
                                          .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC)
                                          .initializer(codeBlock);

    fields.add(instance.build());
    fields.add(protocolFactory());
    return fields;
}
 
Example 14
Source File: JsonMarshallerSpec.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
protected FieldSpec operationInfoField() {
    CodeBlock.Builder initializationCodeBlockBuilder = CodeBlock.builder()
                                                                .add("$T.builder()", OperationInfo.class);
    initializationCodeBlockBuilder.add(".requestUri($S)", shapeModel.getMarshaller().getRequestUri())
                                  .add(".httpMethod($T.$L)", SdkHttpMethod.class, shapeModel.getMarshaller().getVerb())
                                  .add(".hasExplicitPayloadMember($L)", shapeModel.isHasPayloadMember() ||
                                                                        shapeModel.getExplicitEventPayloadMember() != null)
                                  .add(".hasPayloadMembers($L)", shapeModel.hasPayloadMembers());

    if (StringUtils.isNotBlank(shapeModel.getMarshaller().getTarget())) {
        initializationCodeBlockBuilder.add(".operationIdentifier($S)", shapeModel.getMarshaller().getTarget());
    }

    if (shapeModel.isHasStreamingMember()) {
        initializationCodeBlockBuilder.add(".hasStreamingInput(true)");
    }

    if (isEventStreamParentModel(shapeModel)) {
        initializationCodeBlockBuilder.add(".hasEventStreamingInput(true)");
    }

    CodeBlock codeBlock = initializationCodeBlockBuilder.add(".build()").build();

    return FieldSpec.builder(ClassName.get(OperationInfo.class), "SDK_OPERATION_BINDING")
                    .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC)
                    .initializer(codeBlock)
                    .build();
}
 
Example 15
Source File: MemberModel.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
public String getGetterDocumentation() {
    StringBuilder docBuilder = new StringBuilder();
    docBuilder.append(StringUtils.isNotBlank(documentation) ? documentation : defaultGetter().replace("%s", name))
            .append(LF);

    if (returnTypeIs(List.class) || returnTypeIs(Map.class)) {
        appendParagraph(docBuilder, "Attempts to modify the collection returned by this method will result in an "
                                    + "UnsupportedOperationException.");
    }

    if (enumType != null) {
        if (returnTypeIs(List.class)) {
            appendParagraph(docBuilder,
                            "If the list returned by the service includes enum values that are not available in the "
                            + "current SDK version, {@link #%s} will use {@link %s#UNKNOWN_TO_SDK_VERSION} in place of those "
                            + "values in the list. The raw values returned by the service are available from {@link #%s}.",
                            getFluentEnumGetterMethodName(), getEnumType(), getFluentGetterMethodName());
        } else if (returnTypeIs(Map.class)) {
            appendParagraph(docBuilder,
                            "If the map returned by the service includes enum values that are not available in the "
                            + "current SDK version, {@link #%s} will not include those keys in the map. {@link #%s} "
                            + "will include all data from the service.",
                            getFluentEnumGetterMethodName(), getEnumType(), getFluentGetterMethodName());
        } else {
            appendParagraph(docBuilder,
                            "If the service returns an enum value that is not available in the current SDK version, "
                            + "{@link #%s} will return {@link %s#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the "
                            + "service is available from {@link #%s}.",
                            getFluentEnumGetterMethodName(), getEnumType(), getFluentGetterMethodName());
        }
    }

    if (getAutoConstructClassIfExists().isPresent()) {
        appendParagraph(docBuilder,
                        "You can use {@link #%s()} to see if a value was sent in this field.",
                        getExistenceCheckMethodName());
    }

    String variableDesc = StringUtils.isNotBlank(documentation) ? documentation : defaultGetterParam().replace("%s", name);

    docBuilder.append("@return ")
              .append(stripHtmlTags(variableDesc))
              .append(getEnumDoc());

    return docBuilder.toString();
}
 
Example 16
Source File: AddShapes.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private MemberModel generateMemberModel(String c2jMemberName, Member c2jMemberDefinition,
                                        String protocol, Shape parentShape,
                                        Map<String, Shape> allC2jShapes) {
    String c2jShapeName = c2jMemberDefinition.getShape();
    Shape shape = allC2jShapes.get(c2jShapeName);
    String variableName = getNamingStrategy().getVariableName(c2jMemberName);
    String variableType = getTypeUtils().getJavaDataType(allC2jShapes, c2jShapeName);
    String variableDeclarationType = getTypeUtils()
            .getJavaDataType(allC2jShapes, c2jShapeName, getCustomizationConfig());

    //If member is idempotent, then it should be of string type
    //Else throw IllegalArgumentException.
    if (c2jMemberDefinition.isIdempotencyToken() &&
        !variableType.equals(String.class.getSimpleName())) {
        throw new IllegalArgumentException(c2jMemberName +
                                           " is idempotent. It's shape should be string type but it is of " +
                                           variableType + " type.");
    }


    MemberModel memberModel = new MemberModel();

    memberModel.withC2jName(c2jMemberName)
               .withC2jShape(c2jShapeName)
               .withName(capitalize(c2jMemberName))
               .withVariable(new VariableModel(variableName, variableType, variableDeclarationType)
                                     .withDocumentation(c2jMemberDefinition.getDocumentation()))
               .withSetterModel(new VariableModel(variableName, variableType, variableDeclarationType))
               .withGetterModel(new ReturnTypeModel(variableType))
               .withTimestampFormat(resolveTimestampFormat(c2jMemberDefinition, shape))
               .withJsonValue(c2jMemberDefinition.getJsonValue());
    memberModel.setDocumentation(c2jMemberDefinition.getDocumentation());
    memberModel.setDeprecated(c2jMemberDefinition.isDeprecated());
    memberModel.setSensitive(isSensitiveShapeOrContainer(c2jMemberDefinition, allC2jShapes));
    memberModel
            .withFluentGetterMethodName(namingStrategy.getFluentGetterMethodName(c2jMemberName, parentShape, shape))
            .withFluentEnumGetterMethodName(namingStrategy.getFluentEnumGetterMethodName(c2jMemberName, parentShape, shape))
            .withFluentSetterMethodName(namingStrategy.getFluentSetterMethodName(c2jMemberName, parentShape, shape))
            .withFluentEnumSetterMethodName(namingStrategy.getFluentEnumSetterMethodName(c2jMemberName, parentShape, shape))
            .withExistenceCheckMethodName(namingStrategy.getExistenceCheckMethodName(c2jMemberName, parentShape))
            .withBeanStyleGetterMethodName(namingStrategy.getBeanStyleGetterMethodName(c2jMemberName, parentShape, shape))
            .withBeanStyleSetterMethodName(namingStrategy.getBeanStyleSetterMethodName(c2jMemberName, parentShape, shape));
    memberModel.setIdempotencyToken(c2jMemberDefinition.isIdempotencyToken());
    memberModel.setEventPayload(c2jMemberDefinition.isEventPayload());
    memberModel.setEventHeader(c2jMemberDefinition.isEventHeader());
    memberModel.setEndpointDiscoveryId(c2jMemberDefinition.isEndpointDiscoveryId());
    memberModel.setXmlAttribute(c2jMemberDefinition.isXmlAttribute());

    // Pass the xmlNameSpace from the member reference
    if (c2jMemberDefinition.getXmlNamespace() != null) {
        memberModel.setXmlNameSpaceUri(c2jMemberDefinition.getXmlNamespace().getUri());
    }

    // Additional member model metadata for list/map/enum types
    fillContainerTypeMemberMetadata(allC2jShapes, c2jMemberDefinition.getShape(), memberModel,
                                    protocol);


    String deprecatedName = c2jMemberDefinition.getDeprecatedName();
    if (StringUtils.isNotBlank(deprecatedName)) {
        checkForValidDeprecatedName(c2jMemberName, shape);

        memberModel.setDeprecatedName(deprecatedName);
        memberModel.setDeprecatedFluentGetterMethodName(
            namingStrategy.getFluentGetterMethodName(deprecatedName, parentShape, shape));
        memberModel.setDeprecatedFluentSetterMethodName(
            namingStrategy.getFluentSetterMethodName(deprecatedName, parentShape, shape));
        memberModel.setDeprecatedBeanStyleSetterMethodName(
            namingStrategy.getBeanStyleSetterMethodName(deprecatedName, parentShape, shape));
    }

    ParameterHttpMapping httpMapping = generateParameterHttpMapping(parentShape,
                                                                          c2jMemberName,
                                                                          c2jMemberDefinition,
                                                                          protocol,
                                                                          allC2jShapes);

    String payload = parentShape.getPayload();

    boolean shapeIsStreaming = shape.isStreaming();
    boolean memberIsStreaming = c2jMemberDefinition.isStreaming();
    boolean payloadIsStreaming = shapeIsStreaming || memberIsStreaming;
    boolean requiresLength = shape.isRequiresLength() || c2jMemberDefinition.isRequiresLength();

    httpMapping.withPayload(payload != null && payload.equals(c2jMemberName))
               .withStreaming(payloadIsStreaming)
               .withRequiresLength(requiresLength);

    memberModel.setHttp(httpMapping);

    return memberModel;
}
 
Example 17
Source File: DocumentationBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private boolean hasReturn() {
    return StringUtils.isNotBlank(returns);
}
 
Example 18
Source File: BaseClientBuilderClass.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private MethodSpec finalizeServiceConfigurationMethod() {
    String requestHandlerDirectory = Utils.packageToDirectory(model.getMetadata().getFullClientPackageName());
    String requestHandlerPath = String.format("%s/execution.interceptors", requestHandlerDirectory);

    MethodSpec.Builder builder = MethodSpec.methodBuilder("finalizeServiceConfiguration")
                     .addAnnotation(Override.class)
                     .addModifiers(PROTECTED, FINAL)
                     .returns(SdkClientConfiguration.class)
                     .addParameter(SdkClientConfiguration.class, "config");

    // Initialize configuration values

    builder.addCode("$1T interceptorFactory = new $1T();\n", ClasspathInterceptorChainFactory.class)
           .addCode("$T<$T> interceptors = interceptorFactory.getInterceptors($S);\n",
                    List.class, ExecutionInterceptor.class, requestHandlerPath)
           .addCode("interceptors = $T.mergeLists(interceptors, config.option($T.EXECUTION_INTERCEPTORS));\n",
                    CollectionUtils.class, SdkClientOption.class);

    if (model.getMetadata().isQueryProtocol()) {
        TypeName listType = ParameterizedTypeName.get(List.class, ExecutionInterceptor.class);
        builder.addStatement("$T protocolInterceptors = $T.singletonList(new $T())",
                             listType,
                             Collections.class,
                             QueryParametersToBodyInterceptor.class);
        builder.addStatement("interceptors = $T.mergeLists(interceptors, protocolInterceptors)",
                             CollectionUtils.class);
    }

    if (model.getEndpointOperation().isPresent()) {
        builder.beginControlFlow("if (!endpointDiscoveryEnabled)")
               .addStatement("$1T chain = new $1T(config)", DefaultEndpointDiscoveryProviderChain.class)
               .addStatement("endpointDiscoveryEnabled = chain.resolveEndpointDiscovery()")
               .endControlFlow();
    }

    String clientConfigClassName = model.getCustomizationConfig().getServiceSpecificClientConfigClass();
    if (StringUtils.isNotBlank(clientConfigClassName)) {
        ClassName clientConfigClass = ClassName.bestGuess(clientConfigClassName);
        builder.addCode("$1T.Builder c = (($1T) config.option($2T.SERVICE_CONFIGURATION)).toBuilder();" +
                        "c.profileFile(c.profileFile() != null ? c.profileFile() : config.option($2T.PROFILE_FILE))" +
                        " .profileName(c.profileName() != null ? c.profileName() : config.option($2T.PROFILE_NAME));",
                        clientConfigClass, SdkClientOption.class);
    }

    // Update configuration

    builder.addCode("return config.toBuilder()\n");

    if (model.getEndpointOperation().isPresent()) {
        builder.addCode(".option($T.ENDPOINT_DISCOVERY_ENABLED, endpointDiscoveryEnabled)\n",
                        SdkClientOption.class);
    }

    builder.addCode(".option($1T.EXECUTION_INTERCEPTORS, interceptors)", SdkClientOption.class);

    if (StringUtils.isNotBlank(model.getCustomizationConfig().getCustomRetryPolicy())) {
        builder.addCode(".option($1T.RETRY_POLICY, $2T.resolveRetryPolicy(config))",
                        SdkClientOption.class,
                        PoetUtils.classNameFromFqcn(model.getCustomizationConfig().getCustomRetryPolicy()));
    }

    if (StringUtils.isNotBlank(clientConfigClassName)) {
        builder.addCode(".option($T.SERVICE_CONFIGURATION, c.build())", SdkClientOption.class);
    }

    builder.addCode(".build();");

    return builder.build();
}
 
Example 19
Source File: AwsServiceModel.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private boolean shouldGenerateDeprecatedNameGetter(MemberModel member) {
    return StringUtils.isNotBlank(member.getDeprecatedName());
}