Repository: zeppelin Updated Branches: refs/heads/branch-0.6 0b9efaacc -> 5feb6b2fc
[ZEPPELIN-1159] Livy interpreter gets "404 not found" error ### What is this PR for? RestTemplate throws HttpClientErrorException, exception thrown when an HTTP 4xx is received. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/HttpClientErrorException.html ### What type of PR is it? [Bug Fix] ### What is the Jira issue? * [ZEPPELIN-1159](https://issues.apache.org/jira/browse/ZEPPELIN-1159) ### How should this be tested? Run a paragraph using livy interpreter (say sc.version), now let this session expire (or just restart livy server), then try running the same paragraph, this should result in proper error message. ### 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: Prabhjyot Singh <[email protected]> Closes #1184 from prabhjyotsingh/ZEPPELIN-1159 and squashes the following commits: 7c58e42 [Prabhjyot Singh] ZEPPELIN-1159 - catch RestTemplate exception (cherry picked from commit 473dc723f927e7a985dd8e5154ca200db22f9aaf) Signed-off-by: Mina Lee <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/5feb6b2f Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/5feb6b2f Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/5feb6b2f Branch: refs/heads/branch-0.6 Commit: 5feb6b2fcc340586cb92e7ee39723518730230f7 Parents: 0b9efaa Author: Prabhjyot Singh <[email protected]> Authored: Thu Jul 14 15:17:07 2016 +0530 Committer: Mina Lee <[email protected]> Committed: Fri Jul 22 16:02:38 2016 +0900 ---------------------------------------------------------------------- .../org/apache/zeppelin/livy/LivyHelper.java | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/5feb6b2f/livy/src/main/java/org/apache/zeppelin/livy/LivyHelper.java ---------------------------------------------------------------------- diff --git a/livy/src/main/java/org/apache/zeppelin/livy/LivyHelper.java b/livy/src/main/java/org/apache/zeppelin/livy/LivyHelper.java index ec77f1a..78ef5e7 100644 --- a/livy/src/main/java/org/apache/zeppelin/livy/LivyHelper.java +++ b/livy/src/main/java/org/apache/zeppelin/livy/LivyHelper.java @@ -33,6 +33,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.security.kerberos.client.KerberosRestTemplate; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import java.nio.charset.Charset; @@ -342,17 +343,24 @@ public class LivyHelper { HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); ResponseEntity<String> response = null; - if (method.equals("POST")) { - HttpEntity<String> entity = new HttpEntity<String>(jsonData, headers); - response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class); - paragraphHttpMap.put(paragraphId, response); - } else if (method.equals("GET")) { - HttpEntity<String> entity = new HttpEntity<String>(headers); - response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class); - paragraphHttpMap.put(paragraphId, response); - } else if (method.equals("DELETE")) { - HttpEntity<String> entity = new HttpEntity<String>(headers); - response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class); + try { + if (method.equals("POST")) { + HttpEntity<String> entity = new HttpEntity<String>(jsonData, headers); + + response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class); + paragraphHttpMap.put(paragraphId, response); + } else if (method.equals("GET")) { + HttpEntity<String> entity = new HttpEntity<String>(headers); + response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class); + paragraphHttpMap.put(paragraphId, response); + } else if (method.equals("DELETE")) { + HttpEntity<String> entity = new HttpEntity<String>(headers); + response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class); + } + } catch (HttpClientErrorException e) { + response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode()); + LOGGER.error(String.format("Error with %s StatusCode: %s", + response.getStatusCode().value(), e.getResponseBodyAsString())); } if (response == null) { return null;
