ConfiguringEC2Server

Cloud Server Setup
In order to set up the cloud-based COMTOR server (and interface), one needs an Amazon AWS account and an EC2 instance. Additionally the following AWS services are also used:
 * EC2 - You need an EC2 instance on AWS. We use Ubuntu, usually the latest and greatest version available. Microinstances are fine for our purposes at the current time.
 * SES - For email sending (used by the cloud interface and the API server version)
 * S3 - For storing COMTOR reports for up to 5 days (used by the cloud interface and the API server version)
 * SDB - For storing cloud usage data (used only by the cloud interface)
 * DynamoDB - For storing the API key data (used only by the API keygen web app)
 * SQS - used by the API for submitting work requests

Installation Summary
Using apt-get or aptitude (either in sudo mode) install the following software packages to a base Ubuntu server version of the operating system:

This should provide you with a Tomcat installation in the /usr/share/tomcat7/lib. (Note, if Tomcat is installed on a Mac, locally for testing/development, the likely home for Tomcat is /usr/share/tomcat7.) In this directory, we need to soft link to the lib* files installed above. The necessary libraries should be located in /usr/java/, so to perform the link, change into the Tomcat lib directory (cd /usr/share/tomcat7/lib) and then link as shown:
 * sudo ln -s ../../java/httpclient.jar
 * sudo ln -s ../../java/httpcore.jar
 * sudo ln -s ../../java/commons-codec.jar
 * sudo ln -s ../../java/commons-fileupload.jar
 * sudo ln -s ../../java/commons-io.jar
 * sudo ln -s ../../java/commons-logging.jar
 * sudo ln -s ../../java/jackson-core.jar
 * sudo ln -s ../../java/jackson-core-asl.jar

You also need to place a copy of tools.jar into this directory as well, so that COMTOR can programmatically call on the javadoc program code. If you installed the openjdk, we can to link in the tools.jar file that was installed. On the Ubuntu releases, this file can generally be found at /usr/lib/jvm/java-7-openjdk-i386/lib/tools.jar.

LibJackson 2.0
In addition to the apt-get installed Jackson Json library, we'll also need the 2.x version as well. Specifically, we require the core, annotations, and databind libraries.

CORS Support
We also need the CORS filter inserted into the Tomcat CLASSPATH so that we can support the use of the "Dispute" button on the HTML report pages generated by the system. Storing those pages on S3 and making them available for download (by the user after receiving an email from us via AWS SES) presents a Cross-Origin Resource Sharing (CORS) problem for us, as the web service to submit the dispute lies on our EC2 server(s). The CORS filter also requires the java-properties-utils.jar file, linked from the CORS download site.

Java Mail
We also need the Java Mail API to create email messages for sending in the servlet. There is no current apt package for this library, so you need to download the release from the Java Mail web site. The mail.jar file contained in the download also needs to be placed in /usr/share/java and then soft linked to the Tomcat common library area (/usr/share/tomcat7/lib).

reCAPTCHA Library
Used to validate API key generation requests, the reCAPTCHA project presents a Turing test to the requesting user (hopefully human) on the web-based interface to the key request (there's also an API POST service as well for the same reason). You'll need to include the reCAPTCHA jar file in the Tomcat library for runtime use.

AWS Java SDK
We'll also need the AWS Java SDK to make calls to the Amazon Web Services (AWS) that we utilize. You can download the latest SDK and place it in the Tomcat library area discussed above (/usr/share/tomcat7/lib).

Apache Log4J2
Throughout COMTOR, we use the Apache Log4j version 2.0 software. We'll need the latest libraries (as of 6/23/13, the beta7 release is corrupted, and we are using beta6). Download and unzip the release, and copy the following two .jar files and place them in the tomcat /lib area:
 * log4j-api-2.0-beta6.jar
 * log4j-core-2.0-beta6.jar

Configuration Summary
Next, place a copy of the AWS credentials file (APICredentials.properties) into the root directory of tomcat: (/var/lib/tomcat7). The contents of this file should look something like the following: Fill in your AWS Access Key ID and Secret Access Key accessKey = ABCDEF secretKey = ABCDEF456123
 * 1) http://aws.amazon.com/security-credentials

Be sure to change the ownership of the APICredentials.properties file to be that of tomcat7 (sudo chown tomcat7.tomcat7 APICredentials).
 * FYI, the tomcat7 configuration directory can be found at: /etc/tomcat7

Tomcat Commands and Locations To Remember

 * sudo /etc/init.d/tomcat start | stop | status | restart
 * Root application: /var/lib/tomcat7/webapps/ROOT/index.html
 * The Tomcat Manager:  :8080/manager/html

Configuring the Tomcat Roles
Edit the Tomcat config file (tomcat-users.xml) to add two roles and a user-administrator. This file is located in the Tomcat configuration directory (/var/lib/tomcat7/conf)  



Configuring the Tomcat Port
In order to change the response port for Tomcat (normally, port 8080), and response more like a traditional web server, you can edit the server.xml file located in the Tomcat config directory (likely /var/lib/tomcat7/configs). Look for the Connector section under the Catalina service definition. Change the Connector's port number from 8080, to 80, as shown below. Then, restart the server and Tomcat will accept requests on port 80, if no other application is bound to that port previously. 

Additionally, we need to edit /etc/defaults/tomcat7 and set the AUTHBIND line to AUTHBIND=yes. Be sure it is not commented out. For step by step directions see this blog. Though we don't need to apparently do the /etc/authbind file edits...