added sample GitCGIServlet

This commit is contained in:
Sebastian Sdorra
2010-10-08 10:11:15 +02:00
parent 68b9b1fa79
commit 9646389fbf
2 changed files with 99 additions and 2 deletions

View File

@@ -0,0 +1,80 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Singleton;
import sonia.scm.web.cgi.AbstractCGIServlet;
import sonia.scm.web.cgi.EnvList;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class GitCGIServlet extends AbstractCGIServlet
{
/** Field description */
public static final String ENV_HTTP_EXPORT_ALL = "GIT_HTTP_EXPORT_ALL";
/** Field description */
public static final String ENV_PROJECT_ROOT = "GIT_PROJECT_ROOT";
/** Field description */
private static final long serialVersionUID = 9147517765161830847L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected EnvList createEnvironment()
{
EnvList list = super.createEnvironment();
list.set(ENV_PROJECT_ROOT, "/tmp/git");
list.set(ENV_HTTP_EXPORT_ALL, "");
return list;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param req
*
* @return
*
* @throws IOException
* @throws ServletException
*/
@Override
protected File getCommand(HttpServletRequest req)
throws ServletException, IOException
{
return new File("/opt/local/libexec/git-core/git-http-backend/");
}
}

View File

@@ -7,6 +7,12 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.servlet.ServletModule;
import sonia.scm.web.filter.BasicAuthenticationFilter;
/**
*
* @author Sebastian Sdorra
@@ -14,8 +20,11 @@ package sonia.scm.web;
public class GitWebPlugin implements ScmWebPlugin
{
/** Field description */
public static final String SCRIPT = "/sonia/scm/git.config.js";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -38,7 +47,15 @@ public class GitWebPlugin implements ScmWebPlugin
@Override
public void contextInitialized(ScmWebPluginContext context)
{
context.addScriptResource( new ClasspathWebResource(SCRIPT) );
context.addScriptResource(new ClasspathWebResource(SCRIPT));
context.addInjectModule(new ServletModule()
{
@Override
protected void configureServlets()
{
filter("/git/*").through(BasicAuthenticationFilter.class);
serve("/git/*").with(GitCGIServlet.class);
}
});
}
}