Skip to content

Commit d69b215

Browse files
authored
Merge pull request #48 from gullerya/yuri-fixing-proxy-resolve
defect #663077: fixing the logic of proxy resolution to work on host only and not on the full URLs
2 parents a458c72 + f7559b2 commit d69b215

File tree

5 files changed

+69
-100
lines changed

5 files changed

+69
-100
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017 EntIT Software LLC, a Micro Focus company, L.P.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.hp.octane.integrations.exceptions;
18+
19+
20+
public class OctaneSDKGeneralException extends RuntimeException {
21+
22+
public OctaneSDKGeneralException(Throwable throwable) {
23+
super(throwable);
24+
}
25+
26+
public OctaneSDKGeneralException(String message) {
27+
super(message);
28+
}
29+
30+
public OctaneSDKGeneralException(String message, Throwable throwable) {
31+
super(message, throwable);
32+
}
33+
}

integrations-sdk/src/main/java/com/hp/octane/integrations/services/configuration/ConfigurationServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.hp.octane.integrations.dto.connectivity.HttpMethod;
2727
import com.hp.octane.integrations.dto.connectivity.OctaneRequest;
2828
import com.hp.octane.integrations.dto.connectivity.OctaneResponse;
29+
import com.hp.octane.integrations.util.CIPluginSDKUtils;
2930
import org.apache.http.HttpStatus;
3031
import org.apache.http.NameValuePair;
3132
import org.apache.http.client.utils.URLEncodedUtils;
@@ -118,7 +119,8 @@ public OctaneResponse validateConfiguration(OctaneConfiguration configuration) t
118119
throw new IllegalArgumentException("configuration " + configuration + " is not valid");
119120
}
120121

121-
CIProxyConfiguration proxyConfiguration = pluginServices.getProxyConfiguration(configuration.getUrl());
122+
String octaneHost = CIPluginSDKUtils.extractHostFromURL(configuration.getUrl());
123+
CIProxyConfiguration proxyConfiguration = pluginServices.getProxyConfiguration(octaneHost);
122124
RestClient restClientImpl = restService.createClient(proxyConfiguration);
123125
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class)
124126
.setMethod(HttpMethod.GET)

integrations-sdk/src/main/java/com/hp/octane/integrations/services/rest/RestClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ private HttpClientContext createHttpContext(String requestUrl, boolean isLoginRe
266266
}
267267

268268
// configure proxy if needed
269-
CIProxyConfiguration proxyConfiguration = pluginServices.getProxyConfiguration(requestUrl);
269+
String requestHost = CIPluginSDKUtils.extractHostFromURL(requestUrl);
270+
CIProxyConfiguration proxyConfiguration = pluginServices.getProxyConfiguration(requestHost);
270271
if (proxyConfiguration != null) {
271272
logger.debug("proxy will be used with the following setup: " + proxyConfiguration);
272273
HttpHost proxyHost = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort());

integrations-sdk/src/main/java/com/hp/octane/integrations/util/CIPluginSDKUtils.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
package com.hp.octane.integrations.util;
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.hp.octane.integrations.exceptions.OctaneSDKGeneralException;
2021
import org.apache.logging.log4j.LogManager;
2122
import org.apache.logging.log4j.Logger;
2223

2324
import java.io.UnsupportedEncodingException;
25+
import java.net.MalformedURLException;
26+
import java.net.URL;
2427
import java.net.URLEncoder;
2528
import java.nio.charset.StandardCharsets;
2629
import java.util.LinkedList;
@@ -47,15 +50,35 @@ public static void doWait(long period) {
4750
}
4851
}
4952

50-
public static boolean isNonProxyHost(String targetHost, String nonProxyHostsStr) {
51-
boolean noProxyHost = false;
52-
for (Pattern pattern : getNoProxyHostPatterns(nonProxyHostsStr)) {
53-
if (pattern.matcher(targetHost).find()) {
54-
noProxyHost = true;
55-
break;
56-
}
53+
// [YG] should be removed from here and implemented with the relevant plugin, as this implementation is specific to some plugin (Bamboo or TeamCity, i presume)
54+
// @Deprecated
55+
// public static boolean isNonProxyHost(String targetHost, String nonProxyHostsStr) {
56+
// boolean noProxyHost = false;
57+
// List<Pattern> noProxyHosts = new LinkedList<>();
58+
// if (nonProxyHostsStr != null && !nonProxyHostsStr.isEmpty()) {
59+
// String[] hosts = nonProxyHostsStr.split("[ \t\n,|]+");
60+
// for (String host : hosts) {
61+
// if (!host.isEmpty()) {
62+
// noProxyHosts.add(Pattern.compile(host.replace(".", "\\.").replace("*", ".*")));
63+
// }
64+
// }
65+
// }
66+
// for (Pattern pattern : noProxyHosts) {
67+
// if (pattern.matcher(targetHost).find()) {
68+
// noProxyHost = true;
69+
// break;
70+
// }
71+
// }
72+
// return noProxyHost;
73+
// }
74+
75+
public static String extractHostFromURL(String input) {
76+
try {
77+
URL url = new URL(input);
78+
return url.getHost();
79+
} catch (MalformedURLException murle) {
80+
throw new OctaneSDKGeneralException("failed to extract host from URL '" + input + "'", murle);
5781
}
58-
return noProxyHost;
5982
}
6083

6184
public static String urlEncodePathParam(String input) {
@@ -77,18 +100,5 @@ public static String urlEncodeQueryParam(String input) {
77100
}
78101
return result;
79102
}
80-
81-
private static List<Pattern> getNoProxyHostPatterns(String noProxyHost) {
82-
List<Pattern> result = new LinkedList<>();
83-
if (noProxyHost != null && !noProxyHost.isEmpty()) {
84-
String[] hosts = noProxyHost.split("[ \t\n,|]+");
85-
for (String host : hosts) {
86-
if (!host.isEmpty()) {
87-
result.add(Pattern.compile(host.replace(".", "\\.").replace("*", ".*")));
88-
}
89-
}
90-
}
91-
return result;
92-
}
93103
}
94104

integrations-sdk/src/main/java/com/hp/octane/integrations/util/SdkHttpStatus.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)