Ubuntu's tomcat5.5 package installs quite easily, and sets up a server at port 8180. I still have to figure out how to nicely integrate it with the Apache server on port 80, though. Suggestions much appreciated.
From then on, one can add new JSP pages by creating a 'webapp' in /usr/share/tomcat5.5-webapps. The basic structure looks like:
mb-examples.xmlJust copying the large CDK jar (the one with all the third party libraries) into WEB-INF/lib/ did not work for me, but unjaring it into WEB-INF/classes/ seem to work fine.
mb-examples/index.jsp
mb-examples/WEB-INF/
mb-examples/WEB-INF/classes/
mb-examples/WEB-INF/lib/
Then, you can just add Java code using the CDK library for what ever you like. The following (simple) example JSP page, takes one parameter, a molecular formula. This could be the input given in a FORM, but the below page does not deal with that situation yet:
<%@ page import="java.util.*,org.openscience.cdk.*,org.openscience.cdk.tools.*" %>Now, a lot of improvement can be achieved. For example, the <head> stuff can be split out in a header.include. And, after proper integration with the Apache server, rewrites could be used to create a REST service. But, the above is just to give you an idea.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<%
String mf = request.getParameter( "mf" );
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="E.L. Willighagen">
<title>Metabolomics Examples</title>
</head>
<body bgcolor="#FFFFFF">
<table>
<tr>
<td>Molecular Formula:</td>
<td><%= mf %></td>
</tr>
<%
MFAnalyser analyser = new MFAnalyser(mf, new Molecule());
double accurateMass = Math.round(analyser.getMass()*10000.0)/10000.0;
%>
<tr>
<td>Mono-isotopic Accurate Mass:</td>
<td><%= accurateMass %></td>
</tr>
</table>
</body>
</html>
In case you wonder, this work is related to the opensource MetWare database software development our group is involved in.
Regarding Apache and Tomcat http://cheminfo.informatics.indiana.edu/~rguha/misc/apachetomcat.html might provide some useful hints (though it's focused on web servcies)
ReplyDeleteRajarshi, thanx! That indeed sounds like the hints I am looking for.
ReplyDeleteBTW, I forgot to mention to make a symbolic link in /usr/share/tomcat5.5-webapps.
J2EE servers consist of two parts, EJB container and Web Container. EJB containers provide a runtime environment to the Enterprise Java Bean components holding the business logic, while the web containers hold the presentation logic in the form of servlets and Java server pages.
ReplyDelete