Commits

Sebastian Sdorra committed 4d84a40

fix non closing "hg serve" processes

Comments (0)

Files changed (3)

scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.common.io.Closeables;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import sonia.scm.repository.RepositoryException;
 import sonia.scm.repository.RevisionNotFoundException;
 import sonia.scm.repository.api.CatCommandBuilder;
+import sonia.scm.repository.api.RepositoryService;
 
 //~--- JDK imports ------------------------------------------------------------
 
    * @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;
   }
    */
   @Override
   public void write(OutputStream output)
-          throws IOException, WebApplicationException
+    throws IOException, WebApplicationException
   {
     try
     {
       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);
     }
   }
 
 
   /** Field description */
   private String path;
+
+  /** Field description */
+  private RepositoryService repositoryService;
 }

scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.common.io.Closeables;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import sonia.scm.repository.RepositoryException;
 import sonia.scm.repository.RevisionNotFoundException;
 import sonia.scm.repository.api.DiffCommandBuilder;
+import sonia.scm.repository.api.RepositoryService;
 
 //~--- JDK imports ------------------------------------------------------------
 
    * Constructs ...
    *
    *
+   *
+   * @param repositoryService
    * @param builder
    */
-  public DiffStreamingOutput(DiffCommandBuilder builder)
+  public DiffStreamingOutput(RepositoryService repositoryService,
+    DiffCommandBuilder builder)
   {
+    this.repositoryService = repositoryService;
     this.builder = builder;
   }
 
    */
   @Override
   public void write(OutputStream output)
-          throws IOException, WebApplicationException
+    throws IOException, WebApplicationException
   {
     try
     {
       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);
     }
   }
 
 
   /** Field description */
   private DiffCommandBuilder builder;
+
+  /** Field description */
+  private RepositoryService repositoryService;
 }

scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java

         builder.setRevision(revision);
       }
 
-      output = new BrowserStreamingOutput(builder, path);
+      output = new BrowserStreamingOutput(service, builder, path);
 
       String contentDispositionName = getContentDispositionNameFromPath(path);
 
       logger.error("could not retrive content", ex);
       response = createErrorResonse(ex);
     }
-    finally
-    {
-      Closeables.closeQuietly(service);
-    }
 
     return response;
   }
                       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)
     {
       logger.error("could not create diff", ex);
       response = createErrorResonse(ex);
     }
-    finally
-    {
-      Closeables.closeQuietly(service);
-    }
 
     return response;
   }