hit counter
   
 

Random ramblings of a paranoid git
"The question is not if you are paranoid, it is if you are paranoid enough."


All | Security | Work | Wine & Dine | Leisure

   
   
20060917 Sunday September 17, 2006
Glassfish and Mercurial how-to
Permalink | Comments [2] | 2006-09-17 14:57

As promised here is my Glassfish and Mercurial how-to:

I started out by creating a new project in NetBeans and selected "Web Application" from the "Web" category as project template, and called the project "cgi-bin".

Then I opened the web.xml file, and edited it so it looks like below:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>cgiPathPrefix</param-name>
            <param-value>WEB-INF/cgi</param-value>
        </init-param>
        <load-on-startup>10</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
	<welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>

The class org.apache.catalina.servlets.CGIServlet does not have to be created, as it is bundled with Glassfish.

Now I created the WEB-INF/cgi directory and copied the hgweb.cgi file from the Mercurial distribution to that directory, and changed the location of the repository and the name of the repository to reflect upon our configuration:

#!/usr/bin/env python
#
# An example CGI script to use hgweb, edit as necessary

import cgitb, os, sys
cgitb.enable()

# sys.path.insert(0, "/path/to/python/lib") # if not a system-wide install
from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.request import wsgiapplication
import mercurial.hgweb.wsgicgi as wsgicgi

def make_web_app():
    return hgweb("/java/hg/jdk7", "JDK 7 repository")

wsgicgi.launch(wsgiapplication(make_web_app))

After that I built the project and deployed the cgi-bin.war file, and can now access my JDK 7 repository at http://server/cgi-bin/hgweb.cgi.

If I want to enable authentication, it is very simple. I just add a security-constraint section in my web.xml file:
    <security-constraint>
        <display-name>Mercurial</display-name>
        <web-resource-collection>
            <web-resource-name>Mercurial</web-resource-name>
            <description/>
            <url-pattern>/cgi-bin/hgweb.cgi</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>HEAD</http-method>
            <http-method>PUT</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>mercurial</role-name>
            </auth-constraint>
        </security-constraint>
    <security-role>
        <description>Role for accessing hgweb.cgi</description>
        <role-name>mercurial</role-name>
    </security-role>

And configure my authentication domain and people will have to authenticate before they can access the repository.

[Technorati Tags: ]

   
 
Comments:

Not being a Java programmer at all never mind a J2EE program I'm a little out of my depth on the content of the blog entry. Are you saying that you have NetBeans working with Mercurial as a version control system ? If so how would I do that for C source code, say a larger Mercurial source base like the ON consolidation of OpenSolaris ?

Posted by Darren Moffat on September 20, 2006 at 04:02 AM PDT #

@Darren: I talked with Martin earlier this week, and he mentioned this to me. What the files above to is allow a Glassfish server to run the Mercurial CGI script, as opposed to how one would make a web server do it. As a result, you can then use the various administrative features of a Java EE app server, such as authentication and deployment. -- Stephen

Posted by Stephen on September 21, 2006 at 10:58 AM PDT #

Post a Comment:

Comments are closed for this entry.
   
XML
« May 2008
SunMonTueWedThuFriSat
    
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today


Old entries


Bloggtoppen.se
OpenSolaris: Love at First Boot