Posted At : Feb 18, 2010 17:49 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects

ColdFusion is at version 9 already but we still seem to have problems where i would believe all has to be nice for years. I'm talking about CFHTTP tag here.
Yesterday i had to make for a client a script that will
  1. connect to a site
  2. login
  3. move to other internal page from where data should be taken

So what the usual process would be in such a case?
  1. make a CFHTTP request
  2. using the cookies from previous step, if any exists, make the CFHTTP call with login credentials
  3. using the cookies from previous step (here should be present session cookies), make the CFHTTP call to the internal page
  4. do with the data whatever you need
Sometimes step 1 may not be needed.

Everything looks fine so far and in most of the cases works as supposed, but NOT everytime. Sometimes on step 3 instead of going to the internal page it "lose the session" and as result you get there the login page instead. This is exactly what happened for me for this particular client. I have no idea what the problem is but i remember such an issue even back in 2003. I tried all i could think of: passing cookies in CFHTTPPARAMs, puttin the heder with cookies and all in USERAGENT parameter of CFHTTP (yes this one looks a bit weird, but i remember this solving the problem for some sites within last 7-8 years). Nothing helped. Then i tried CFX_HTTP that i was using years ago in such situations and of course everything worked great.

So the question is - WHAT THE HECK ?!
After so many years we still should have such problems with CFHTTP? Weird.

For this particular client it happened there to be a 64-bit system, so instead of CFX_HTTP i had to rewrite the script to use CFX_HTTP5. But this doesn't change the fact that it wasn't possible to be done with CFHTTP itself. Googling for solutions from other's experience didn't help. So i thought - if ColdFusion is Java, why not try a Java solution?
Another half day in googling, trying, testing and i've created a function that not only do a GET HTTP connection, but also works fine for the situation described above. It's far from being universal enough, but it worked well for my situation. So if anyone need it, here is the code:
<cffunction name="makeHTTPRequest" output="yes" returntype="any">
   <cfargument name="requestURL" required="Yes" type="any">
   <cfargument name="requestCookies" required="No" type="any" default="">
   
   <cfset var result = StructNew()>
   <cfset var i = 1>
   <cfset var urlConnection = createObject("java", "java.net.URL").init("#arguments.requestURL#").openConnection()>
   <cfset var inputReader = "">
   <cfset var bufferedReader = "">
   <cfif Len(arguments.requestCookies)>
      <cfset urlConnection.setRequestProperty("Cookie", arguments.requestCookies)>
   </cfif>
   <cfset urlConnection.connect()>
   
   <cfset inputReader = createObject("java", "java.io.InputStreamReader").init(urlConnection.getInputStream())>
   <cfset bufferedReader = createObject("java", "java.io.BufferedReader").init(inputReader)>

   <cfset result.headers = "">
   <cfset result.headerNoCookie = "">
   <cfset result.cookies = "">
   <cfset result.content = "">

   <cfscript>
      do
      {
         headerName = urlConnection.getHeaderFieldKey(i);
         lineCheck = IsDefined("headerName");
         if (lineCheck)
         {
            if (Len(result.headers))
            {
               result.headers = result.headers & "|" & headerName & "=" & urlConnection.getHeaderField(i);
            }
            else
            {
               result.headers = headerName & "=" & urlConnection.getHeaderField(i);
            }
            if (headerName.equals("Set-Cookie"))
            {
               result.cookies = result.cookies & ListGetAt(urlConnection.getHeaderField(i), 1, ";") & "; ";
            }
            else
            {
               if (Len(result.headerNoCookie))
               {
                  result.headerNoCookie = result.headerNoCookie & "|" & headerName & "=" & urlConnection.getHeaderField(i);
               }
               else
               {
                  result.headerNoCookie = headerName & "=" & urlConnection.getHeaderField(i);
               }
            }
         }
         i = i + 1;
      } while(lineCheck);
      
      do
      {
         line = bufferedReader.readLine();
         lineCheck = IsDefined("line");
         if(lineCheck)
         {
            result.content = result.content & line;
         }
      } while(lineCheck);
   </cfscript>
   
   <cfreturn result>
</cffunction>

It takes at input the URL and optionally a string with cookies and returns a structure with 4 keys headers, headerNoCookie, cookies, content

And here is an usage example:
<!--- make first request to firstURL with login credentials --->
<cfset firstCall = makeHTTPRequest(firstURL)>
<!--- make second request to secondURL using the cookiens from the first request --->
<cfset secondCall = makeHTTPRequest(secondURL, firstCall.cookies)>

Hope it will help somebody.

HAPPY CODING !!!

P.S.: If anyone want to comment on it, please do so.

Comments Comments (2) | Print Print | Email Send | 344 Views | 2% / 13% Popularity


Posted At : Feb 08, 2010 23:14 PM | Posted By : Ed Tabara
Related Categories: ColdFusion

So ColdFusion is definitely not dead. If you need further proof of that, you can check out isColdFusiondead.com, where we have a lot of detailed information about that question. But no, it's a funny thing that we hear, you know, every couple of years ColdFusion shifted from companies, from starting at Allaire to Macromedia to Adobe and any time that sort of happens, there's always this "What's going to happen?" sort of thing.

But no, thankfully Adobe is really, really helping ColdFusion and it's really starting to blossom, what we're seeing is what we're calling like a "ColdFusion Renaissance." In the last few years, the ColdFusion community has almost tripled in size, going from about 250,000 developers about four or five years ago to about 800,000 developers today.

We're anticipating even getting close to a million developers worldwide, hopefully maybe by sometime next year. We've really increased how many companies are using ColdFusion, as well. So 75 of the top Fortune 100 companies are running ColdFusion. About 12,000 companies worldwide have ColdFusion installed for internal applications and public websites development.

Check full interview here .

Comments Comments (2) | Print Print | Email Send | 414 Views | 2% / 13% Popularity


Posted At : Feb 01, 2010 18:10 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, cfHSSF, My Projects

After over 2 years, cfHSSF has been updated. It has been done by Steven Durette and he did a really great job!

From his email:
I made a couple more additions and I set it up so that it would degrade gracefully if the version of POI isn't high enough to support the features.
I also made a change to the way values are set in cells. Before a row was created every time a cell value was set. With newer versions of POI if a cell already existed in a row, it was wiped out when another cell in the same row was set. The new method first checks to see if the row exists and uses that. If the row doesn't exist then it creates it.
The ability to put JPEG and PNG images into workbooks was added. This works with the POI included with CF9. If someone tries to use it that doesn't have a new enough version, it takes the cell where the image was to reside and places a message that the POI version doesn't support it.
You can now stream the workbook directly to the browser instead of having to create a file first by using one of the new functions.

Basicaly there has been done the following changes:
  1. Added options for XLSX (Office 2007) files if the POI is the right version.
  2. Added getRow function. This function will get a row or create it if it doesn't already exist.
  3. Added getCell function. This function will get a cell or create it if it doesn't already exist.
  4. Changed multiple functions to use getRow and getCell functions.
  5. Added AddImage function to place an image in the spreadsheet.
  6. Added AddJPGImage function to put a JPEG image in the spreadsheet.
  7. Added AddPNGImage function to put a PNG image in the spreadsheet.
  8. Added createBookVar to allow for streaming workbook to the browser without creating a file.
  9. Updated create region to allow creation of regions in xlsx workbooks.

If anyone interested, you may download it here.

Comments Comments (0) | Print Print | Email Send | 527 Views | 3% / 0% Popularity


Posted At : Jan 26, 2010 17:13 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, Fun

Right now HERE are not too many tests, but it's a start.
So, have fun!

Comments Comments (0) | Print Print | Email Send | 472 Views | 2% / 0% Popularity


Posted At : Jan 19, 2010 17:50 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, Other

Congratulations to all new and re-approved Adobe Community Professionals!

Comments Comments (1) | Print Print | Email Send | 530 Views | 3% / 6% Popularity


Posted At : Jan 12, 2010 15:15 PM | Posted By : Ed Tabara
Related Categories: ColdFusion

  1. In float numbers, if for example the "Avg Execution Time" is less than 1 second, you will see 2 zeroes before the dot. For example instead of 0.654 you will see 00.654
  2. Often when open the monitor there are missing the top buttons: "Start Monitor", "Start Profiling" and "Start Memory Tracking". But a simple refresh usually fix the issue

Are this bugs or "as supposed to be" i don't know. Just some observations

Comments Comments (0) | Print Print | Email Send | 530 Views | 3% / 0% Popularity


Posted At : Jan 05, 2010 18:12 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, 1ssBlog

Posts - 56 (29 of them being in december)
Comments - 60 (18 being my answers)
Total views - 118758 (15280 in december)
Unique views - 25415 (2910 in december)

My open source projects downloads: 1939
  • 1ssBlog - 351
  • cfWatcher2.1 - 324
  • cfFirewall - 256
  • cfWatcher1 - 203
  • cfHSSF - 201
  • cfSQLMaster - 138
  • mollom - 115
  • robots - 114
  • defensio - 79
  • yahooSiteExplorer - 75
  • 1ssBlog1Update1 - 43
  • 1ssBlog1Update2 - 40

Top 10 posts by views:

Top 10 posts by unique IP views:


Comments Comments (0) | Print Print | Email Send | 345 Views | 2% / 0% Popularity