Archive

Archive for the ‘Web’ Category

JSP On Grizzly

May 24th, 2010 No comments

We had a lot of people that ask how to put JSP over Grizzly, but we didn’t have a implementation or a working sample to show them.
It couldn’t stay like that for ever … so I took a little of my spare time and I got something for you :)

I’ll show you how to to compile your JSP with Jasper and use them with GrizzlyWebServer.
I used Jasper that came with Tomcat 6. I’ll need to include some librairies to your project.
I didn’t try with Tomcat 4.x, but maybe you could save some space.
I’ll skip the jars required for Jasper to the end of this article. Now let’s take a look at the beast (ok, mini-beast).

The JSP page is really simple. If you want to use framework like Struts, you will have more work to do, but I won’t cover that.

<html>	<body>

		Hello to you : 		<table>			<tr>		<% for(int i=0;i<5;i++){%>			<td><%=i%></td>		<%}%>		</tr>	</table>	</body>	</html>

We need to compile the JSP if we want to use it with our GrizzlyWebServer. It isn’t really complicated.

public void compileJSP(String[] params) throws Exception {		JspC jasper = new JspC();

		jasper.setArgs(params);		jasper.execute();}

...  

String jasperParams[] = new String[]{				"-webapp", 				"./jsp",				"-v",				"-p", 				"ca.sebastiendionne", 				"-d", 				"./classes", 				"-l", 				"-s", 				//"-webxml", // if you want JSPC to generate a webxml				//"./web_jasper.xml", 				"-compile"};

//compile the JSPcompileJSP(jasperParams);

That will generate the welcome_jsp.java and compile into /classes. Now we need to call it in our application.

public void launch(){		GrizzlyWebServer ws = new GrizzlyWebServer(80);

		try {            ServletAdapter sa = new ServletAdapter();            sa.setContextPath("/");

            // need to load JspRuntimeContext            Class.forName("org.apache.jasper.compiler.JspRuntimeContext");

            Servlet servlet = (Servlet)ClassLoaderUtil.load("ca.sebastiendionne.welcome_jsp");    	      sa.setServletInstance(servlet);

    	      ws.addGrizzlyAdapter(sa, new String[]{});            ws.start();        } catch (Exception e){            s_logger.error("Error Launching GrizzlyWebServer",e);        }}

The final touch is to test it. You will obtain a very nice output :) http://localhost

Hello to you :0 	1 	2 	3 	4

I didn’t go to deep into JSPC. I used JSPC, the class used by the Ant task. So because of that, we will need
to include Ant jars into the project. If you have problems with that, I’m sure that you could extract the code from
the ant task too.
The jars needed are :

ant-launcher.jar // from ant 1.7x
ant.jar // from ant 1.7x
el-api.jar // from Tomcat 6.x
jasper-el.jar // from Tomcat 6.x
jasper-jdt.jar // from Tomcat 6.x
jasper.jar // from Tomcat 6.x
jsp-api.jar // from Tomcat 6.x
servlet-api.jar // from Tomcat 6.x
tomcat-juli.jar // from Tomcat 6.x : for the logging into JSPC

You can download the source code here.

Categories: Grizzly, Web Tags: , ,

Grizzly : Drop connection for banned IP

May 24th, 2010 No comments

I want to show you how you can block IPs in your Grizzly server. I pretty sure that you can found lot of reasons why you could want that.
I’ll use a list from http://iblocklist.com/ as input for my demo.
What you have to do to close the connection from client that isn’t wanted is pretty simple.

    Controller controller = new Controller();    TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler(){        public SelectableChannel acceptWithoutRegistration(SelectionKey key) throws IOException {            ServerSocketChannel server = (ServerSocketChannel) key.channel();            SocketChannel channel = server.accept();

            if (isAddressBanned(channel.socket().getInetAddress()))  {                if(s_logger.isDebugEnabled()){                  s_logger.debug("This IP [" + channel.socket().getInetAddress() +                   "] is banned, the connection will be close");                }                closeChannel(channel);                return null;            }

            return channel;        }    };    tcpSelectorHandler.setPort(port);    controller.addSelectorHandler(tcpSelectorHandler);

With that, as soon as a connection is made, Grizzly will valid if the IP is valid and close the connection is required.
I won’t show the implementation of “isAddressBanned”, because is not really related to Grizzly, but you can find it in the source code.
You can download the complete source code from here.

Categories: Grizzly, Web Tags: ,

Template Code Generator Part 2 : FreeMarker

May 24th, 2010 No comments

In my previous post, I covered Apache Velocity, Eclipse JET/JET2.
I got a suggestion to look the framework FreeMarker.

FreeMarker look like Velocity. You can even find converters : Velocity -> FreeMarker.
I’ll describe in this part how to create the same output but using FreeMarker.

Take a look at the generate method.

SampleFreeMarker.java

  public void generate() {

    try {      Configuration cfg = new Configuration();

      cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);

      Template tpl = cfg.getTemplate("./templates/GalleryTemplateFreeMarker.ftl");      OutputStreamWriter output = new OutputStreamWriter(System.out);

      Map root = new HashMap();

      root.put("list", mediaFileList);

      tpl.process(root, output);

    } catch (Exception e) {      s_logger.error("generate", e);    }

  }

Let’s compare to the Velocity implementation.

SampleVelocity.java

  public void generate() {

    try {      Velocity.init();

      VelocityContext context = new VelocityContext();      context.put("list", mediaFileList);

      Template template = Velocity.getTemplate("./templates/GalleryTemplateVelocity.vm");

      BufferedWriter writer = writer = new BufferedWriter(new OutputStreamWriter(System.out));

      if (template != null)        template.merge(context, writer);

      /*       * flush and cleanup       */

      writer.flush();      writer.close();

    } catch (Exception e) {      s_logger.error("generate", e);    }

  }

The main difference is with FreeMarker you need to create a root HashMap and put the objects in it.
With Velocity you put the objects within the context.

Now see the FreeMarker template.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 <html>   <head>    <!-- include the required JavaScript file -->   </head>

 <body>  <div align="center">    <table width="80%"><#assign maxItembyRow = 2><#assign index = 0><#assign count = 0><#assign newLine = true><#foreach mediaFile in list>  <#if newLine>      <tr>  <#assign newLine = false>  </#if>        <td>            <a href="${mediaFile.name}" id="player${count}">            </a>        </td>  <#if index < maxItembyRow-1>            <#assign index = index + 1>  <#else>    <#assign index = 0>    <#assign newLine = true>  </#if>  <#if newLine>      </tr>  </#if>  <#assign count = count + 1></#foreach>    </tr>  </table>  </div>  </body></html> 

It’s almost the same as Velocity except that the syntax change a little.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 <html>   <head>    <!-- include the required JavaScript file -->   </head>

 <body>  <div align="center">    <table width="80%">#set( $maxItembyRow = 2)#set( $index = 0)#set( $newLine = true)#foreach( $mediaFile in $list )#if( $newLine )    <tr>#set( $newLine = false)#end#if( $index<$maxItembyRow )        <td><a href="$mediaFile.name" id="player$velocityCount">             </a>        </td>#set($index = $index+1)#else#set($index = 0)#set( $newLine = true)#end#end    </tr>  </table>  </div>  </body></html> 

What I didn’t like about FreeMarker is the lack of documentation.
There had good javadoc, but something you need more than that like “real life” samples.
The source code can be downloaded here.

Categories: Java Tools, Web Tags:

Template Code Generator : Apache Velocity – JET – JET2

May 24th, 2010 3 comments

I wanted to use a template as input for my Code Generator, but the problem was to find one that worked in a stand alone mode, not a web based one. In my research a found few that do what I wanted. Apache Velocity and Eclipse JET/JET2.

I’ll explain in details theses Template Code Generator with a little application. I’ll create a web page as output.

Here the specs for the demo.

– The web page template should create a entry for each items in the list received in parameter
– The list could be created dynamically (so the number of items is not fixed)

Before starting to explain how to do it with theses frameworks, I’ll use a class : MediaFile that contains the info on a media file. I’ll create a html that display 2 items by row and just to kept the demo simpler, I’ll use a even number of items.

Take a look at the html that I would like to generate.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 <html>   <head>    <!-- include the required JavaScript file -->   </head>

 <body>  <div align="center">    <table width="80%">        <tr>            <td>              <a href="name1" id="player1">name1               </a>             </td>            <td>              <a href="name2" id="player2">name2              </a>             </td>        </tr>        <tr>            <td>              <a href="name3" id="player3">name3              </a>             </td>            <td>              <a href="name4" id="player4">name4              </a>             </td>        </tr>        <tr>            <td>              <a href="name5" id="player5">name5              </a>             </td>            <td>              <a href="name6" id="player6">name6               </a>             </td>        </tr>    </table>  </div>  </body></html> 

I didn’t put <td> and <a> on the same line on purpose. The reason it because it’s easier to show the format’s problems with a code generator. I’ll explain it in more details later.

The MediaFile’s list will be populated like that :

public void init() {

    mediaFileList = new ArrayList();

    for (int i = 0; i < 5; i++) {      MediaFile mediaFile = new MediaFile();      mediaFile.setName("name" + i);      mediaFile.setFps("29.997");      mediaFile.setDuration("12:45");      mediaFile.setCodec("H264");      mediaFile.setWidth("320");      mediaFile.setHeight("240");      mediaFile.setStreamSize("2 Megs");

      mediaFileList.add(mediaFile);    }

  }

Apache Velocity

I known the framework by name, but I never used before. I have to say that it wasn’t too hard to get it to work. Apache have a good documentation for Velocity API. If you are not familiar with this API, go take a look at the user guide http://velocity.apache.org/engine/devel/user-guide.html

Apache Velocity use it’s own language, but it’s pretty simple. What I didn’t like at first was the lack of nested loop.

I wanted to do something like that (using the iterator in a nested loop):

  for(Iterator it = list.iterator();it.hasNext();){   ...      for(int i=0;i<2;i++){        Object element = iterator.next();        ...      }      ... }  

I’m not a expert in Velocity, but after looking around on the web, I didn’t find a simple answer, so I had to do it another way. The problem with a template like below, is that it could become hard to read, because if you let some blank lines for the readiness of the code, theses lines will appear in the generated code.

Let’s take a look at the template in Velocity that will give the desirable layout.

GalleryTemplateVelocity.vm

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 <html>   <head>    <!-- include the required JavaScript file -->   </head>

 <body>  <div align="center">    <table width="80%">#set( $maxItembyRow = 2)#set( $index = 0)#set( $newLine = true)#foreach( $mediaFile in $list )#if( $newLine )    <tr>#set( $newLine = false)#end#if( $index<$maxItembyRow )        <td><a href="$mediaFile.name" id="player$velocityCount">$mediaFile.name            </a>        </td>#set($index = $index+1)#else#set($index = 0)#set( $newLine = true)#end#end    </tr>  </table>  </div>  </body></html>  

After that we need the main class that will call the template, and populate the list of MediaFile. If you want to pass variables to Velocity template, you have to put them in the context, like you do for a HttpRequest.

SampleVelocity.java

  public void generate() {

    try {      Velocity.init();

      VelocityContext context = new VelocityContext();      context.put("list", mediaFileList);

      Template template = Velocity.getTemplate("./templates/GalleryTemplateVelocity.vm");

      BufferedWriter writer = writer = new BufferedWriter(new OutputStreamWriter(System.out));

      if (template != null)        template.merge(context, writer);

      /*       * flush and cleanup       */

      writer.flush();      writer.close();

    } catch (Exception e) {      s_logger.error("generate", e);    }

  }

Eclipse JET

JET can be used as a template code generator. It’s was made to run within Eclipse, but you can include two Eclipse jar and that will do the trick. JET is based on the JSP syntax. If you have done scriplet in JSP, you won’t find that hard to use.

The main differences between JEt and Velocity, is that JET only take 1 parameter in the template. Yes, only one… You can pass that by creating a java class that will contains all your variables. Yes it’s ugly, but when you know it, it’s not hard to use.

The second big difference is that JET framework compile the template into a java class, and you use this class in your application.

Take a look at the JET template (look like a JSP with the 2 first lines that you related to JET.

GalleryTemplateJet.jet

<%@ jet package="ca.sebastiendionne.gallery.jet" class="GalleryHtmlJET" imports="java.util.* ca.sebastiendionne.gallery.model.*" %><% List<MediaFile> mediaFileList = (List<MediaFile>) argument; %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 <html>   <head>    <!-- include the required JavaScript file -->   </head>

 <body>  <div align="center">    <table width="80%">      <% 

      int maxItembyRow = 2;      int index = 0;

      for (Iterator<MediaFile> iterator=mediaFileList.iterator();iterator.hasNext();) {%>        <tr>        <%        for(int j=0;j<maxItembyRow;j++){          MediaFile element = iterator.next();          %>            <td>            <a href="<%=element.getName()%>" id="player<%=index%>"><%=element.getName()%>           </a> 

            <%=element%>

            </td>          <%          index++;        }%>        </tr>        <%      }      %>    </table>  </div>  </body></html>

That will generate the java class : ca.sebastiendionne.gallery.jet.GalleryHtmlJET

and you use it like that :

  public void generate(){

    GalleryHtmlJET galleryJET = new GalleryHtmlJET();

    String html = galleryJET.generate(mediaFileList);  // the argument is the list

    System.out.println(html);  }

The method generate() is simpler and smaller than Velocity, but in other hands… The formatting is more tricky with JSP syntax. Try for fun to look at a html page generated with scriptlet. It’s will works, but there will be lot of blank lines and it won’t have a nice indentation. That is important when you want to generate java class. You don’t want to pass a formatter after the generating job.

I had used JET few months ago for my application IbatisGen. I think that it took more time to get the indentation right that coding the rest of the application.

JET have some limitations like the one argument, but that JET2 fixed that.

Eclipse JET2

JET2 differs than JET1 in different ways. JET1 can be used outside Eclipse, but not JET2.

JET2 can be easily use in Eclipse if you have a xml file as input, but if you don’t have a fixed input like this demo. It’s more complicated.
You will have to create a Eclipse Plugin that will be able to handle dynamic input.

So, if you don’t want to create a Eclipse Plugin, stop here, take JET or Velocity.

I won’t cover how to create the JET2 Plugin, you can find a good sample here http://www.eclipse.org/articles/Article-JET2/jet_tutorial2.html, but I’ll show you how to use a xml input file.

The JET2 templates can you JSP and JSLT syntax like.

sample.xml

<app class="Car">  <property name="model" type="String" initial="Hybrid" />  <property name="horsepower" type="int" initial="140" />  <property name="spareTires" type="boolean" initial="true" /></app>

The main template (like the java class that contains the main() )

main.jet

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %><c:if test="isVariableDefined('org.eclipse.jet.resource.project.name')">    <ws:file template="templates/testCar.jet" path="{$org.eclipse.jet.resource.project.name}/dump2.xml"/></c:if>

testCar.jet (the template that will generate the code from sample.xml) (We are creating a getter/setter class)

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>class <c:get select="/app/@class" /> {<c:iterate select="/app/property" var="p" >  private <c:get select="$p/@type" /> <c:get select="$p/@name" />;</c:iterate>

  public <c:get select="/app/@class" />() {  <c:iterate select="/app/property" var="p" >    this.<c:get select="$p/@name" /> = <c:choose select="$p/@type" >    <c:when test="'String'">"<c:get select="$p/@initial" />"</c:when>    <c:otherwise><c:get select="$p/@initial" /></c:otherwise>    </c:choose>;  </c:iterate>  }

<c:iterate select="/app/property" var="p" >  public void set<c:get select="camelCase($p/@name)" />(<c:get select="$p/@type" /> <c:get select="$p/@name" />) {    System.out.println("In set<c:get select="camelCase($p/@name)" />()");    this.<c:get select="$p/@name" /> = <c:get select="$p/@name" />;  }

  public <c:get select="$p/@type" /> get<c:get select="camelCase($p/@name)" />() {    System.out.println("In get<c:get select="camelCase($p/@name)" />()");    return <c:get select="$p/@name" />;  }

</c:iterate>}

To run all that you need to “Run as … JET Transformation” in Eclipse.

I won’t go into details, but here what the generate() method should look like if you want to handle a dynamic input.

public void generate(){

    GalleryHtmlJET galleryJET = new GalleryHtmlJET();

    JET2Context context = new JET2Context(null);    context.setVariable("list", mediaFileList);

    JET2Writer out = new BodyContentWriter();

    context.setTagFactory(new TagFactoryImpl(context));

    ... the line for the Plugin      galleryJET.generate(context, out);    ... end of the Plugin stuff    System.out.println(out);

  }

It’s look really like Apache Velocity at this point.

If I had to choose between them, I don’t know if I would choose Velocity or JET. Both of them could work in a plugin (Eclipse or Netbean), support Ant task.

What do you think ? Do you know some framework that you want to share with us ?
You can download the source code here : Velocity/JET and JET2.

Categories: Java Tools, Web Tags: , , ,

Tools for debugging html/css/javascript

May 24th, 2010 No comments

There are so many browsers and version of theses browsers that I became harder to create HTML that will run on all the possibles combinations.

You need the appropriate tools to help you to debug. There are few application and plugins you need to try :

- Firebug for Firefox (https://addons.mozilla.org/fr/firefox/addon/1843) : to debug everything : html, css, javascript, ajax …

- Markup Validation Service (http://validator.w3.org/) : to validate your (x)html page.

- Internet Explorer Developer Toolbar (http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en) :

Microsoft Firebug alternative : to debug html, css …

- Install multiple versions of IE on your PC (http://tredosoft.com/Multiple_IE) : Install more than one version of IE on your PC.

- CSS Formatter and Optimiser (http://floele.flyspray.org/csstidy//css_optimiser.php?lang=en) : a nice CSS formatter and optimiser.

-I also recommend trying IETester (http://www.my-debugbar.com/wiki/IETester/HomePag) which allows you to open browser tabs with individual IE engines.

I like this even a little bit better than MultipleIE,

which is a very cool package but caused me some problems while IETester just ran out of the box.

Theses are the tools that I’m using to debug the main page of Glassfish. Even with that.. it’s hard :)

Categories: Java Tools, Web Tags:

Read web.xml with one line of code

May 24th, 2010 No comments

I needed to parse a web.xml for a sample for Grizzly and I wanted to find a way to have something that I can reuse later. You don’t have to do it by hand. There are tools out there to do it for you.

One of them is XMLBeans from Apache group and more popular is JAXB. For JDK 1.4 ,I used XMLBeans and if you have JDK6 JAXB will reduce the dependencies and will be more smaller. I’ll show you how to use theses two API.

XMLBEANS

What I like about this tool is that I can generate Java classes from a xsd within seconds using Ant.

I want to show you how to obtain a Class that will contains a web.xml loaded with only one line of code :)

Let’s start by downloading XMLBeans. I’ll skip to the folder structure I’ll use for this demo.

lib/ : Where you put the XMLBeans libraries
schemas/ : Where you put the xsd
build.xml

Download build.xml from here.

I use the schemas from Glassfish sources : glassfish/appserv-commons/schemas

You don’t have to copy all the files. Copy just the main schemas and Ant will download the missing schemas.

For my demo I used theses files :

schemas/j2ee_1_4.xsd
schemas/jsp_2_0.xsd
schemas/web-app_2_4.xsd

you just have to launch the ant task with this command :

ant -autoproxy

that will generate a jar file and the java source for theses schemas.

Now.. How do we load a web.xml within our Java application ?

#1 – Include the jar file : j2ee_schemas-xmlbeans.jar into your project
#2 – Create the root class of your schema and load the web.xml

WebAppDocument webAppDocument = WebAppDocument.Factory.parse(webxmlFile);

After that .. It’s up to you, webAppDocument contains all the config from web.xml.

JAXB

You will need the librairies for the compilation, but after that if you use JDK6, you can remove them, because JAXB is include in JDK6.

#1 – To generate the schemas, you use ant.
#2 – Include the jar file : j2ee_schemas-jaxb.jar into your project
#3 – Create the root class of your schema and load the web.xml

JAXBContext jc = JAXBContext.newInstance(“ca.sebastiendionne.jaxb.xsd”);

// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();

JAXBElement root = (JAXBElement)u.unmarshal( new FileInputStream(“./web.xml”) );

WebAppType webAppType = (WebAppType)root.getValue();

It’s take a little more line of code, but it’s not complicated.

I put the source project (xmlbeans + jabx) here.

Categories: Java Tools, Web Tags: , , ,

DisplayTag : Create a html grid within five minutes

May 24th, 2010 No comments

I found a really nice taglib to generate html table for my JSP :D isplayTag. What I like about DisplayTag is that the most common features are buildin : Sort, Pagination, Export to Excel… Before that I had to do it each time, and it’s not really productive and worst.. the code can easily be broke by others developpers.

I’ll show you how to create a search page using Struts with Tiles and display the result using DisplayTag.

Let’s start by a screenshot of the result and I’ll show you how to reproduce that step by step.

I took Tomcat 4.1 for the demo. The reason is to take the lowest version of JSTL and JSP just to show you that it can be use on all Webserver.

The source code and the project is available to download here.

Here the steps to do :

#1 – Will be to create a web project. I won’t cover that point.

#2 – Edit web.xml to include DisplayTag and JSTL tags. Here the complete web.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE web-app
PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/j2ee/dtds/web-app_2_3.dtd”>

<web-app id=”WebApp_ID”>
<display-name>DisplayTagDemo</display-name>

<!– Filter for the export, need that when using Struts and tiles –>
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>

<!– Filter mapping for the export –>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

<!– Struts servlet –>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<!– Standard Action Servlet Mapping –>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<!– Struts Tag Library Descriptors –>
<taglib>
<taglib-uri>/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

<!– DisplayTag –>
<taglib>
<taglib-uri>/displaytag.tld</taglib-uri>
<taglib-location>/WEB-INF/displaytag.tld</taglib-location>
</taglib>

<!– JSTL Core Tag –>
<taglib>
<taglib-uri>/c.tld</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>

</web-app>

If you don’t want to export the data you don’t need to include the filter.

#3 – Create your Actions if you want to use Struts. I won’t list the files here, but you can check the source code. Nothing special to explain.

#4 – the fun part. The DisplayTag in the JSP.

<display:table name=”sessionScope.searchResults” export=”true” uid=”uid” defaultsort=”0″ defaultorder=”descending” requestURI=”sort.do”>
<display:column sortable=”false” media=”html” title=”" ><c:out value=”${uid_rowNum}”/> </display:column>
<display:column sortable=”true” property=”name” title=”Name” headerClass=”sortable”/>
<display:column sortable=”true” property=”lastname” title=”Lastname” headerClass=”sortable”/>
<display:column sortable=”true” property=”age” title=”Age” headerClass=”sortable”/>
</display:table>

That need some explanations.

In the first line you have to use the field name to tell what is the LIST that contain the data. Here my demo, I put the list into the session.

The field export is use when you want to allow the data to be exported.

The field uid is needed when you want to generate a unique id for each row.

The fields defaultsort and defaultorder are used for sorting

The field requestURI is important when you sort the data. You need to tell to DisplayTag where the request will be forwarded after sorting the data. If you are using Tiles, you need an action that will forward to the JSP. That was the tricky part.

After that you select which columns to show for your table and which column you want to be sortable. One particular field is media. You select where you want to show this column. If you put media=”html” it will be displayed in the browser, but won’t be exported. If you put media=”html pdf” it will be displayed and exported but only for pdf.

#5 – sorry no #5. It’s not more complicated than that. You can customize the css of DisplayTag of course.

For more details start by looking at the source code and for DisplayTag documentation go here.

The next step should be to create a jMaki widget to do the same thing.. maybe another time.

Categories: Web Tags: , , ,

Joomla on Glassfish

May 24th, 2010 No comments

I’ll show you in this article how to setup the CMS Joomla on Glassfish. We won’t need Apache for this one. There are few ways to do PHP on a J2EE server. I’ll describe what I think the easiest way. First we will need to download and install PHP using PHP/JavaBridge (or you can use Quercus too here the link http://quercus.caucho.com/.

You can download PHP from this site http://www.php.net/downloads.php . I recommend to install it by the installer (if you use Windows).

After that you install PHP, you will have to add a system variable : PHP_HOME=path of php installation (ex : PHP_HOME=c:\php). You also need to add PHP in your path : (Windows : ;%PHP_HOME% ).

Now download the project PHP/JavaBridge from there web site : http://php-java-bridge.sourceforge.net/doc/ . Once you have the zip file of the project, you will have to extract it. You will obtain a file named : JavaBridge.war with others, but this file is the most important for the following steps.

Now that we have PHP install and the PHP/JavaBridge project, we can now starts intalling Joomla on Glassfish. Like I said in the beginning, I choose the most easiest way, so it’s not the most efficiant, (will you understand when you will see the next steps), but it will show you how it’s done.

Extract the file JavaBridge.war (Follow the same procedure for Quercus). Now copy the files and folders that are in the root of your Joomla site. Example : htdocs/joomla/ into the JavaBridge folder. (or copy the folder joomla into JavaBridge/Joomla but that will require more setup to do in Glassfish if you don’t want to URL to contain …/Joomla. I won’t convert it in this article).

Here the complete list of the files and folder into my JavaBridge folder. (of course that need a cleanup, but it’s just to show you that it can be done)

.htaccess
administrator
cache
CHANGELOG.php
components
configuration.php
configuration.php-dist
COPYRIGHT.php
CREDITS.php
documentClient.php
excel.php
hello.php
htaccess.txt
images
includes
index.php
index2.php
info.php
INSTALL.php
installation_
java
jsp+php.jsp
jsr223.jsp
language
libraries
LICENSE.php
LICENSES.php
locale
logs
MANIFEST.MF
media
metaconfig.xml
modules
numberguess.jsp
numberguess.php
plugins
robots.txt
sessionSharing.jsp
sessionSharing.php
settings.php
sitemap.xml
source.php
T.TXT
templates
test
test.php
TestInstallation$1.class
TestInstallation$2.class
TestInstallation$SimpleBrowser.class
TestInstallation.class
tmp
WEB-INF
xmlrpc

After that you obtain this ugly structure… compress it back into a .war. I’ll named it JavaBridge2.war.

Now the last step. Deploy it on Glassfish. Log into the admin web page and select deploy a war. Browse for JavaBridge2.war and deploy it.

Let take a look of the admin of Glassfish once JavaBridge2.war is deployed.

and the final touch.. See Joomla Live on Glassfish my entered the URL : http://localhost:8888/JavaBridge2 (8888 is my port of GF.. your should be 8080)

I hope that can help you to see are easy it can be to do PHP into Glassfish. The next step should be to benchmark Joomla on Glassfish with JavaBridge VS Joomla on Apache.

Categories: Glassfish, Web Tags: , , ,

Setup dynamic domain name when your ISP block 80's port

May 24th, 2010 No comments

For those that have a dynamic IP, it’s really hard to setup a web site with a domain name, if your provider blocks the 80 port. Most of the time, you will register to a free dynamic domain name like no-ip.com, dyndns.com. The problem is when you want to purchase a static domain name like mydomainname.com and what that domain name to be indexed byt Google, Yahoo and the others. If you go with the basic settings that came with the free services and theses dns providers, you will have a setup like that.

dynamic-dns.no-ip.com -> your IP : port like this : 222.222.222.222:8080 (remember that your port 80 is blocked).

If you want to add your static domain name it’s become more complicated. You will have to use a URL forwarding service. Most of the free dynamic dns offers that service, but some of them will add a banner and a frame that contain ads. But there always offer a real URL forwarding service for money :) . Take a look of what you will obtain with the URL forwarding.


yourdomainname.com -> dynamic-dsn.no-ip.com

dynamic-dsn.no-ip.com -> your IP : port like this : 222.222.222.222:8080

so if I use enter the URL : http://yourdomainname.com the request will be forwarded to this address : http://222.222.222.222:8080 that’s not what you need, if you want to index your site. You want to keep your domain name. The dns provider can offer you a “Cloaking URL” within the URL forwarding service. You will obtain the URL you entered : http://yourdomainname.com BUT, there will be something added to your url (depends of the dns provider). Example : http://yourdomainname.com/blog/page1.html can become : http://yourdomainname.com?id_page=blog_page1_html and it will become even more complicated with the links in your web pages.

Here what I did :

I first purchase my domain name : sebastiendionne.ca (I choose Namespro.ca, because I wanted a .ca, and not .com and they answer my questions the same day and the answer were accurate. I’m still wanting answer from others company (I can’t imagine what support that I’ll had receive from them after…). You can take a look if you want, and I’ll show you later how to setup the forwarding. <b><font color=”#D80000;”>Namespro.ca</font> – Register your domains for $12.88 CDN.<br>CIRA certified. Lowest price in Canada. Click here.</b> or try to find for fun if your domain name is available. (go.. use your imagination.. after that I’ll go in more detail how to setup everything)

OK, time to be serious. What we need after register your domain name it’s a URL forwarding service. Something your dns provider will be able to offer you that service. I use DnsExit for this service. For the same reason as Namespro.. the support was fast and accurate and it’s cheap.

I’ll explain how to setup your service with DnsExit. First, you will have to create a account for your static domain name. After that your account is created, you will have a Domain DNS in DnsExit for the port 80. You need to create a second entry for URL forwarding for your web port, like 8080.

example of what you will obtain

yourdomainname.com -> 64.182.102.186 (IP of DnsExit)

www2.yourdomainname.com (you choose what you want, it’s this URL that will appear in the browser) -> your IP : port like this : 222.222.222.222:8080

You can setup multiple dns entry like : yourdomainname.com, and www.yourdomainname.com

After setuping your URL Forwarding service, you need to go to use Dns provider account (mine is Namespro), and change the dns name server for

ns1.dnsExit.com (69.57.160.118)
ns2.dnsExit.com (64.182.102.188)
ns3.dnsExit.com (64.182.105.8)
ns4.dnsExit.com (74.218.158.84)

That’s it. It can takes few hours to update the domain names into the dns around the world.. but it will works.

With this procedure can you setup a web server on your computer with a dynamic IP and without using the port 80, and when you buy a hosting service for your web site, you won’t have to reindex your web site into Google and Yahoo, and you won’t loose your stats. I hope that will help someone out there.

Categories: Web Tags: ,

Apache + Glassfish + Subversion + Joomla

May 24th, 2010 No comments

I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll explain in this article how to setup Apache and the configuration of Apache to setup a web server. I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll setup Apache with Tomcat, Glassfish, Hudson, Subversion, PHP and Joomla. It” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s a quick guide how to setup everything, you could have to change some settings to reflect your configuration.

Take a look of the applications that will be installed

  • Apache
  • Php
  • PhpMyAdmin
  • MySQL
  • Glassfish
  • Tomcat
  • Subversion
  • Hudson
  • Joomla

First, We will have to download the applications. (Only download what you need).

Download applications

Apache

To simplify the installation and configuration process, I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll use an ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”all in one” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)” setup : xampp. You can download it here.

Tomcat

If you need Tomcat 6.0.14 , you can download the addon for xampp here , or download it from Jakarta here.

If you want Tomcat or Glassfish you will need a JDK. You can use the latest JDK 6 here or try JDK 7 here.

Glassfish

You can download binaries of Glassfish from here or the latest version from svn. (If you want to do this step, you will need Maven 2.0.7 here). There is a really good procedure from Sun here for building from the sources.

Hudson

You can download it here.

Subversion

Subversion server can be download from here. We will need an addon for Apache, that can be download here.

Joomla

To download Joomla go here.

Installation and configuration

Apache

When you use the installer from xampp, it” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s very easy to install. Just follow the wizard. When the installation is done, you need to change the default security settings. Follow this guide.

You could have to modify httpd.conf if you install the others applications. I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll explain it in the appropriate application” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s configuration.

Tomcat

Once you have installed Tomcat, you need to configure Apache to redirect the Url to Tomcat. You need to activate the module mod_jk in httpd.conf of Apache. (If you used the Tomcat module for xampp, it will be already activated).

Add this line at the end of httpd.conf :

Include conf/extra/mod_jk.conf

and create the file if is not there and put this in the file.

<IfModule !mod_jk.c>
LoadModule jk_module modules/mod_jk.so
</IfModule>

<IfModule mod_jk.c>
JkWorkersFile ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”C:/www/tomcat/conf/workers.properties” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”
JkLogFile ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”C:/www/tomcat/logs/mod_jk.log” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”
JkLogLevel info
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# Alias /examples ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”C:/www/tomcat/webapps/examples” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”

#<Directory ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”C:/www/tomcat/webapps/examples” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”>
# Options All
# </Directory>

# here it” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s the url that will be forwarded to tomcat
JkMount /*.jsp ajp13
JkMount /examples/* ajp13

</IfModule>

Please take a look at the line :

JkWorkersFile ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”C:/www/tomcat/conf/workers.properties” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”

This line is the configuration for the module in Tomcat. You configure the port, load balancing… (Tomcat have a complete documentation with example here). Tomcat have a ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”auto config” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)” if you want to keep it simple.

here a sample

worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

Subversion

I recommend that you start by reading this good guide.

You will have to edit the httpd.conf of Apache.

Add theses lines at the end : (don” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t forget the replace settings that represent your setup)

# Subversion
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /svnrepository>
DAV svn
SVNPath ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”c:/www/Subversion/repository” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”
#SVNParentPath ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”c:/www/Subversion/repository” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”
#SVNIndexXSLT ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”c:/www/Subversion/repository/svnindex.xsl” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”
SVNAutoversioning on
</Location>

I suggest to install a Subversion client, it will be easier to configure and create repositories. I use TortoiseSvn and Eclipse (SVN plugin).

Joomla

To install Joomla, it” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s really simple. Unzip the installation file into the document root of Apache (if you don” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t know, check the for the line : DocumentRoot in httpd.conf).

After that, start a browser and enter this URL (need to reflect your configuration) :

http://localhost:80/joomla/

you will be forwared to the Joomla Setup. Just follow the wizard, and when your setup is completed, you will have to delete the folder …/Joomla/installation

Glassfish

To install Glassfish, you have multiples options. I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll recommend the easiest way for your first time. Install the Glassfish with the Installer, just follow the wizard. Don” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t forget.. You need the JDK for that.. not the JRE!

If you prefer bulding Glassfish from the sources, you can follow this excellent guide.

You can configure Glassfish in Apache using mod_jk (like Tomcat) or use mod_proxy.

If you use mod_jk, you won” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t use the full connectivity power of Glassfish, but it will works. I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll explain how to configure both of them. Just for your information, I prefer the mod_proxy config.

Mod_jk setup

Please read the config for Tomcat in this article and go to this post from Jean-Francois Arcand here.

This procedure works for Glassfish 2.1. At this moment, it doesn” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t work for the latest version of Glassfish. There is a open bug for that.

And your need to log into the Glassfish console admin. Go into the section : Application Server, JVM Setting. Add this line :

-Dcom.sun.enterprise.web.connector.enableJK=8009

Mod_proxy setup

Open httpd.conf of Apache and add theses lines at the end :

LoadModule proxy_html_module modules/mod_proxy_html.so
Include conf/proxy_html.conf

ProxyPreserveHost on
RewriteEngine on

# example of web application installed on Glassfish
#RewriteRule ^/hudson$ /hudson/ [R,L]
#RewriteRule ^/hudson/(.*) http://localhost:8888/hudson/$1 [P,L]

you can get the file : conf/proxy_html.conf

ADMIN GUI

It” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s possible that you don” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t have the admin gui console bundle with your installation. You will need to install it. You can let Glassfish auto-install it for you (Recommended), or install it yourself. Right now there is a bug on the build that I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”m testing, so I have to install it myself. I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”ll describe the both ways.

Auto-install

Enter the URL : http://localhost:8080 (it the port you choose). You should get a welcome page : Your Application Server is now running. Click on the link : To manage the server, click here. You will be redirect to : http://localhost:8080/admin

it the console is not install, you will be able to install it from there, just follow the steps. Like I said, I” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”m not able to install it from there, so is you are in the same situation.. go to the next step.

Manually

Download the admin.war from Glassfish site. You can have the latest promoted test build here : http://download.java.net/glassfish/v3/admingui/

Once you have downloaded the war..

copy it in the folder glassfish/bin

open a command line : asadmin deploy -p 8080 admingui-v3-prelude-b20.war

that will install it and it will be accessible with this link : http://localhost:8080/admingui-v3-prelude-b20/

Hudson

To install Hudson into Glassfish it” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”s really easy. Log into the Glassfish admin console or by command line.

You can deploy the war with the command line, like the Glassfish admin gui installation or use GF admin to deploy it. I prefer the Gui. Open Glassfish admin and click on Deploy war application. Click on browse and followed by OK. That it. The application will start automaticaly. You will be able to access it by : http://localhost:8080/hudson

PS. There is a bug in the admin gui. If your port is not 8080, when you click on the ” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)”launch” onclick=”return TrackClick(” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”" onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”,” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”%2F%2Ftortoisesvn.tigris.org%2F” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”)” link for an application, it won” onclick=”return TrackClick(”,’%2F%2Ftortoisesvn.tigris.org%2F’)”t use your custom port. It will open it using the port 8080, that you will have th edit the URL to reflect your port. That should be fixed in V3.