[NO ISSUE][OTH] Add util method to get request http scheme
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Add util method to get request http scheme.
- Allow exceptions to be thrown from servletNotFound.
Change-Id: I85e88223a0ec3291be4423cf5dc146d7d7d09903
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11224
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServerHandler.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServerHandler.java
index 77d3493..a7ace7a 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServerHandler.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServerHandler.java
@@ -18,8 +18,6 @@
*/
package org.apache.hyracks.http.server;
-import static org.apache.hyracks.http.server.utils.HttpUtil.X_FORWARDED_PROTO;
-
import java.io.IOException;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
@@ -143,9 +141,7 @@
private void submit(ChannelHandlerContext ctx, IServlet servlet, FullHttpRequest request) throws IOException {
IServletRequest servletRequest;
try {
- HttpScheme scheme =
- server.getScheme() == HttpScheme.HTTPS || "https".equals(request.headers().get(X_FORWARDED_PROTO))
- ? HttpScheme.HTTPS : HttpScheme.HTTP;
+ HttpScheme scheme = HttpUtil.getScheme(server, request);
servletRequest = createServletRequest(ctx, request, scheme);
} catch (IllegalArgumentException e) {
LOGGER.log(Level.WARN, "Failure Decoding Request", e);
@@ -166,7 +162,7 @@
}
}
- protected void handleServletNotFound(ChannelHandlerContext ctx, FullHttpRequest request) {
+ protected void handleServletNotFound(ChannelHandlerContext ctx, FullHttpRequest request) throws IOException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No servlet for " + request.uri());
}
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/utils/HttpUtil.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/utils/HttpUtil.java
index 4c0942b..c61e0d2 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/utils/HttpUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/utils/HttpUtil.java
@@ -43,6 +43,7 @@
import org.apache.hyracks.http.api.IServletResponse;
import org.apache.hyracks.http.server.BaseRequest;
import org.apache.hyracks.http.server.FormUrlEncodedRequest;
+import org.apache.hyracks.http.server.HttpServer;
import org.apache.hyracks.util.ThrowingConsumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -230,6 +231,11 @@
}
}
+ public static HttpScheme getScheme(HttpServer server, FullHttpRequest request) {
+ return server.getScheme() == HttpScheme.HTTPS || "https".equals(request.headers().get(X_FORWARDED_PROTO))
+ ? HttpScheme.HTTPS : HttpScheme.HTTP;
+ }
+
public static class ContentType {
public static final String ADM = "adm";
public static final String JSON = "json";