Till Westmann has submitted this change and it was merged. Change subject: drop support for HTTP GET ......................................................................
drop support for HTTP GET remove QueryServiceServlet.doGet Change-Id: I5f922ea1524ba1f07efcb081769b2bbbfeabe1f2 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1088 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Michael Blow <[email protected]> --- M asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java M asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java 2 files changed, 31 insertions(+), 33 deletions(-) Approvals: Michael Blow: Looks good to me, approved Jenkins: Verified; No violations found; Verified diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java index d3507d8..90e8adf 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java @@ -384,18 +384,6 @@ } } - @Override - public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - String query = request.getParameter(Parameter.STATEMENT.str()); - try { - handleRequest(request, response, query); - } 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); - } - } - private void handleRequest(HttpServletRequest request, HttpServletResponse response, String query) throws IOException { long elapsedStart = System.nanoTime(); diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java index 6bfbd64..45a5fc4 100644 --- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java +++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java @@ -44,10 +44,10 @@ import org.apache.asterix.test.server.ITestServer; import org.apache.asterix.test.server.TestServerProvider; import org.apache.asterix.testframework.context.TestCaseContext; -import org.apache.asterix.testframework.context.TestCaseContext.OutputFormat; import org.apache.asterix.testframework.context.TestFileContext; -import org.apache.asterix.testframework.xml.TestCase.CompilationUnit; +import org.apache.asterix.testframework.context.TestCaseContext.OutputFormat; import org.apache.asterix.testframework.xml.TestGroup; +import org.apache.asterix.testframework.xml.TestCase.CompilationUnit; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.http.HttpResponse; @@ -280,8 +280,8 @@ return httpResponse; } - public InputStream executeQuery(String str, OutputFormat fmt, String url, - List<CompilationUnit.Parameter> params) throws Exception { + public InputStream executeQuery(String str, OutputFormat fmt, String url, List<CompilationUnit.Parameter> params) + throws Exception { HttpUriRequest method = constructHttpMethod(str, url, "query", false, params); // Set accepted output response type method.setHeader("Accept", fmt.mimeType()); @@ -292,7 +292,7 @@ public InputStream executeQueryService(String str, OutputFormat fmt, String url, List<CompilationUnit.Parameter> params) throws Exception { setFormatParam(params, fmt); - HttpUriRequest method = constructHttpMethod(str, url, "statement", true, params); + HttpUriRequest method = constructPostMethod(str, url, "statement", true, params); // Set accepted output response type method.setHeader("Accept", OutputFormat.CLEAN_JSON.mimeType()); HttpResponse response = executeHttpRequest(method); @@ -315,28 +315,38 @@ } } - private HttpUriRequest constructHttpMethod(String statement, String endpoint, String stmtParam, boolean postStmtAsParam, - List<CompilationUnit.Parameter> otherParams) { - RequestBuilder builder; + private HttpUriRequest constructHttpMethod(String statement, String endpoint, String stmtParam, + boolean postStmtAsParam, List<CompilationUnit.Parameter> otherParams) { if (statement.length() + endpoint.length() < MAX_URL_LENGTH) { // Use GET for small-ish queries - builder = RequestBuilder.get(endpoint); - builder.addParameter(stmtParam, statement); + return constructGetMethod(statement, endpoint, stmtParam, otherParams); + } else { + // Use POST for bigger ones to avoid 413 FULL_HEAD + return constructPostMethod(statement, endpoint, stmtParam, postStmtAsParam, otherParams); + } + } + + private HttpUriRequest constructGetMethod(String statement, String endpoint, String stmtParam, + List<CompilationUnit.Parameter> otherParams) { + RequestBuilder builder = RequestBuilder.get(endpoint).addParameter(stmtParam, statement); + for (CompilationUnit.Parameter param : otherParams) { + builder.addParameter(param.getName(), param.getValue()); + } + builder.setCharset(StandardCharsets.UTF_8); + return builder.build(); + } + + private HttpUriRequest constructPostMethod(String statement, String endpoint, String stmtParam, + boolean postStmtAsParam, List<CompilationUnit.Parameter> otherParams) { + RequestBuilder builder = RequestBuilder.post(endpoint); + if (postStmtAsParam) { for (CompilationUnit.Parameter param : otherParams) { builder.addParameter(param.getName(), param.getValue()); } + builder.addParameter(stmtParam, statement); } else { - // Use POST for bigger ones to avoid 413 FULL_HEAD - builder = RequestBuilder.post(endpoint); - if (postStmtAsParam) { - for (CompilationUnit.Parameter param : otherParams) { - builder.addParameter(param.getName(), param.getValue()); - } - builder.addParameter("statement", statement); - } else { - // this seems pretty bad - we should probably fix the API and not the client - builder.setEntity(new StringEntity(statement, StandardCharsets.UTF_8)); - } + // this seems pretty bad - we should probably fix the API and not the client + builder.setEntity(new StringEntity(statement, StandardCharsets.UTF_8)); } builder.setCharset(StandardCharsets.UTF_8); return builder.build(); -- To view, visit https://asterix-gerrit.ics.uci.edu/1088 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5f922ea1524ba1f07efcb081769b2bbbfeabe1f2 Gerrit-PatchSet: 4 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Till Westmann <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]> Gerrit-Reviewer: Yingyi Bu <[email protected]>
