Step 5: Create Submission Form

This part of the tutorial steps you through the process of creating a simple Web submission form that accepts input from a user and then publishes a submissionReceived event that Metis will use to activate the workflows created in Step 3 of this tutorial. As such, this part of the tutorial occurs outside of Metis, but not outside of Tomcat. Since you are already using Tomcat to host Metis, we will simply create a new Web application in your Tomcat environment to implement the Web submission form.

Work Avoidance: If you do not want to create the files listed below, you can download the "Julia Child's" version of this step. Uncompress this tar file and expand its contents within your <$CATALINA_HOME/webapps/> directory. Then, scroll down to see how much work you saved! :-)

1. Create a new directory, named examDL in <$CATALINA_HOME/webapps/>.

2. Create a file called confirmation.html within the examDL directory. The contents of this file appear below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Submission Received</title>
</head>
<body>
    <h1>Submission Received!</h1>
    <p>Your paper has been submitted. An action editor will contact you shortly.</p>
</body>
</html>

3. Create a file called problem.html within the examDL directory. The contents of this file appear below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Problem With Submission</title>
</head>
<body>
    <h1>Problem With Submission</h1>
    <p>There was a problem with your submission. Go back to the
       submission form and ensure that all fields have been filled out properly.</p>
</body>
</html>

4. Create a file called index.html within the examDL directory. The contents of this file appear below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Submission Form</title>
</head>
<body>
    <h1>Submission Form </h1>

    <form action="controller" method="get">

    <table border="1">
        <tr>
            <th>Contact Author</td>
            <td><input type="text" name="contactName" /></td>
        </tr>
        <tr>
            <th>Contact Author Email</td>
            <td><input type="text" name="contactEmail" /></td>
        </tr>
        <tr>
            <th>Paper Title</td>
            <td><input type="text" name="title" /></td>
        </tr>
        <tr>
            <th>Author List</td>
            <td><input type="text" name="authors" /></td>
        </tr>
        <tr>
            <th>Topic Area</td>
            <td>
                <select name="area">
                    <option value="none">Select a Topic Area</option>
                    <option value="physics">Physics</option>
                    <option value="chemistry">Chemistry</option>
                    <option value="geology">Geology</option>
                    <option value="biology">Biology</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>URL of Submission</td>
            <td><input type="text" name="url" /></td>
        </tr>
    </table>
    <br />
    <table>
        <tr>
            <td>
                <input type="submit" name="submission" value="Submit Paper" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

5. Create a directory called WEB-INF within the examDL directory.

6. Create a file called web.xml within the WEB-INF directory. The contents of this file appear below. Note: You may have to modify the value of the httpHost context parameter to match your local Tomcat configuration.

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>Submission Form</display-name>

    <context-param>
        <param-name>httpHost</param-name>
        <param-value>http://localhost:8080/</param-value>
        <description>The hostname and port of the HTTP server running Metis.</description>
    </context-param>

    <servlet>
        <servlet-name>submission_servlet</servlet-name>
        <servlet-class>metis.examples.submissionServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>submission_servlet</servlet-name>
        <url-pattern>/controller</url-pattern>
    </servlet-mapping>

</web-app>

7. Create a directory called lib within the WEB-INF directory.

8. Copy the files metis.jar and xmlrpc-1.1.jar from the <$CATALINA_HOME/webapps/metis/WEB-INF/lib/ directory into the lib directory created in step 7.

9. Create a directory called classes within the WEB-INF directory.

10. Create a directory called metis within the classes directory.

11. Create a directory called examples within the metis directory.

12. Create a file called submissionServlet.java within the WEB-INF directory. The contents of this file appear below. The code within the handleSubmission method demonstrates how to package up the values of the submission form and send them to Metis using the activate method.

package metis.examples;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.IOException;
import java.util.Hashtable;

import metis.util.Global;
import metis.workflows.execution.client.ExecutionAPI;

import org.apache.xmlrpc.XmlRpcClient;

public class submissionServlet extends HttpServlet {

    public void doGet(
        HttpServletRequest request,
        HttpServletResponse response)
    throws ServletException, IOException {

        boolean submitted = handleSubmission(request,response);

        if (submitted) {
            response.sendRedirect("confirmation.html");
        } else {
            response.sendRedirect("problem.html");
        }
    }

    public boolean handleSubmission(
        HttpServletRequest request,
        HttpServletResponse response) {

        String submission = request.getParameter("submission");
        if (submission != null) {
            Integer      paperId = new Integer(_id++);
            Hashtable    atts    = new Hashtable();
            ExecutionAPI api     = new ExecutionAPI();

            try {
                atts.put("area", request.getParameter("area"));
                atts.put("authors", request.getParameter("authors"));
                atts.put("contactEmail", request.getParameter("contactEmail"));
                atts.put("contactName", request.getParameter("contactName"));
                atts.put("id", "" + paperId);
                atts.put("title", request.getParameter("title"));
                atts.put("url", request.getParameter("url"));

                api.activate("submissionReceived", atts);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public void init() {
        _id   = 0;

        Global.httpHost = getServletContext().getInitParameter("httpHost");
    }

    private int _id;
}

13. Compile the submissionServlet.java file and place the resulting submissionServlet.class file in the <$CATALINA_HOME/webapps/examDL/WEB-INF/classes/metis/examples/> directory.

In order to compile this file, you will need to add the following jar files to your classpath:

You can do this from the command line like this (place the following all on one line, with no spaces between the colons):

javac -classpath $CATALINA_HOME/common/lib/servlet.jar:
$CATALINA_HOME/webapps/examDL/WEB-INF/lib/metis.jar:
$CATALINA_HOME/webapps/examDL/WEB-INF/lib/xmlrpc-1.1.jar
submissionServlet.java

14. You are now ready to try out the submission form and step through your first Metis workflow!