fix(platform-vertx): Fix NPE where HTTP reasonCode or Exception messages are not set.
fix(platform-vertx): Ensure that Host header is not suppressed before the connector
Resolves
MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPolicyErrorWriter.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPolicyErrorWriter.java
@@ -60,8 +60,8 @@ public class DefaultPolicyErrorWriter implements IPolicyErrorWriter {
if (request != null && request.getApi() != null && "xml".equals(request.getApi().getEndpointContentType())) {
isXml = true;
}
-
- response.setHeader("X-Gateway-Error", error.getMessage());
+ String message = (error.getMessage() == null) ? "" : error.getMessage(); // TODO get and/or print ultimate cause?
+ response.setHeader("X-Gateway-Error", message);
response.setStatusCode(500);
EngineErrorResponse eer = createErrorResponse(error);

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/connector/HttpConnector.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/connector/HttpConnector.java
@@ -49,7 +49,7 @@ import io.vertx.core.logging.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Set;
@@ -65,15 +65,17 @@ import java.util.Set;
@SuppressWarnings("nls")
class HttpConnector implements IApiConnectionResponse, IApiConnection {
- private static final Set<String> SUPPRESSED_HEADERS = new HashSet<>();
+ private static final Set<String> SUPPRESSED_REQUEST_HEADERS = new LinkedHashSet<>();
+ private static final Set<String> SUPPRESSED_RESPONSE_HEADERS = new LinkedHashSet<>();
+
static {
- SUPPRESSED_HEADERS.add("Transfer-Encoding");
- SUPPRESSED_HEADERS.add("X-API-Key");
- SUPPRESSED_HEADERS.add("Host");
+ SUPPRESSED_REQUEST_HEADERS.add("X-API-Key");
+ SUPPRESSED_REQUEST_HEADERS.add("Host");
+
+ SUPPRESSED_RESPONSE_HEADERS.add("Connection");
}
private Logger logger = LoggerFactory.getLogger(this.getClass());
-
private ApiRequest apiRequest;
private ApiResponse apiResponse;
@@ -171,7 +173,7 @@ class HttpConnector implements IApiConnectionResponse, IApiConnection {
// Pause until we're given permission to xfer the response.
vxClientResponse.pause();
- apiResponse = HttpApiFactory.buildResponse(vxClientResponse, SUPPRESSED_HEADERS);
+ apiResponse = HttpApiFactory.buildResponse(vxClientResponse, SUPPRESSED_RESPONSE_HEADERS);
vxClientResponse.handler((Handler<Buffer>) chunk -> {
bodyHandler.handle(new VertxApimanBuffer(chunk));
@@ -195,7 +197,12 @@ class HttpConnector implements IApiConnectionResponse, IApiConnection {
clientRequest.setChunked(true);
}
- apiRequest.getHeaders().forEach(e -> clientRequest.headers().add(e.getKey(), e.getValue()));
+ apiRequest.getHeaders()
+ .forEach(e -> {
+ if (!SUPPRESSED_REQUEST_HEADERS.contains(e.getKey())) {
+ clientRequest.headers().add(e.getKey(), e.getValue());
+ }
+ });
addMandatoryRequestHeaders(clientRequest.headers());

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/http/HttpApiFactory.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/http/HttpApiFactory.java
@@ -45,7 +45,7 @@ public class HttpApiFactory {
private final static Set<String> IGNORESET = new HashSet<>();
static {
IGNORESET.add(ApimanPathUtils.X_API_VERSION_HEADER);
- IGNORESET.add("Host");
+ //IGNORESET.add("Host");
}
private static IApiRequestPathParser requestPathParser;
@@ -57,7 +57,7 @@ public class HttpApiFactory {
public static ApiResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) {
ApiResponse apimanResponse = new ApiResponse();
apimanResponse.setCode(response.statusCode());
- apimanResponse.setMessage(response.statusMessage());
+ apimanResponse.setMessage(response.statusMessage() == null ? "" : response.statusMessage());
multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders);
return apimanResponse;
}
@@ -69,7 +69,7 @@ public class HttpApiFactory {
}
});
httpServerResponse.setStatusCode(amanResponse.getCode());
- httpServerResponse.setStatusMessage(amanResponse.getMessage());
+ httpServerResponse.setStatusMessage(amanResponse.getMessage() == null ? "" : amanResponse.getMessage());
}
public static ApiRequest buildRequest(HttpServerRequest req, boolean isTransportSecure) {

fix(platform-vertx): Fix NPE where HTTP reasonCode or Exception messages are not set.

fix(platform-vertx): Ensure that Host header is not suppressed before the connector

Resolves APIMAN-1271