| 1 | = Standalone webserver = |
| 2 | Inside the GCC project, you will find a folder called [http://www.molgenis.org/svn/gcc/trunk/handwritten/webserver/ 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. |
| 3 | |
| 4 | It is ready for immediate use, just run '[http://www.molgenis.org/svn/gcc/trunk/handwritten/webserver/RunStandalone.java RunStandalone.java]' as a Java application and you're set. |
| 5 | |
| 6 | However, there are three important things to notice! |
| 7 | |
| 8 | ''Say you are working on an application named "My Application", or 'myapp' for short.'' |
| 9 | |
| 10 | 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: |
| 11 | |
| 12 | {{{ |
| 13 | db_mode = standalone |
| 14 | }}} |
| 15 | This places the datasource settings inside your MolgenisServlet. (see how this works: [wiki:MolgenisServletGen http://www.molgenis.org/svn/molgenis/trunk/src/org/molgenis/generators/server/MolgenisServletGen.ftl]) This ALSO works for deploying on Tomcat, so there is no backward compatibility issue :) |
| 16 | |
| 17 | 2) Your MOLGENIS name determines the deploy URL. |
| 18 | |
| 19 | 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. |
| 20 | |
| 21 | So if you want to have your application served on such location: |
| 22 | |
| 23 | {{{ |
| 24 | http://localhost:8080/myapp/molgenis.do |
| 25 | }}} |
| 26 | You must include an endpoint XML file in your 'myapp.properties', e.g: |
| 27 | |
| 28 | {{{ |
| 29 | model_database = handwritten/datamodel/shared/auth.xml,\ |
| 30 | handwritten/datamodel/shared/core.xml,\ |
| 31 | -- all my datamodel files etc -- |
| 32 | handwritten/apps/org/molgenis/myapp/myapp_deployname.xml |
| 33 | }}} |
| 34 | Which typically contains: |
| 35 | |
| 36 | {{{ |
| 37 | <molgenis name="myapp" label="My Application"> |
| 38 | </molgenis> |
| 39 | }}} |
| 40 | The MOLGENIS name is now 'myapp', retrieved from the MolgenisServlet by ''MolgenisServlet.getMolgenisVariantID()'' in the [[mappings http://www.molgenis.org/svn/gcc/trunk/handwritten/webserver/WWWServer.java]. |
| 41 | |
| 42 | 3) Custom servlets. |
| 43 | |
| 44 | To avoid editing hardcoded mappings in the [WWWServer http://www.molgenis.org/svn/gcc/trunk/handwritten/webserver/WWWServer.java] class, we decided to add a dynamic component. Any Java class in handwritten/java/servlets ([http://www.molgenis.org/svn/gcc/trunk/handwritten/java/servlets/ link]) is considered a servlet, and automatically loaded. |
| 45 | |
| 46 | The filename is used as the servlet name! So for example, 'AddEventMenuServlet' will be served on http://localhost:8080/myapp/AddEventMenuServlet. |
| 47 | |
| 48 | 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) |