Java Code Examples for org.apache.camel.util.StringHelper#before()

The following examples show how to use org.apache.camel.util.StringHelper#before() . 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: CamelCloudServiceFilterAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
private CamelCloudServiceFilter createServiceFilter(CamelCloudConfigurationProperties.ServiceFilterConfiguration configuration) {
    BlacklistServiceFilter blacklist = new BlacklistServiceFilter();

    Map<String, List<String>> services = configuration.getBlacklist();
    for (Map.Entry<String, List<String>> entry : services.entrySet()) {
        for (String part : entry.getValue()) {
            String host = StringHelper.before(part, ":");
            String port = StringHelper.after(part, ":");

            if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
                blacklist.addServer(
                    DefaultServiceDefinition.builder()
                        .withName(entry.getKey())
                        .withHost(host)
                        .withPort(Integer.parseInt(port))
                        .build()
                );
            }
        }
    }

    return new CamelCloudServiceFilter(Arrays.asList(new HealthyServiceFilter(), blacklist));
}
 
Example 2
Source File: KubernetesPropertiesFunction.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public String apply(String remainder) {
    final String defaultValue = StringHelper.after(remainder, ":");

    if (this.root == null) {
        return defaultValue;
    }

    final String name = StringHelper.before(remainder, "/");
    final String property = StringHelper.after(remainder, "/");

    if (name == null || property == null) {
        return defaultValue;
    }

    Path file = this.root.resolve(name.toLowerCase()).resolve(property);
    if (Files.exists(file) && !Files.isDirectory(file)) {
        try {
            return Files.readString(file, StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    return defaultValue;
}
 
Example 3
Source File: HttpConnectorFactories.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public static String computeHttpUri(String scheme, Map<String, Object> options) {
    String baseUrl = (String)options.remove("baseUrl");

    if (ObjectHelper.isEmpty(baseUrl)) {
        throw new IllegalArgumentException("baseUrl si mandatory");
    }

    String uriScheme = StringHelper.before(baseUrl, "://");
    if (ObjectHelper.isNotEmpty(uriScheme) && !ObjectHelper.equal(scheme, uriScheme)) {
        throw new IllegalArgumentException("Unsupported scheme: " + uriScheme);
    }

    if (ObjectHelper.isNotEmpty(uriScheme)) {
        baseUrl = StringHelper.after(baseUrl, "://");
    }

    String path = (String)options.remove("path");
    if (StringUtils.isNotEmpty(path)) {
        return StringUtils.removeEnd(baseUrl, "/") + "/" + StringUtils.removeStart(path, "/");
    } else {
        return baseUrl;
    }
}
 
Example 4
Source File: HttpConnectorVerifierExtension.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public Result verify(Scope scope, Map<String, Object> parameters) {
    final Map<String, Object> options = new HashMap<>(parameters);

    String baseUrl = (String) options.remove("baseUrl");
    String uriScheme = StringHelper.before(baseUrl, "://");

    if (ObjectHelper.isNotEmpty(uriScheme) && !ObjectHelper.equal(supportedScheme, uriScheme)) {
        return ResultBuilder.withScope(scope).error(
            ResultErrorBuilder.withCode("unsupported_scheme")
                .description("Unsupported scheme: " + uriScheme)
                .parameterKey("baseUrl")
                .build()
        ).build();
    }

    if (ObjectHelper.isEmpty(uriScheme)) {
        baseUrl = new StringBuilder(supportedScheme).append("://").append(baseUrl).toString();
    }

    String path = (String) options.remove("path");
    if (ObjectHelper.isNotEmpty(path)) {
        final String uri = StringUtils.removeEnd(baseUrl, "/") + "/" + StringUtils.removeStart(path, "/");

        options.put("httpUri", uri);
    } else {
        options.put("httpUri", baseUrl);
    }

    Component component = getCamelContext().getComponent(this.componentScheme);
    if (component == null) {
        return ResultBuilder.withScope(scope).error(
            ResultErrorBuilder.withCode(VerificationError.StandardCode.UNSUPPORTED_COMPONENT)
                .description("Unsupported component " + this.componentScheme)
                .build()
        ).build();
    }

    return component.getExtension(ComponentVerifierExtension.class)
        .map(extension -> extension.verify(scope, options))
        .orElseGet(() -> ResultBuilder.unsupported().build());
}