Repository: zeppelin Updated Branches: refs/heads/master 88c257a09 -> 47ac1d41e
[ZEPPELIN-728] Can't POST interpreter setting (CorsFilter?) ### What is this PR for? This handles the NPE when the input json is empty for the interpreter setting POST request. ### What type of PR is it? Bug Fix ### Todos NA ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-728 ### How should this be tested? When empty json is sent for interpreter setting POST request, 400 status code should be returned. ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Kavin <[email protected]> Author: Kavin Kumar <[email protected]> Closes #1345 from kavinkumarks/zeppelin-728-fix-NPE-intepreter-setting-post and squashes the following commits: 7ab1117 [Kavin] Updated the error codes in the REST API doc. 3397fb0 [Kavin Kumar] Handled NPE when the json is empty for interpreter setting POST request and corrected the json in the REST API doc. Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/47ac1d41 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/47ac1d41 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/47ac1d41 Branch: refs/heads/master Commit: 47ac1d41e7ec18a16c6144460fbbc35877d71a11 Parents: 88c257a Author: Kavin <[email protected]> Authored: Tue Aug 23 18:05:36 2016 +0530 Committer: Jongyoul Lee <[email protected]> Committed: Wed Aug 24 12:54:45 2016 +0900 ---------------------------------------------------------------------- docs/rest-api/rest-interpreter.md | 21 +++++++++++++++----- .../zeppelin/rest/InterpreterRestApi.java | 3 +++ .../zeppelin/rest/InterpreterRestApiTest.java | 9 +++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/47ac1d41/docs/rest-api/rest-interpreter.md ---------------------------------------------------------------------- diff --git a/docs/rest-api/rest-interpreter.md b/docs/rest-api/rest-interpreter.md index 734dbd9..75b0d90 100644 --- a/docs/rest-api/rest-interpreter.md +++ b/docs/rest-api/rest-interpreter.md @@ -198,7 +198,10 @@ The role of registered interpreters, settings and interpreters group are describ </tr> <tr> <td>Fail code</td> - <td> 500 </td> + <td> + 400 if the input json is empty <br/> + 500 for any other errors + </td> </tr> <tr> <td>Sample JSON input</td> @@ -219,7 +222,9 @@ The role of registered interpreters, settings and interpreters group are describ "dependencies": [ { "groupArtifactVersion": "groupId:artifactId:version", - "exclusions": "groupId:artifactId" + "exclusions": [ + "groupId:artifactId" + ] } ] } @@ -249,7 +254,9 @@ The role of registered interpreters, settings and interpreters group are describ "dependencies": [ { "groupArtifactVersion": "groupId:artifactId:version", - "exclusions": "groupId:artifactId" + "exclusions": [ + "groupId:artifactId" + ] } ] } @@ -298,7 +305,9 @@ The role of registered interpreters, settings and interpreters group are describ "dependencies": [ { "groupArtifactVersion": "groupId:artifactId:version", - "exclusions": "groupId:artifactId" + "exclusions": [ + "groupId:artifactId" + ] } ] } @@ -328,7 +337,9 @@ The role of registered interpreters, settings and interpreters group are describ "dependencies": [ { "groupArtifactVersion": "groupId:artifactId:version", - "exclusions": "groupId:artifactId" + "exclusions": [ + "groupId:artifactId" + ] } ] } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/47ac1d41/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index f77aac0..6025b52 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -90,6 +90,9 @@ public class InterpreterRestApi { try { NewInterpreterSettingRequest request = gson.fromJson(message, NewInterpreterSettingRequest.class); + if (request == null) { + return new JsonResponse<>(Status.BAD_REQUEST).build(); + } Properties p = new Properties(); p.putAll(request.getProperties()); InterpreterSetting interpreterSetting = interpreterFactory http://git-wip-us.apache.org/repos/asf/zeppelin/blob/47ac1d41/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index e92432f..1ed3567 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -120,6 +120,15 @@ public class InterpreterRestApiTest extends AbstractTestRestApi { } @Test + public void testSettingsCreateWithEmptyJson() throws IOException { + // Call Create Setting REST API + PostMethod post = httpPost("/interpreter/setting/", ""); + LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString()); + assertThat("test create method:", post, isBadRequest()); + post.releaseConnection(); + } + + @Test public void testInterpreterAutoBinding() throws IOException { // create note Note note = ZeppelinServer.notebook.createNote(null);
