Skip to content

Commit f812428

Browse files
author
rathnapandi
committed
- Fix issue #568
1 parent e2a2fac commit f812428

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

modules/apim-adapter/src/main/java/com/axway/apim/lib/CoreParameters.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static Mode valueOfDefault(String key) {
7474
private boolean disableCompression;
7575
private boolean overrideSpecBasePath;
7676
private String customHeaders;
77+
private String apiBasepath;
7778

7879
public CoreParameters() {
7980
instance = this;
@@ -143,6 +144,9 @@ public int getPort2() {
143144

144145

145146
public String getApiBasepath() {
147+
if (apiManagerUrl != null) {
148+
return apiBasepath;
149+
}
146150
return DEFAULT_API_BASEPATH;
147151
}
148152

@@ -247,6 +251,7 @@ public void setAPIManagerURL(String apiManagerUrl) throws AppException {
247251
if (apiManagerUrl == null) return;
248252
try {
249253
this.apiManagerUrl = new URI(apiManagerUrl);
254+
this.apiBasepath = this.apiManagerUrl.getPath();
250255
} catch (URISyntaxException e) {
251256
throw new AppException("Error parsing up API-Manager URL: " + apiManagerUrl, ErrorCode.INVALID_PARAMETER, e);
252257
}
@@ -257,7 +262,13 @@ public URI getAPIManagerURL() throws AppException {
257262
if (apiManagerUrl == null) {
258263
return new URI("https://" + this.getHostname2() + ":" + this.getPort2());
259264
}
260-
return apiManagerUrl;
265+
URI uri = apiManagerUrl.resolve("/");
266+
String uriStr = uri.toString();
267+
if (uriStr.endsWith("/")) {
268+
return new URI(uriStr.substring(0, uriStr.length() - 1));
269+
}
270+
return uri;
271+
261272
} catch (URISyntaxException e) {
262273
throw new AppException("Error setting up API-Manager URL", ErrorCode.INVALID_PARAMETER, e);
263274
}

modules/apim-adapter/src/test/java/com/axway/lib/CoreParametersTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import com.axway.apim.adapter.CacheType;
88
import com.axway.apim.lib.CoreParameters;
99

10+
import java.net.URI;
11+
import java.net.URISyntaxException;
12+
1013
public class CoreParametersTest {
1114

1215
@Test
@@ -137,4 +140,32 @@ public void testIgnoreQuota(){
137140
params.setIgnoreQuotas(true);
138141
Assert.assertTrue(params.isIgnoreQuotas());
139142
}
143+
144+
@Test
145+
public void testCustomBasepath() throws AppException {
146+
CoreParameters params = new CoreParameters();
147+
params.setAPIManagerURL("https://localhost:8075/api/portal/v1.4/test");
148+
Assert.assertEquals(params.getApiBasepath(), "/api/portal/v1.4/test");
149+
}
150+
151+
@Test
152+
public void testDefaultBasepath() {
153+
CoreParameters params = new CoreParameters();
154+
Assert.assertEquals(params.getApiBasepath(), "/api/portal/v1.4");
155+
}
156+
157+
@Test
158+
public void testApiManagerUrl() throws AppException, URISyntaxException {
159+
CoreParameters params = new CoreParameters();
160+
params.setAPIManagerURL("https://localhost:8075/api/portal/v1.4/test");
161+
Assert.assertEquals(params.getAPIManagerURL(), new URI("https://localhost:8075"));
162+
}
163+
164+
@Test
165+
public void testApiManagerUrlWithoutBasepath() throws AppException, URISyntaxException {
166+
CoreParameters params = new CoreParameters();
167+
params.setAPIManagerURL("https://localhost:8075");
168+
Assert.assertEquals(params.getAPIManagerURL(), new URI("https://localhost:8075"));
169+
}
170+
140171
}

0 commit comments

Comments
 (0)