fix non closing "hg serve" processes

This commit is contained in:
Sebastian Sdorra
2012-08-20 08:57:45 +02:00
parent 7151827e6a
commit 68edc4fa14
3 changed files with 37 additions and 17 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}