From 68edc4fa1430615df9a968aaa34e9f313efb1593 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 20 Aug 2012 08:57:45 +0200 Subject: [PATCH] fix non closing "hg serve" processes --- .../resources/BrowserStreamingOutput.java | 20 ++++++++++++++++--- .../rest/resources/DiffStreamingOutput.java | 20 ++++++++++++++++--- .../rest/resources/RepositoryResource.java | 14 +++---------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java index 5b2dcfa50b..25b9ff03b0 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java @@ -35,6 +35,8 @@ package sonia.scm.api.rest.resources; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.io.Closeables; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +44,7 @@ import sonia.scm.repository.PathNotFoundException; import sonia.scm.repository.RepositoryException; import sonia.scm.repository.RevisionNotFoundException; import sonia.scm.repository.api.CatCommandBuilder; +import sonia.scm.repository.api.RepositoryService; //~--- JDK imports ------------------------------------------------------------ @@ -72,11 +75,15 @@ public class BrowserStreamingOutput implements StreamingOutput * @param browser * @param revision * + * @param repositoryService + * * @param builder * @param path */ - public BrowserStreamingOutput(CatCommandBuilder builder, String path) + public BrowserStreamingOutput(RepositoryService repositoryService, + CatCommandBuilder builder, String path) { + this.repositoryService = repositoryService; this.builder = builder; this.path = path; } @@ -94,7 +101,7 @@ public class BrowserStreamingOutput implements StreamingOutput */ @Override public void write(OutputStream output) - throws IOException, WebApplicationException + throws IOException, WebApplicationException { try { @@ -123,7 +130,11 @@ public class BrowserStreamingOutput implements StreamingOutput logger.error("could not write content to page", ex); throw new WebApplicationException(ex, - Response.Status.INTERNAL_SERVER_ERROR); + Response.Status.INTERNAL_SERVER_ERROR); + } + finally + { + Closeables.closeQuietly(repositoryService); } } @@ -134,4 +145,7 @@ public class BrowserStreamingOutput implements StreamingOutput /** Field description */ private String path; + + /** Field description */ + private RepositoryService repositoryService; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java index ad55889c0d..20a0a7b42f 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java @@ -35,6 +35,8 @@ package sonia.scm.api.rest.resources; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.io.Closeables; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +44,7 @@ import sonia.scm.repository.PathNotFoundException; import sonia.scm.repository.RepositoryException; import sonia.scm.repository.RevisionNotFoundException; import sonia.scm.repository.api.DiffCommandBuilder; +import sonia.scm.repository.api.RepositoryService; //~--- JDK imports ------------------------------------------------------------ @@ -69,10 +72,14 @@ public class DiffStreamingOutput implements StreamingOutput * Constructs ... * * + * + * @param repositoryService * @param builder */ - public DiffStreamingOutput(DiffCommandBuilder builder) + public DiffStreamingOutput(RepositoryService repositoryService, + DiffCommandBuilder builder) { + this.repositoryService = repositoryService; this.builder = builder; } @@ -89,7 +96,7 @@ public class DiffStreamingOutput implements StreamingOutput */ @Override public void write(OutputStream output) - throws IOException, WebApplicationException + throws IOException, WebApplicationException { try { @@ -118,7 +125,11 @@ public class DiffStreamingOutput implements StreamingOutput logger.error("could not write content to page", ex); throw new WebApplicationException(ex, - Response.Status.INTERNAL_SERVER_ERROR); + Response.Status.INTERNAL_SERVER_ERROR); + } + finally + { + Closeables.closeQuietly(repositoryService); } } @@ -126,4 +137,7 @@ public class DiffStreamingOutput implements StreamingOutput /** Field description */ private DiffCommandBuilder builder; + + /** Field description */ + private RepositoryService repositoryService; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 12db6099ea..a8adf22f6e 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -776,7 +776,7 @@ public class RepositoryResource builder.setRevision(revision); } - output = new BrowserStreamingOutput(builder, path); + output = new BrowserStreamingOutput(service, builder, path); String contentDispositionName = getContentDispositionNameFromPath(path); @@ -797,10 +797,6 @@ public class RepositoryResource logger.error("could not retrive content", ex); response = createErrorResonse(ex); } - finally - { - Closeables.closeQuietly(service); - } return response; } @@ -860,8 +856,8 @@ public class RepositoryResource revision).concat(".diff"); String contentDispositionName = getContentDispositionName(name); - response = Response.ok(new DiffStreamingOutput(builder)).header( - "Content-Disposition", contentDispositionName).build(); + response = Response.ok(new DiffStreamingOutput(service, + builder)).header("Content-Disposition", contentDispositionName).build(); } catch (RepositoryNotFoundException ex) { @@ -876,10 +872,6 @@ public class RepositoryResource logger.error("could not create diff", ex); response = createErrorResonse(ex); } - finally - { - Closeables.closeQuietly(service); - } return response; }