refactor(gateway-vertx) Change public-endpoint feature to be more consistent with Servlet.
MODIFY
gateway/engine/vertx-polling/src/main/java/io/apiman/gateway/engine/vertx/polling/URILoadingRegistry.java
gateway/engine/vertx-polling/src/main/java/io/apiman/gateway/engine/vertx/polling/URILoadingRegistry.java
@@ -105,14 +105,14 @@ public class URILoadingRegistry extends InMemoryRegistry implements AsyncInitial
public static void reloadData(IAsyncHandler<Void> doneHandler) {
synchronized(URILoadingRegistry.class) {
if (instance == null) {
- doneHandler.handle(null);
+ doneHandler.handle((Void) null);
+ return;
}
Map<URILoadingRegistry, IAsyncResultHandler<Void>> regs = instance.handlers;
Vertx vertx = instance.vertx;
URI uri = instance.uri;
Map<String, String> config = instance.config;
AtomicInteger ctr = new AtomicInteger(regs.size());
-
OneShotURILoader newLoader = new OneShotURILoader(vertx, uri, config);
regs.entrySet().stream().forEach(pair -> {

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/api/ApiResourceImpl.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/api/ApiResourceImpl.java
@@ -34,6 +34,7 @@ import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
/**
@@ -128,32 +129,44 @@ public class ApiResourceImpl implements IApiResource, IRouteBuilder {
retire(orgId, apiId, ver);
}
- // TODO refactor to look up apiId in engine, we can then determine more accurately what the URL scheme should be.
@Override
public ApiEndpoint getApiEndpoint(String organizationId, String apiId, String version)
throws NotAuthorizedException {
String scheme = apimanConfig.preferSecure() ? "https" : "http";
int port = apimanConfig.getPort(scheme);
- StringBuilder sb = new StringBuilder(100);
- sb.append(scheme + "://");
+ String host = this.host;
+ String path = "";
+ // If endpoint was manually specified
+ if (apimanConfig.getPublicEndpoint() != null) {
+ URI publicEndpoint = URI.create(apimanConfig.getPublicEndpoint());
- if (apimanConfig.getEndpoint() == null) {
- sb.append(host);
- } else {
- sb.append(apimanConfig.getEndpoint());
+ if (publicEndpoint.getPort() != -1) {
+ port = publicEndpoint.getPort();
+ }
+ if (publicEndpoint.getScheme() != null && !publicEndpoint.getScheme().isEmpty()) {
+ scheme = publicEndpoint.getScheme();
+ }
+ if (publicEndpoint.getPath() != null && !publicEndpoint.getPath().isEmpty()) {
+ path = publicEndpoint.getPath();
+ }
+ if (publicEndpoint.getHost() != null && !publicEndpoint.getHost().isEmpty()) {
+ host = publicEndpoint.getHost();
+ }
}
+ String endpoint = scheme + "://" + host;
if (port != 443 && port != 80)
- sb.append(":" + port + "/");
- sb.append(SimpleStringUtils.join("/", organizationId, apiId, version));
+ endpoint += ":" + port + "/";
+ endpoint += path;
+ endpoint += SimpleStringUtils.join("/", organizationId, apiId, version);
- ApiEndpoint endpoint = new ApiEndpoint();
- endpoint.setEndpoint(sb.toString());
- return endpoint;
+ ApiEndpoint endpointObj = new ApiEndpoint();
+ endpointObj.setEndpoint(endpoint);
+ return endpointObj;
}
public void getApiEndpoint(RoutingContext routingContext) {
- if (apimanConfig.getEndpoint() == null) {
+ if (apimanConfig.getPublicEndpoint() == null) {
try {
host = new URL(routingContext.request().absoluteURI()).getHost();
} catch (MalformedURLException e) {

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
@@ -69,7 +69,7 @@ public class VertxEngineConfig implements IEngineConfig {
private static final String VERTICLE_COUNT = "count";
private static final String GATEWAY_HOSTNAME = "hostname";
- private static final String GATEWAY_ENDPOINT = "endpoint";
+ private static final String GATEWAY_PUBLIC_ENDPOINT = "publicEndpoint";
private static final String GATEWAY_PREFER_SECURE = "preferSecure";
private static final String API_AUTH = "auth";
@@ -244,8 +244,8 @@ public class VertxEngineConfig implements IEngineConfig {
return stringConfigWithDefault(GATEWAY_HOSTNAME, "localhost");
}
- public String getEndpoint() {
- return config.getString(GATEWAY_ENDPOINT);
+ public String getPublicEndpoint() {
+ return config.getString(GATEWAY_PUBLIC_ENDPOINT);
}
public Boolean preferSecure() {

refactor(gateway-vertx) Change public-endpoint feature to be more consistent with Servlet.