use new cgiservlet

This commit is contained in:
Sebastian Sdorra
2010-09-28 18:59:33 +02:00
parent 0e1bc215cb
commit 12fc507d7b
4 changed files with 77 additions and 18 deletions

View File

@@ -12,15 +12,16 @@ package sonia.scm.web;
import com.google.inject.Scopes;
import com.google.inject.servlet.ServletModule;
import org.apache.catalina.servlets.CGIServlet;
import sonia.scm.web.filter.BasicAuthenticationFilter;
import sonia.scm.web.cgi.CGIServlet;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
@@ -28,6 +29,19 @@ import java.util.Map;
public class HgServletModule extends ServletModule
{
/**
* Constructs ...
*
*
* @param servletContext
*/
HgServletModule(ServletContext servletContext)
{
cgiPath = HgUtil.getCGI().getAbsolutePath();
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -39,8 +53,13 @@ public class HgServletModule extends ServletModule
Map<String, String> initParams = new HashMap<String, String>();
initParams.put("cgiPathPrefix", "WEB-INF/cgi/hgweb.cgi");
initParams.put("command", cgiPath);
bind(CGIServlet.class).in(Scopes.SINGLETON);
serve("/hg/*").with(CGIServlet.class, initParams);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String cgiPath;
}

View File

@@ -0,0 +1,52 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.SCMContext;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/**
*
* @author Sebastian Sdorra
*/
public class HgUtil
{
/** Field description */
public static final String CGI_DIRECTORY = "cgi-bin";
/** Field description */
public static final String CGI_NAME = "hgweb.cgi";
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public static File getCGI()
{
File cgiDirectory = new File(SCMContext.getContext().getBaseDirectory(),
CGI_DIRECTORY);
if (!cgiDirectory.exists() &&!cgiDirectory.mkdirs())
{
throw new RuntimeException(
"could not create directory".concat(cgiDirectory.getPath()));
}
return new File(cgiDirectory, CGI_NAME);
}
}

View File

@@ -34,9 +34,6 @@ import javax.servlet.ServletContext;
public class HgWebConfigWriter
{
/** Field description */
public static final String CGI_PATH = "WEB-INF/cgi/hgweb.cgi";
/** Field description */
public static final String CGI_TEMPLATE = "/sonia/scm/hgweb.cgi";
@@ -72,17 +69,7 @@ public class HgWebConfigWriter
writeWebConfigFile(webConfigFile);
String path = context.getRealPath(CGI_PATH);
File cgiFile = new File(path);
File cgiDirectory = cgiFile.getParentFile();
if (!cgiDirectory.exists() &&!cgiDirectory.mkdirs())
{
throw new IOException(
"could not create directory: ".concat(cgiDirectory.getPath()));
}
System.out.println( cgiFile );
File cgiFile = HgUtil.getCGI();
writeCGIFile(cgiFile, webConfigFile);
}
@@ -111,6 +98,7 @@ public class HgWebConfigWriter
rp.addVariable("python", config.getPythonBinary());
rp.addVariable("config", webConfigFile.getAbsolutePath());
rp.process(input, output);
cgiFile.setExecutable(true);
}
finally
{

View File

@@ -42,6 +42,6 @@ public class HgWebPlugin implements ScmWebPlugin
public void contextInitialized(ScmWebPluginContext context)
{
context.addScriptResource(new ClasspathWebResource(SCRIPT));
context.addInjectModule(new HgServletModule());
context.addInjectModule(new HgServletModule( context.getServletContext() ));
}
}