@Bean public ConfigurableHttpConnectionFactory httpClientConnectionFactory() { return new HttpClientConfigurableHttpConnectionFactory(); } }
@Override public HttpConnection create(URL url) throws IOException { return create(url, null); }
private String getUrlWithPlaceholders(URL url, String key) { String spec = url.toString(); String[] tokens = key.split(PLACEHOLDER_PATTERN); if (tokens.length > 1) { List<String> placeholders = getPlaceholders(key); List<String> values = getValues(spec, tokens); if (placeholders.size() == values.size()) { for (int i = 0; i < values.size(); i++) { spec = spec.replace(values.get(i), String.format("{%s}", placeholders.get(i))); } } } return spec; }
@Override public void addConfiguration(MultipleJGitEnvironmentProperties environmentProperties) throws GeneralSecurityException { addHttpClient(environmentProperties); for (JGitEnvironmentProperties repo : environmentProperties.getRepos().values()) { addHttpClient(repo); } }
@Override public HttpConnection create(URL url, Proxy proxy) throws IOException { return new HttpClientConnection(url.toString(), null, lookupHttpClientBuilder(url).build()); }
private HttpClientBuilder lookupHttpClientBuilder(final URL url) { Map<String, HttpClientBuilder> builderMap = httpClientBuildersByUri.entrySet().stream().filter(entry -> { String key = entry.getKey(); String spec = getUrlWithPlaceholders(url, key); if (spec.equals(key)) { return true; } int index = spec.lastIndexOf("/"); while (index != -1) { spec = spec.substring(0, index); if (spec.equals(key)) { return true; } index = spec.lastIndexOf("/"); } return false; }).collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); if (builderMap.isEmpty()) { log.warn(String.format("No custom http config found for URL: %s", url)); return HttpClients.custom(); } if (builderMap.size() > 1) { log.error(String.format("More than one git repo URL template matched URL: %s, proxy and skipSslValidation config won't be applied. Matched templates: %s", url, builderMap.keySet().stream().collect(Collectors.joining(", ")))); return HttpClients.custom(); } return new ArrayList<>(builderMap.values()).get(0); }