Repository: zeppelin Updated Branches: refs/heads/master fea00460b -> 473dc723f
[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 Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/473dc723 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/473dc723 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/473dc723 Branch: refs/heads/master Commit: 473dc723f927e7a985dd8e5154ca200db22f9aaf Parents: fea0046 Author: Prabhjyot Singh <[email protected]> Authored: Thu Jul 14 15:17:07 2016 +0530 Committer: Prabhjyot Singh <[email protected]> Committed: Tue Jul 19 17:51:26 2016 +0530 ---------------------------------------------------------------------- .../org/apache/zeppelin/livy/LivyHelper.java | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/473dc723/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 f84765d..9a92c31 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; @@ -350,17 +351,24 @@ public class LivyHelper { headers.add("Content-Type", "application/json"); headers.add("X-Requested-By", "zeppelin"); 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;
