wiki:DJWS

DJWS: Standalone webserver for rapid application testing

Inside the GCC project, you will find a folder called webserver. This is a fully functional, custom-written webserver in Java, nicknamed the 'DJWS' (danny joeri web server). It currently takes 3 seconds (could be faster if we rework certain servlets) to start up, and 1 second to kill. This means it's exceptionally suitable for rapid testing of web applications, because servers like Tomcat are much more 'heavyweight' and generally much slower to start and stop due to smart caching and other advanced features.

It is ready for use (after step 1), just run 'RunStandalone.java' as a Java application and you're set. You only have to restart when Java code is changed, do this by terminating the process and hitting start. (run Java app)

However, there are three important things to notice!

Say you are working on an application named "My Application", or 'myapp' for short.

1) The default way of getting the datasource is in Tomcat is from the servlet context

In order to use DJWS, you must add the following line to your 'myapp.properties' file and regenerate:

db_mode = standalone

This places the datasource settings inside your MolgenisServlet. (see how this works: MolgenisServletGen) This ALSO works for deploying on Tomcat, so there is no backward compatibility issue.

2) Your MOLGENIS name determines the deploy URL

The so-called MOLGENIS name of your application is used to form the URL on which it is server. This name taken from the datamodel files, the last one encountered is used. Since our datamodels are shared, you can't just put your app name in one of them.

So if you want to have your application served on such location:

http://localhost:8080/myapp/molgenis.do

You must include an endpoint XML file in your 'myapp.properties', e.g:

model_database =	handwritten/datamodel/shared/auth.xml,\
			handwritten/datamodel/shared/core.xml,\
			#### all my datamodel files etc ####
			handwritten/apps/org/molgenis/myapp/myapp_deployname.xml

Which typically contains:

<molgenis name="myapp" label="My Application">
</molgenis>

The MOLGENIS name is now 'myapp', retrieved from the MolgenisServlet by MolgenisServlet.getMolgenisVariantID() in the mapper.

Note: this mechanism is extremely useful for letting the 'outside world' know where your application is located, and is also makes deployment under different names very easy. Just 'hot' edit the MolgenisServlet and export a WAR file with the same name.

3) Custom servlets

To avoid editing hardcoded mappings in the WWWServer mapper class, we decided to add a dynamic component. Any Java class in handwritten/java/servlets (link) is considered a servlet, and automatically loaded.

The filename is used as the servlet name! So for example, 'AddEventMenuServlet.java' will be served on http://localhost:8080/myapp/AddEventMenuServlet. The mapping recurses through all packages within handwritten/java/servlets, so this can be kept tidy in e.g. a package for each application. (though not needed maybe)

So add your own servlets by putting them somewhere in handwritten/java/servlets, with a filename under which you'd like to have it deployed also.

Last modified 13 years ago Last modified on 2011-02-01T14:50:51+01:00