Repository: ambari Updated Branches: refs/heads/trunk fdb12d480 -> 78e038a80
AMBARI-20353. Log error while importing the workflow from encrypted path. (Madhan Mohan Reddy via gauravn7) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/78e038a8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/78e038a8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/78e038a8 Branch: refs/heads/trunk Commit: 78e038a8098200c58b425c7cd6b5e87e75da0ea8 Parents: fdb12d4 Author: Gaurav Nagar <grv...@gmail.com> Authored: Wed Mar 8 17:00:23 2017 +0530 Committer: Gaurav Nagar <grv...@gmail.com> Committed: Wed Mar 8 17:00:23 2017 +0530 ---------------------------------------------------------------------- .../ambari/view/OozieProxyImpersonator.java | 42 ++------------------ .../org/apache/oozie/ambari/view/Utils.java | 30 ++++++++++++++ 2 files changed, 34 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/78e038a8/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java ---------------------------------------------------------------------- diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java index 9bf2f90..d82f928 100644 --- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java +++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java @@ -23,7 +23,6 @@ import static org.apache.oozie.ambari.view.Constants.STATUS_OK; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -37,7 +36,6 @@ import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -335,15 +333,7 @@ public class OozieProxyImpersonator { } try { final InputStream is = workflowFilesService.readAssset(assetPath); - StreamingOutput streamer = new StreamingOutput() { - @Override - public void write(OutputStream os) throws IOException, - WebApplicationException { - IOUtils.copy(is, os); - is.close(); - os.close(); - } - }; + StreamingOutput streamer = utils.streamResponse(is); return Response.ok(streamer).status(200).build(); } catch (IOException ex) { LOGGER.error(ex.getMessage(),ex); @@ -359,15 +349,7 @@ public class OozieProxyImpersonator { } try { final InputStream is = workflowFilesService.readDraft(workflowPath); - StreamingOutput streamer = new StreamingOutput() { - @Override - public void write(OutputStream os) throws IOException, - WebApplicationException { - IOUtils.copy(is, os); - is.close(); - os.close(); - } - }; + StreamingOutput streamer = utils.streamResponse(is); return Response.ok(streamer).status(200).build(); } catch (IOException ex) { LOGGER.error(ex.getMessage(),ex); @@ -426,15 +408,7 @@ public class OozieProxyImpersonator { private Response getWorkflowResponse(String filePath, String responseType, boolean olderFormatDraftIngored) throws IOException { final InputStream is = workflowFilesService.readWorkflowXml(filePath); - StreamingOutput streamer = new StreamingOutput() { - @Override - public void write(OutputStream os) throws IOException, - WebApplicationException { - IOUtils.copy(is, os); - is.close(); - os.close(); - } - }; + StreamingOutput streamer = utils.streamResponse(is); Response.ResponseBuilder responseBuilder = Response.ok(streamer).header(RESPONSE_TYPE, responseType); if (olderFormatDraftIngored) { responseBuilder.header(OLDER_FORMAT_DRAFT_INGORED, Boolean.TRUE.toString()); @@ -455,15 +429,7 @@ public class OozieProxyImpersonator { throw new WfmWebException(ErrorCode.WORKFLOW_XML_DOES_NOT_EXIST); } final InputStream is = workflowFilesService.readWorkflowXml(workflowPath); - StreamingOutput streamer = new StreamingOutput() { - @Override - public void write(OutputStream os) throws IOException, - WebApplicationException { - IOUtils.copy(is, os); - is.close(); - os.close(); - } - }; + StreamingOutput streamer = utils.streamResponse(is); return Response.ok(streamer).status(200).build(); } catch (WfmWebException ex) { LOGGER.error(ex.getMessage(),ex); http://git-wip-us.apache.org/repos/asf/ambari/blob/78e038a8/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java ---------------------------------------------------------------------- diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java index 0b9adda..8f427bd 100644 --- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java +++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java @@ -18,6 +18,10 @@ package org.apache.oozie.ambari.view; import java.io.IOException; +import java.io.OutputStream; +import java.io.InputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedInputStream; import java.io.StringReader; import java.io.StringWriter; import java.util.HashMap; @@ -26,9 +30,11 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.StreamingOutput; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -163,4 +169,28 @@ public class Utils { return false; } } + public StreamingOutput streamResponse(final InputStream is) { + return new StreamingOutput() { + @Override + public void write(OutputStream os) throws IOException, + WebApplicationException { + BufferedInputStream bis=new BufferedInputStream(is); + BufferedOutputStream bos=new BufferedOutputStream(os); + try { + int data; + while ((data = bis.read()) != -1) { + bos.write(data); + } + is.close(); + os.close(); + }catch (IOException e){ + LOGGER.error(e.getMessage(),e); + throw e; + }catch (Exception e){ + LOGGER.error(e.getMessage(),e); + throw new RuntimeException(e); + } + } + }; + } }