Monday, June 11, 2012

ColdFusion 10 and AJAX HTTP POST Request hangs

For the past few days I was working on an old application that now runs on ColdFusion 10 in my test environment and all the Ajax calls where just hanging with no response. The funny thing, is in the production server which is CF 8 everything was working fine and in 9 they worked as well as my development server was 9 before. After a little debugging I noticed the problem was because we had the calls being sent as HTTP POST request rather than GET. Now I remember the reason for doing this was an IE issue with caching that would be fixed by making the calls as POST rather than GET.

So how come ColdFusion 10 fails, well it is quite weird. First I will show you an example of how our calls where structured.

First our test CFC (ajax.cfc) we will use an example.


As you can see it is quite simple. We have a function called TestCall which requires an argument called name and then returns a struct with the name value back in it. Real simple just for this simple test.

Now below is an example of how our calls were structured.


As you can see we saved our CFC's url into a global variable in case we used it more than once, then our params in an object that get passed in the simple jQuery ajax function. At success I am just dumping our response to the console log. Absolutely nothing wrong here but in ColdFusion 10 this would just hang. Below is an example with 3 different calls and the firebug output for a better visual representation.




As you can see our first call is just hanging and honestly never responds and the following 2 do work. The difference between each, is that the second request is made as a GET HTTP request and the third is a POST but with the method name in the URL portion rather than as a POST param. So to me it appeared that CF is now only looking for a method definition in the GET (URL) scope and if passed in the POST (form) scope, it just didn't know what to do. As you can see I thought I had it solved but then one thing happened by mistake. As I was writing this post I forgot to add the wsdl to the URL and everything worked.




This time everything worked. Now when I started playing with AJAX a couple of years back it was my understanding that we had to append WSDL to our CFC request but it appears it is not needed and by removing this everything worked fine in 10. So if you are experiencing this same issue do 1 of 2 things.

  1. Remove WSDL from your URL if you have it
  2. Make sure the method request is in the URL portion in a POST request

Hope this helps someone from pulling out as many hairs as I did .. good night world!

Wednesday, June 06, 2012

ColdFusion 9, Mac OS X 64 Bit, missing intel-macosx64

So today, I reinstalled ColdFusion 9 on my Mac so I can have both 9 and 10 running. As fas as my apache server, I have 2 config files that I choose which to use depending on which version of CF I want running (note you can use the buit in webserver and avoid this). Anyways, while I was doing this, I referenced Andy Allan's instruction on how to bypass wsconfig. Now everything is pretty straight forward and it all works fine except the the 64 bit installer is missing the 64 bit connector in the wsconfig.jar file. Basically the following directory connectors/apache/intel-macosx64/ is not in the jar file, you actually have to go get the wsconfig.jar file from hotfix CVE-2009-1876 which is part of Adobe Security Bulletin APSB09-12. I know, it is frustrating but at least there is a solution :-).

Directory named manager in webroot not accessible in ColdFusion 10

So today I ran into another little ColdFusion 10 related problem. I am not calling it a bug because I guess it has its purpose but I am calling it a problem, because it has now become something I need to figure what to do with. Apparently if you have a site with a directory named manager from the root, so /manager/ you will get a 404 from Tomcat like displayed below.



Apparently Tomcat is giving another directory precedence over my local /manager folder. Now the fix is really easy, just rename my folder and all works but I wanted to find out what folder Tomcat was running instead of mine. After some tinkering, the folder is located in (based on single server install) ColdFusion10/cfusion/runtime/manager/. I believe this folder is for the Tomcat manager app, which I don't know much of since this is my first time really working with Tomcat so it is all a learning experience. Now, if I rename this folder to something other than manager and restart ColdFusion, then everything works great but I don't know if this will have a negative impact on ColdFusion. This is a development server so I will continue to play and test but maybe someone smarter will be able to comment here.

A couple of things I tried is doing a rewrite, but if the folder in the end that you are pointing to is /manager at your webroot it will fail but a manager folder 1 level or more deep is fine. So /app/manager/ will work without any problems.

I thought this was quite weird and some people may ask why did I call the directory /manager but at the time when this particular app was built it is what seemed right. Hope this answers someone else similar issue with a simple Google search.

Friday, June 01, 2012

You are not going crazy CGI.PATH_INFO is empty in ColdFusion 10

Well I think the subject says it all. Today I upgraded my development and new production server to ColdFusion 10 and to my surprise a variable I was relying on to manage my routing is being passed empty on all requests. After a little googling I stumbled upon this page over at RIA Forge which stated this.

RIA Forge Page

Now I didn't just want to rely on that alone so I decided to do a test on all 3 servers I have, 8, 9 and 10 with the same page showing the same information (ColdFusion Version Number, CGI.PATH_INFO and CGI.SCRIPT_NAME)


Windows 2003, IIS 6, ColdFusion 8



Windows 2003, IIS 6, ColdFusion 9



Windows 2008 R2, IIS 7.5, ColdFusion 10



As you can see the third one does not show the cgi.path_info variable. So stop pulling your hair out and thinking it is more than just what it is. Apparently from IIS7 to Tomcat this just does not get passed. But I decided to do one more test on my Mac and it appears it is not only IIS7 but Apache is also affected and this variable is not being passed. So if you really need this and you are going to 10 lets hope the Tomcat team does something to remedy soon or come up with a different solution. Remember there is always more than 1 way to skin a cat.

Mac, Apache, ColdFusion 10



Code Example

Below is what I did to work with this issue in a current project. Since several developers using different platforms are on this single project I wrote it with that in mind. Basically save the final variable output into the request scope in case I need it anywhere else thru the request. This is set on the onRequestStart function of my APplication.cfc



Update

This is an output of what I use to get from CF9 using cgi.path_info, check out the URL and the output.



BTW * the domain used is not a real one, this is a local url I defined in my host file, in case anyone tries to go to it :). giancarlo.com actually belongs to someone else.