In my previous post regarding Railo and Aptana Cloud, I left off dealing with SES-style URLs not being processed by Tomcat. After much research (Google, forum threads, etc.), I learned this is an issue with Tomcat itself...sort of.
On Aptana Cloud, Apache's role, as I understand it, was simply to pass all requests to Tomcat, which is the HTTP server on the site. This is a smart design since Tomcat for a single site/application will perform better than Tomcat connected to Apache via a module, such as mod_jk.
Well, the downside is that Tomcat cannot properly parse SES URLs, more specifically, it has an issue with some wildcard characters in it's web configuration file that we'd need to use for SES URLs.
I should clarify something. Tomcat parses URLs correctly, following the URL specification. However, many dynamic web applications use URL in a different way. Specifically, many of our dynamic applications use the URL as a set of instructions to the application and not as a reference to an actual resource (file or directory) on the server.
For example, in a ColdBox application, uses a URL such as the following:
http://www.mysite.com/pages/view/3
There's not actually a directory on the server named 3 that resides in a directory called view that resides in a directory called pages. This URL is merely an instruction to the ColdBox framework. It's saying (in essence): find the pages controller, run the view method and pass the view method the value 3. In English, it's a (very) basic way of saying show me a page in the database that has an ID of 3.
Tomcat, however, sees the URL above indicating that the user wants (is requesting) an actual resource on the server. It will try to find the folder 3 inside a folder called view inside one called pages. Attempting to access a similar URL to the one above on my Cloud site results in a 404 error (resource/file not found).
The 'problem' is that when you set up the servlet mappings in Tomcat's web.xml file for Railo (Railo is but a servlet that Tomcat tells to handle any and all CF-related requests) Tomcat does not hand off URLs such as these to Railo for processing, instead processing them itself.
In the Tomcat web.xml file, there is a servlet mapping element (can be many of them, actually), each with a url pattern element that instructs Tomcat to hand off certain URLs to a particular servlet. I'm saving the detailed code for my next post but here's a sample:
This instruction tells Tomcat to hand off any URL with .cfm at the end to Railo, which is the CFMLServlet. It works great when you actually use CFM pages in your URL (www.mysite.com/page.cfm or www.mysite.com/page.cfm?id=3).
If you don't use CFM files in your URL as the above, you're hosed :). Well, kind of.
Ideally, and what some other Java-based servers allow (jboss is an example), is that we'd tell Tomcat to pass any URLs matching *.cfm/* off to Railo.
The added /* would ensure that URLs such as the one above get passed to Railo for processing (and are thus not processed by Tomcat). Unfortunately (for me, anyway), Tomcat doesn't do this.
The solution (for now) is to create some URL rewrite rules, such as is done with IIS or Apache to create SES URLs on those servers. Because Aptana Cloud is setup such that Tomcat handles the HTTP requests, using Apache's mod_rewrite (a powerful URL rewriting module) is not possible.
A little Googling turned up a utility called UrlRewriteFilter. This, in essence, was created to replace many of the features of Apache's mod_rewrite. It's not a duplication of mod_rewrite and some key elements are missing. However, it does let us get URL rewriting working on Tomcat.
I'm still working on my rewrite rules and trying to optimize them, work out kinks, and look for genuinely good alternatives. My next post will cover those rules.
On Aptana Cloud, Apache's role, as I understand it, was simply to pass all requests to Tomcat, which is the HTTP server on the site. This is a smart design since Tomcat for a single site/application will perform better than Tomcat connected to Apache via a module, such as mod_jk.
Well, the downside is that Tomcat cannot properly parse SES URLs, more specifically, it has an issue with some wildcard characters in it's web configuration file that we'd need to use for SES URLs.
I should clarify something. Tomcat parses URLs correctly, following the URL specification. However, many dynamic web applications use URL in a different way. Specifically, many of our dynamic applications use the URL as a set of instructions to the application and not as a reference to an actual resource (file or directory) on the server.
For example, in a ColdBox application, uses a URL such as the following:
http://www.mysite.com/pages/view/3
There's not actually a directory on the server named 3 that resides in a directory called view that resides in a directory called pages. This URL is merely an instruction to the ColdBox framework. It's saying (in essence): find the pages controller, run the view method and pass the view method the value 3. In English, it's a (very) basic way of saying show me a page in the database that has an ID of 3.
Tomcat, however, sees the URL above indicating that the user wants (is requesting) an actual resource on the server. It will try to find the folder 3 inside a folder called view inside one called pages. Attempting to access a similar URL to the one above on my Cloud site results in a 404 error (resource/file not found).
The 'problem' is that when you set up the servlet mappings in Tomcat's web.xml file for Railo (Railo is but a servlet that Tomcat tells to handle any and all CF-related requests) Tomcat does not hand off URLs such as these to Railo for processing, instead processing them itself.
In the Tomcat web.xml file, there is a servlet mapping element (can be many of them, actually), each with a url pattern element that instructs Tomcat to hand off certain URLs to a particular servlet. I'm saving the detailed code for my next post but here's a sample:
CFMLServlet
*.cfm
This instruction tells Tomcat to hand off any URL with .cfm at the end to Railo, which is the CFMLServlet. It works great when you actually use CFM pages in your URL (www.mysite.com/page.cfm or www.mysite.com/page.cfm?id=3).
If you don't use CFM files in your URL as the above, you're hosed :). Well, kind of.
Ideally, and what some other Java-based servers allow (jboss is an example), is that we'd tell Tomcat to pass any URLs matching *.cfm/* off to Railo.
CFMLServlet
*.cfm/*
The added /* would ensure that URLs such as the one above get passed to Railo for processing (and are thus not processed by Tomcat). Unfortunately (for me, anyway), Tomcat doesn't do this.
The solution (for now) is to create some URL rewrite rules, such as is done with IIS or Apache to create SES URLs on those servers. Because Aptana Cloud is setup such that Tomcat handles the HTTP requests, using Apache's mod_rewrite (a powerful URL rewriting module) is not possible.
A little Googling turned up a utility called UrlRewriteFilter. This, in essence, was created to replace many of the features of Apache's mod_rewrite. It's not a duplication of mod_rewrite and some key elements are missing. However, it does let us get URL rewriting working on Tomcat.
I'm still working on my rewrite rules and trying to optimize them, work out kinks, and look for genuinely good alternatives. My next post will cover those rules.