Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.ericsson</groupId>
<artifactId>eiffel-intelligence</artifactId>
<version>2.2.3</version>
<version>2.2.4</version>
<packaging>war</packaging>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ public JsonNode fetchJenkinsCrumb(String encoding, String url)
*/
private URL buildJenkinsCrumbUrl(String url) throws MalformedURLException {
String baseUrl = urlParser.extractBaseUrl(url);
URL jenkinsCrumbUrl = new URL(baseUrl + JENKINS_CRUMB_ENDPOINT);
String contextPath = urlParser.extractContextPath(url).split("/")[1];
URL jenkinsCrumbUrl;
if (contextPath.equals("job")) {
jenkinsCrumbUrl = new URL(baseUrl + JENKINS_CRUMB_ENDPOINT);
} else {
String jenkinsBaseUrl = String.format("%s/%s", baseUrl, contextPath);
jenkinsCrumbUrl = new URL(jenkinsBaseUrl + JENKINS_CRUMB_ENDPOINT);
}
return jenkinsCrumbUrl;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/ericsson/ei/notifications/UrlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public String extractBaseUrl(String url) throws MalformedURLException {
* @throws MalformedURLException
* @throws URISyntaxException
*/
private String extractContextPath(String url) throws MalformedURLException {
public String extractContextPath(String url) throws MalformedURLException {
URL absoluteUrl = new URL(url);
String contextPath = absoluteUrl.getPath();
return contextPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class JenkinsCrumbTest {

private static final String URL = "http://www.somehot.com/some-endpoint/";
private static final String BASE_URL = "http://www.somehot.com";
private static final String JENKINS_CRUMB_URL = "http://www.somehot.com/crumbIssuer/api/json";
private static final String CONTEXT_PATH = "/some-endpoint";
private static final String JENKINS_CRUMB_URL = "http://www.somehot.com/some-endpoint/crumbIssuer/api/json";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";

Expand All @@ -65,6 +66,7 @@ public class JenkinsCrumbTest {
public void beforeTests() throws IOException {
encoding = Base64.getEncoder().encodeToString((USERNAME + ":" + PASSWORD).getBytes());
when(urlParser.extractBaseUrl(URL)).thenReturn(BASE_URL);
when(urlParser.extractContextPath(URL)).thenReturn(CONTEXT_PATH);

headers.add("Authorization", "Basic " + encoding);
headers.setContentType(MediaType.APPLICATION_JSON);
Expand Down