ASTERIXDB-1804: update AsterixDB servlets
Change-Id: Id48a4753775a19094b28876ef3544bda989f918d
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1519
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
index 395365a..40c7f2c 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
@@ -83,7 +83,8 @@
this.componentProvider = componentProvider;
}
- public void doPost(IServletRequest request, IServletResponse response) {
+ @Override
+ protected void post(IServletRequest request, IServletResponse response) {
// Query language
ILangCompilationProvider compilationProvider = "AQL".equals(request.getParameter("query-language"))
? aqlCompilationProvider : sqlppCompilationProvider;
@@ -157,7 +158,8 @@
}
}
- public void doGet(IServletRequest request, IServletResponse response) {
+ @Override
+ protected void get(IServletRequest request, IServletResponse response) {
String resourcePath = null;
String requestURI = request.getHttpRequest().uri();
@@ -226,17 +228,4 @@
private static boolean isSet(String requestParameter) {
return requestParameter != null && "true".equals(requestParameter);
}
-
- @Override
- public void handle(IServletRequest request, IServletResponse response) {
- response.setStatus(HttpResponseStatus.OK);
- if (request.getHttpRequest().method() == HttpMethod.GET) {
- doGet(request, response);
- } else if (request.getHttpRequest().method() == HttpMethod.POST) {
- doPost(request, response);
- } else {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- }
- }
-
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
index 71559b1..1d37baf 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
@@ -65,7 +65,8 @@
super(ctx, paths);
}
- protected void getUnsafe(IServletRequest request, IServletResponse response) throws IOException {
+ @Override
+ protected void get(IServletRequest request, IServletResponse response) throws IOException {
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
PrintWriter responseWriter = response.writer();
try {
@@ -173,18 +174,4 @@
}
return clusterURL;
}
-
- @Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.GET) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
- try {
- getUnsafe(request, response);
- } catch (IOException e) {
- LOGGER.log(Level.WARNING, "Unhandled IOException thrown from " + getClass().getName() + " get impl", e);
- }
- }
-
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
index 69f5db4..776f884 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java
@@ -46,7 +46,7 @@
}
@Override
- protected void getUnsafe(IServletRequest request, IServletResponse response) throws IOException {
+ protected void get(IServletRequest request, IServletResponse response) throws IOException {
PrintWriter responseWriter = response.writer();
IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
try {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
index a6c0783..cd632cab 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
@@ -65,11 +65,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.GET) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void get(IServletRequest request, IServletResponse response) {
response.setStatus(HttpResponseStatus.OK);
try {
HttpUtil.setContentType(response, HttpUtil.ContentType.TEXT_HTML, HttpUtil.Encoding.UTF8);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
index 4d6f641..366007d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
@@ -55,7 +55,7 @@
}
@Override
- protected void getUnsafe(IServletRequest request, IServletResponse response) throws IOException {
+ protected void get(IServletRequest request, IServletResponse response) throws IOException {
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
PrintWriter responseWriter = response.writer();
ObjectNode json;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FeedServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FeedServlet.java
index 7831674..0b4a088 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FeedServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FeedServlet.java
@@ -46,7 +46,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
+ protected void get(IServletRequest request, IServletResponse response) {
try {
response.setStatus(HttpResponseStatus.OK);
String resourcePath;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
index 30718cf..ca0888b 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
@@ -54,7 +54,7 @@
}
@Override
- protected void getUnsafe(IServletRequest request, IServletResponse response) throws IOException {
+ protected void get(IServletRequest request, IServletResponse response) throws IOException {
PrintWriter responseWriter = response.writer();
IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
try {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryResultApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryResultApiServlet.java
index 522fd29..dfc8a8f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryResultApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryResultApiServlet.java
@@ -59,11 +59,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.GET) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void get(IServletRequest request, IServletResponse response) {
response.setStatus(HttpResponseStatus.OK);
// TODO this seems wrong ...
try {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 3c7a1a1..c0a38e8 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -85,11 +85,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.POST) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void post(IServletRequest request, IServletResponse response) {
try {
handleRequest(getRequestParameters(request), response);
} catch (IOException e) {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
index 075615e..5a62eaa 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
@@ -53,11 +53,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.GET) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void get(IServletRequest request, IServletResponse response) {
response.setStatus(HttpResponseStatus.OK);
try {
HttpUtil.setContentType(response, HttpUtil.ContentType.TEXT_HTML, HttpUtil.Encoding.UTF8);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryWebInterfaceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryWebInterfaceServlet.java
index 8a41fc1..b839b26 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryWebInterfaceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryWebInterfaceServlet.java
@@ -48,23 +48,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- try {
- if (request.getHttpRequest().method() == HttpMethod.GET) {
- doGet(request, response);
- } else if (request.getHttpRequest().method() == HttpMethod.POST) {
- doPost(response);
- } else {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- }
- } catch (IOException e) {
- LOGGER.log(Level.WARNING, "Failure setting content type", e);
- response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- private void doGet(IServletRequest request, IServletResponse response) throws IOException {
+ protected void get(IServletRequest request, IServletResponse response) throws IOException {
String resourcePath = null;
String requestURI = request.getHttpRequest().uri();
response.setStatus(HttpResponseStatus.OK);
@@ -105,7 +89,8 @@
}
}
- private void doPost(IServletResponse response) throws IOException {
+ @Override
+ protected void post(IServletRequest request, IServletResponse response) throws IOException {
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
ExternalProperties externalProperties = AppContextInfo.INSTANCE.getExternalProperties();
response.setStatus(HttpResponseStatus.OK);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/RestApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/RestApiServlet.java
index d1ae95d..bdc9d62 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/RestApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/RestApiServlet.java
@@ -157,7 +157,16 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
+ protected void get(IServletRequest request, IServletResponse response) {
+ getOrPost(request, response);
+ }
+
+ @Override
+ protected void post(IServletRequest request, IServletResponse response) {
+ getOrPost(request, response);
+ }
+
+ private void getOrPost(IServletRequest request, IServletResponse response) {
try {
String query = query(request);
// enable cross-origin resource sharing
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ShutdownApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ShutdownApiServlet.java
index d9dc424..9050907 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ShutdownApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ShutdownApiServlet.java
@@ -54,11 +54,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.POST) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void post(IServletRequest request, IServletResponse response) {
IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
boolean terminateNCServices = "true".equalsIgnoreCase(request.getParameter("all"));
Thread t = new Thread(() -> {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java
index 62b85cd..91bebfe 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java
@@ -47,11 +47,7 @@
}
@Override
- public void handle(IServletRequest request, IServletResponse response) {
- if (request.getHttpRequest().method() != HttpMethod.GET) {
- response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- return;
- }
+ protected void get(IServletRequest request, IServletResponse response) {
response.setStatus(HttpResponseStatus.OK);
AppContextInfo props = (AppContextInfo) ctx.get(ASTERIX_BUILD_PROP_ATTR);
Map<String, String> buildProperties = props.getBuildProperties().getAllProps();
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/server/RSSFeedServlet.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/server/RSSFeedServlet.java
index 2cf47f9..f79f5e9 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/server/RSSFeedServlet.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/server/RSSFeedServlet.java
@@ -61,7 +61,8 @@
defaultFeedType = (defaultFeedType != null) ? defaultFeedType : "atom_0.3";
}
- protected void doGet(IServletRequest req, IServletResponse res) throws IOException {
+ @Override
+ protected void get(IServletRequest req, IServletResponse res) throws IOException {
try {
SyndFeed feed = getFeed(req);
String feedType = req.getParameter(FEED_TYPE);
@@ -78,21 +79,6 @@
}
}
- @Override
- public void handle(IServletRequest req, IServletResponse res) {
- if (req.getHttpRequest().method() == HttpMethod.GET) {
- try {
- doGet(req, res);
- } catch (IOException e) {
- // Servlet methods should not throw exceptions
- // http://cwe.mitre.org/data/definitions/600.html
- GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
- }
- } else {
- res.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED);
- }
- }
-
protected SyndFeed getFeed(IServletRequest req) throws IOException, FeedException, ParseException {
SyndFeed feed = new SyndFeedImpl();
feed.setTitle("Sample Feed (created with ROME)");