Future of Taffy: SES url hack we're using is (sort of) going away

617 views
Skip to first unread message

Adam Tuttle

unread,
Nov 13, 2011, 2:05:26 PM11/13/11
to taffy...@googlegroups.com
Hi all,

So as you may be aware, Taffy currently works by routing every request through index.cfm, like so:


Even if you're using url rewriting, that is just making what the end user sees prettier (removes the /index.cfm/) but ultimately what's being sent to JRun/etc still contains it. For ease of discussion, let's call this "the path_info hack".

I can't necessarily say how I know this, wink-wink-nudge-nudge, but this may not be an option for all users going forward, in versions of ColdFusion after CF9. It's been publicly announced that the next version of CF will ditch JRun in favor of Tomcat, and the inside information is that the "server" install will still allow the path_info hack, via some voodoo that's being done with the Tomcat install... However... People who do a J2EE (EAR/WAR) install will not have this functionality (at least not as of the current version of the inside information). As far as I know, this also includes multi-instance installs.

The problem is that vanilla/core Tomcat does not see the stuff after index.cfm and put it in the CGI.PATH_INFO environment variable. Indeed, it may not function at all, as it sees all of that "stuff" as part of the file name being requested, and fails...

I've devised one proposed workaround, and I wanted to throw it out to the community and see (a) if you see any problems with this approach, and (b) if you have any better ideas.

My first thought was to adopt the twitter-style "hash-bang": http://api.example.com/#!/some/resource

...but the problem with this approach is that the url hash is a client-side only thing. It's not sent to the server. So I've come up with an alternative:


I included the second example just to illustrate that, while this is technically hijacking the query string and using it in a way other than it was intended, that doesn't mean we can't add a second "query string" on to the end of it, to specify arguments. Is it confusing to have the question mark in the middle like that? Would you rather see this more or less functionally equivalent syntax? 


Of course this is just what's being sent to the server. If you have URL rewriting available, you can still have your users see the same pretty URL:


There are three primary benefits to this approach that I like:
  1. Using ?/some/resource just takes things that were in CGI.PATH_INFO and moves them into the query string; so changes to the routing methods in Taffy will be minimal.
  2. Updating your rewrite rules and/or clients currently accessing your api's will be minimal... just replace "index.cfm/" with "?/".
  3. This appears to be fairly future-proof. I don't see them taking away CGI.QUERY_STRING any time <del>soon</del> ever.
Lastly, I'll pose this question to you:

Assuming I get Taffy 1.1 released by the end of 2011, would you rather see this included in Taffy 1.1, or hold it off until Taffy-next (either 1.2 or 2.0)?

Thanks so much!
Adam

Adam Tuttle

unread,
Nov 13, 2011, 2:16:48 PM11/13/11
to taffy...@googlegroups.com
I suppose if it came right down to it, we could always go with:


The one thing that bothers me about this is the potential for parameter name collision. If you ever name an argument "resource", then you'll have a problem on your hands. Getting more specific, like taffy_resource=/some/resource solves that problem, but makes urls even uglier for those without rewriting...

Adam

AJ Mercer

unread,
Nov 13, 2011, 5:28:35 PM11/13/11
to taffy...@googlegroups.com
Hi Adam,

I am running Taffy on Railo/ Tomcat & Jetty and it has the same issue that the next version of CF/Tomcat has that you described here

The issue is Tomcat (in fact most J2EE app servers have. I thought Jetty 7 was going but I have not seen it as yet) is you can not have multiple wildcards in the servlet mapping
eg *.cfm/*

So what we do
in <webroot>/WEB-INF/web.xml
ad the following

...
  <servlet-mapping>
    <servlet-name>CFMLServlet</servlet-name>

<url-pattern>/ajm/index.cfm/</url-pattern>
<url-pattern>/ajm/index.cfm/*</url-pattern>
<url-pattern>/taffy/examples/api/index.cfm/</url-pattern>
<url-pattern>/taffy/examples/api/index.cfm/*</url-pattern>
<url-pattern>/taffy/examples/consumer/index.cfm/</url-pattern>
<url-pattern>/taffy/examples/consumer/index.cfm/*</url-pattern>
<url-pattern>/ormBlog/api/index.cfm/</url-pattern>
<url-pattern>/ormBlog/api/index.cfm/*</url-pattern>
<url-pattern>/ormBlog/api2/index.cfm/</url-pattern>
<url-pattern>/ormBlog/api2/index.cfm/*</url-pattern>

  </servlet-mapping>
...
[full file (jetty) attached]
web.xml

Adam Tuttle

unread,
Nov 13, 2011, 7:03:16 PM11/13/11
to taffy...@googlegroups.com
Yep, that's the standard work-around I've been giving people so far...

Adam

Adam Tuttle

unread,
Nov 16, 2011, 8:22:13 PM11/16/11
to taffy...@googlegroups.com

Nobody has any opinions, good, bad, or indifferent?

Matt Gersting

unread,
Nov 16, 2011, 10:51:16 PM11/16/11
to taffy...@googlegroups.com
My two cents:

I've actually never been a fan of the PATH_INFO hack.  For two reasons: First, the word hack throws me off.  There's obviously a time and a place for them, but in general we all try to avoid them, right? Especially when, secondly, it doesn't REALLY get to us to the promise land in the sense of - that url isn't really that clean.  Anytime I use any product that routes through the index I always end up rewriting those URLs anyway so it doesn't reveal the underlying technology.  That's just me, though.

So, given the options presented I would absolutely throw my preferential weight behind option 3:

http://api.example.com/?resource=/some/resource&foo=bar

The hash tag, like you said, pushes it out of the query string, and option two is confusing as all get out.  Nothing wrong with a good old fashioned URL. They work for a reason and we can still rewrite them.

Barney Boisvert

unread,
Nov 16, 2011, 11:48:15 PM11/16/11
to taffy...@googlegroups.com
I vote for standard CFML-style URLs. Where you've attempted to get this:

domain.com/path/to/resource.json

just leave it like this:

domain.com/path/to/taffy/index.cfm?_resource=/path/to/resource&_representation=json

I've deliberately prefixed with underscore to help avoid the
collisions you mentioned before.

Yes, that's a hella ugly URL, but who cares. If you want pretty URLs,
there are myriad ways to get them, and better left to something more
suited for it than Servlet mappings, Application.cfc request thievery,
or JRun hackery. For example (using mod_rewrite):

RewriteRule ^(/path/to/[^.]+)(\.([a-zA-Z0-9])+)?$
/path/to/taffy/index.cfm?_resource=$1&_representation=$3 [PT]

Now the first URL will get to the second one. Or if you don't have
Apache and/or want to stay pure JEE, you can use UrlRewrite
(http://www.tuckey.org/urlrewrite/):

<rule>
<from>^(/path/to/[^.]+)(\.([a-zA-Z0-9])+)?$</from>
<to type="forward">/path/to/taffy/index.cfm?_resource=$1&_representation=$3</to>
</rule>

Same net result.

I should say that I gave up on PATH_INFO eight or nine years ago and
never looked back. It's probably been six or seven since I've even
seen a standalone CF install (the only place the JRun voodoo works).
Honestly, I've never missed it, and I refuse to believe that there are
a significant number of people who both a) don't use a webserver, and
b) can't drop in urlrewrite.jar and wire up the filter. If you can
tweak your web.xml, then you can add the UrlRewrite filter just as
easily as change the servlet mappings, so why not just do that?

The one sentence version is "it's pretty irrelevant what Taffy
supports because I'm not going to use it's in-built format for public
consumption" which I guess puts me in the indifferent camp.

cheers,
barneyb

--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/

James Eisenlohr

unread,
Jan 22, 2012, 6:48:26 PM1/22/12
to taffy...@googlegroups.com
Hi AJ,

I am trying to add the mappings that you state into the web.xml for Railo/Tomcat, but I am still getting a 404 anytime I try to use Taffy's mock client to run a get request. Does my mapping look correct?

/Library/Railo/tomcat/ROOT/WEB-INF/web.xml

   version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>

        <servlet-mapping>
                <servlet-name>CFMLServlet</servlet-name>

                <url-pattern>/experiments.com/api/v1/index.cfm/</url-pattern>
                <url-pattern>/experiments.com/api/v1/index.cfm/*</url-pattern>
        </servlet-mapping>

</web-app>

Thank you,

James

AJ Mercer

unread,
Jan 22, 2012, 7:12:00 PM1/22/12
to taffy...@googlegroups.com
try
<url-pattern>/api/v1/index.cfm/</url-pattern>
<url-pattern>/api/v1/index.cfm/*</url-pattern>

and you will need to restart Tomcat (not just Railo from within the web admin)

James Eisenlohr

unread,
Jan 22, 2012, 9:52:26 PM1/22/12
to taffy...@googlegroups.com
Thanks, AJ!

I restarted Railo from admin, restarted Tomcat from command line, updated the path of the mapping to your suggestion, restarted both Railo and Tomcat again, but I am still getting the 404 error. Not sure what to try now?

James

AJ Mercer

unread,
Jan 22, 2012, 10:03:38 PM1/22/12
to taffy...@googlegroups.com
which web.xml file are you editing?

I used the on in WEB-INF

James Eisenlohr

unread,
Jan 22, 2012, 10:05:03 PM1/22/12
to taffy...@googlegroups.com
I do have multiple sites setup with Railo... could this be the issue? I have the following files:

/Library/Railo/tomcat/webapps/ROOT/WEB-INF/web.xml

/Library/Railo/tomcat/webapps/ROOT/experiments.com/WEB-INF/railo/railo-web.xml.cfm

I've tried adding the mapping to both at same time and to one at a time (restarting tomcat each time), with no luck... :( 

James Eisenlohr

unread,
Jan 25, 2012, 5:27:17 PM1/25/12
to taffy...@googlegroups.com
Just so anyone looking knows, I was able to get Taffy working with Railo multi-site setup with a lot of help from AJ Mercer! Thank you!

Here was the solution:

1. Create a new web.xml file specific for the site I wanted to use Taffy with.
2. Put the following within this new web.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
   version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  <servlet-mapping>
       <servlet-name>GlobalCFMLServlet</servlet-name>
       <url-pattern>/api/v1/index.cfm/*</url-pattern>
    </servlet-mapping>
</web-app>

So for the url-pattern above, just place the path to your api and you should be good!

Thanks,

James


Adam Tuttle

unread,
Jan 25, 2012, 8:24:28 PM1/25/12
to taffy...@googlegroups.com
Just to clarify, this is not a Railo-specific issue, it's a Tomcat issue. If you were to install ACF on Tomcat you'd have to do the same thing.

Adam

James Eisenlohr

unread,
Jan 26, 2012, 8:38:39 AM1/26/12
to taffy...@googlegroups.com
Yes, thank you for the clarification, Adam! So this configuration will be required for CF10 (Zeus)... it will be running on Tomcat instead of JRun, correct?

AJ Mercer

unread,
Jan 26, 2012, 8:42:01 AM1/26/12
to taffy...@googlegroups.com
Zeus will be available on Tomcat.
I am not sure if Adobe is going to have multiple web contexts, but as I understanding it, the installation will be the same, that is, no messing around with XML configs (so just like the JRun installer).

On 26 January 2012 21:38, James Eisenlohr <jamesei...@gmail.com> wrote:
Yes, thank you for the clarification, Adam! So this configuration will be required for CF10 (Zeus)... it will be running on Tomcat instead of JRun, correct?



James Eisenlohr

unread,
Jan 26, 2012, 8:43:23 AM1/26/12
to taffy...@googlegroups.com
I really like the sound of that! :)

Brad Coughlin

unread,
Apr 26, 2012, 8:23:35 PM4/26/12
to taffy...@googlegroups.com
Thanks, James and AJ. This solution got me headed in the right direction. Also, thanks to Adam for pointing me to this group & thread. I'm sure I'll be visiting here often while I learn how to implement Taffy.

James Eisenlohr

unread,
Apr 26, 2012, 8:47:21 PM4/26/12
to taffy...@googlegroups.com
Great to hear! Good luck!
Reply all
Reply to author
Forward
0 new messages