private Integer standardizePort(Integer port) { Validate.isTrue(port == null || port >= -1, "Port must be positive (or null/-1 to indicate no port), but was '%s'", port); if (port != null && port == -1) { return null; } return port; }
private Integer standardizePort(Integer port) { Validate.isTrue(port == null || port >= -1, "Port must be positive (or null/-1 to indicate no port), but was '%s'", port); if (port != null && port == -1) { return null; } return port; }
/** * Require that the provided properties are configured in this profile. */ private void requireProperties(String... requiredProperties) { Arrays.stream(requiredProperties) .forEach(p -> Validate.isTrue(properties.containsKey(p), "Profile property '%s' was not configured for '%s'.", p, name)); }
/** * Require that the provided properties are configured in this profile. */ private void requireProperties(String... requiredProperties) { Arrays.stream(requiredProperties) .forEach(p -> Validate.isTrue(properties.containsKey(p), "Profile property '%s' was not configured for '%s'.", p, name)); }
@Override public Builder endpoint(URI endpoint) { if (endpoint != null) { Validate.isTrue(isEmpty(endpoint.getUserInfo()), "Proxy endpoint user info is not supported."); Validate.isTrue(isEmpty(endpoint.getPath()), "Proxy endpoint path is not supported."); Validate.isTrue(isEmpty(endpoint.getQuery()), "Proxy endpoint query is not supported."); Validate.isTrue(isEmpty(endpoint.getFragment()), "Proxy endpoint fragment is not supported."); } this.endpoint = endpoint; return this; }
private NewServiceCreator(CommandLine commandLine) { this.mavenProjectRoot = Paths.get(commandLine.getOptionValue("maven-project-root").trim()); this.mavenProjectVersion = commandLine.getOptionValue("maven-project-version").trim(); this.serviceModuleName = commandLine.getOptionValue("service-module-name").trim(); this.serviceId = commandLine.getOptionValue("service-id").trim(); this.serviceProtocol = transformSpecialProtocols(commandLine.getOptionValue("service-protocol").trim()); Validate.isTrue(Files.exists(mavenProjectRoot), "Project root does not exist: " + mavenProjectRoot); }
@Override public Builder endpoint(URI endpoint) { if (endpoint != null) { Validate.isTrue(isEmpty(endpoint.getUserInfo()), "Proxy endpoint user info is not supported."); Validate.isTrue(isEmpty(endpoint.getPath()), "Proxy endpoint path is not supported."); Validate.isTrue(isEmpty(endpoint.getQuery()), "Proxy endpoint query is not supported."); Validate.isTrue(isEmpty(endpoint.getFragment()), "Proxy endpoint fragment is not supported."); } this.endpoint = endpoint; return this; }
private String standardizeProtocol(String protocol) { Validate.paramNotNull(protocol, "protocol"); String standardizedProtocol = StringUtils.lowerCase(protocol); Validate.isTrue(standardizedProtocol.equals("http") || standardizedProtocol.equals("https"), "Protocol must be 'http' or 'https', but was %s", protocol); return standardizedProtocol; }
private String standardizeProtocol(String protocol) { Validate.paramNotNull(protocol, "protocol"); String standardizedProtocol = StringUtils.lowerCase(protocol); Validate.isTrue(standardizedProtocol.equals("http") || standardizedProtocol.equals("https"), "Protocol must be 'http' or 'https', but was %s", protocol); return standardizedProtocol; }
/** * Returns true if the specified port is the standard port for the given protocol. (i.e. 80 for HTTP or 443 for HTTPS). * * Null or -1 ports (to simplify interaction with {@link URI}'s default value) are treated as standard ports. * * @return True if the specified port is standard for the specified protocol, otherwise false. */ public static boolean isUsingStandardPort(String protocol, Integer port) { Validate.paramNotNull(protocol, "protocol"); Validate.isTrue(protocol.equals("http") || protocol.equals("https"), "Protocol must be 'http' or 'https', but was '%s'.", protocol); String scheme = StringUtils.lowerCase(protocol); return port == null || port == -1 || (scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443); }
/** * Returns true if the specified port is the standard port for the given protocol. (i.e. 80 for HTTP or 443 for HTTPS). * * Null or -1 ports (to simplify interaction with {@link URI}'s default value) are treated as standard ports. * * @return True if the specified port is standard for the specified protocol, otherwise false. */ public static boolean isUsingStandardPort(String protocol, Integer port) { Validate.paramNotNull(protocol, "protocol"); Validate.isTrue(protocol.equals("http") || protocol.equals("https"), "Protocol must be 'http' or 'https', but was '%s'.", protocol); String scheme = StringUtils.lowerCase(protocol); return port == null || port == -1 || (scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443); }
private SdkEventLoopGroup eventLoopGroup(DefaultBuilder builder) { Validate.isTrue(builder.eventLoopGroup == null || builder.eventLoopGroupBuilder == null, "The eventLoopGroup and the eventLoopGroupFactory can't both be configured."); return Either.fromNullable(builder.eventLoopGroup, builder.eventLoopGroupBuilder) .map(e -> e.map(this::nonManagedEventLoopGroup, SdkEventLoopGroup.Builder::build)) .orElseGet(SharedSdkEventLoopGroup::get); }
private SdkEventLoopGroup eventLoopGroup(DefaultBuilder builder) { Validate.isTrue(builder.eventLoopGroup == null || builder.eventLoopGroupBuilder == null, "The eventLoopGroup and the eventLoopGroupFactory can't both be configured."); return Either.fromNullable(builder.eventLoopGroup, builder.eventLoopGroupBuilder) .map(e -> e.map(this::nonManagedEventLoopGroup, SdkEventLoopGroup.Builder::build)) .orElseGet(SharedSdkEventLoopGroup::get); }
public void run() throws Exception { Validate.isTrue(Files.isRegularFile(serviceJson), serviceJson + " is not a file."); Path codegenFileLocation = codegenFileLocation(serviceModuleName); copyFile(serviceJson, codegenFileLocation.resolve("service-2.json")); copyFile(paginatorsJson, codegenFileLocation.resolve("paginators-1.json")); copyFile(waitersJson, codegenFileLocation.resolve("waiters-2.json")); }
/** * Given a property line, load the property key and value. If the property line is invalid and should be ignored, this will * return empty. */ private static Optional<Pair<String, String>> parsePropertyDefinition(ParserState state, String line) { int firstEqualsLocation = line.indexOf('='); Validate.isTrue(firstEqualsLocation != -1, "Expected an '=' sign defining a property on line " + state.currentLineNumber); String propertyKey = StringUtils.trim(line.substring(0, firstEqualsLocation)); String propertyValue = StringUtils.trim(line.substring(firstEqualsLocation + 1)); Validate.isTrue(!propertyKey.isEmpty(), "Property did not have a name on line " + state.currentLineNumber); // If the profile name includes invalid characters, it should be ignored. if (!isValidIdentifier(propertyKey)) { log.warn(() -> "Ignoring property '" + propertyKey + "' on line " + state.currentLineNumber + " because " + "its name was not alphanumeric with dashes or underscores."); return Optional.empty(); } return Optional.of(Pair.of(propertyKey, propertyValue)); }
/** * Given a property line, load the property key and value. If the property line is invalid and should be ignored, this will * return empty. */ private static Optional<Pair<String, String>> parsePropertyDefinition(ParserState state, String line) { int firstEqualsLocation = line.indexOf('='); Validate.isTrue(firstEqualsLocation != -1, "Expected an '=' sign defining a property on line " + state.currentLineNumber); String propertyKey = StringUtils.trim(line.substring(0, firstEqualsLocation)); String propertyValue = StringUtils.trim(line.substring(firstEqualsLocation + 1)); Validate.isTrue(!propertyKey.isEmpty(), "Property did not have a name on line " + state.currentLineNumber); // If the profile name includes invalid characters, it should be ignored. if (!isValidIdentifier(propertyKey)) { log.warn(() -> "Ignoring property '" + propertyKey + "' on line " + state.currentLineNumber + " because " + "its name was not alphanumeric with dashes or underscores."); return Optional.empty(); } return Optional.of(Pair.of(propertyKey, propertyValue)); }
/** * Finalize which sync HTTP client will be used for the created client. */ private SdkHttpClient resolveSyncHttpClient(SdkClientConfiguration config) { Validate.isTrue(config.option(SdkClientOption.SYNC_HTTP_CLIENT) == null || httpClientBuilder == null, "The httpClient and the httpClientBuilder can't both be configured."); return Either.fromNullable(config.option(SdkClientOption.SYNC_HTTP_CLIENT), httpClientBuilder) .map(e -> e.map(NonManagedSdkHttpClient::new, b -> b.buildWithDefaults(childHttpConfig()))) .orElseGet(() -> defaultHttpClientBuilder.buildWithDefaults(childHttpConfig())); }
/** * Finalize which async HTTP client will be used for the created client. */ private SdkAsyncHttpClient resolveAsyncHttpClient(SdkClientConfiguration config) { Validate.isTrue(config.option(ASYNC_HTTP_CLIENT) == null || asyncHttpClientBuilder == null, "The asyncHttpClient and the asyncHttpClientBuilder can't both be configured."); return Either.fromNullable(config.option(ASYNC_HTTP_CLIENT), asyncHttpClientBuilder) .map(e -> e.map(NonManagedSdkAsyncHttpClient::new, b -> b.buildWithDefaults(childHttpConfig()))) .orElseGet(() -> defaultAsyncHttpClientBuilder.buildWithDefaults(childHttpConfig())); }
/** * Static method to repeatedly call action until it succeeds or the max allowed attempts is * reached. * * @param callable Callable implementing assertion logic * @param params Retry related parameters * @return Successful result */ public static <T> T doRetryableAction(Callable<T> callable, RetryableParams params) throws Exception { Validate.isTrue(params.getMaxAttempts() > 0, "maxAttempts"); return new RetryableAction<T>(callable, params).call(); }
/** * Static method to repeatedly call action until it succeeds or the max allowed attempts is * reached. * * @param callable Callable implementing assertion logic * @param params Retry related parameters * @return Successful result */ public static <T> T doRetryableAction(Callable<T> callable, RetryableParams params) throws Exception { Validate.isTrue(params.getMaxAttempts() > 0, "maxAttempts"); return new RetryableAction<T>(callable, params).call(); }