The Dev Pages

A knowledge base for web applications development (and beyond)

Archive for May, 2008




The base href effect on XMLHtttpRequest.open (in IE)

Imagine that. If your base href is set to something weird, the ajax requests will get Access errors indicating “Permission Denied to call method yourXMLHttpRequestObject.open” Errors! But only in IE.

In IE, with AJAX requests, your url root must match your base href. base ref=”http://www.mydomain.com should be the same as the base url in xmlHttp.open(“GET”, “http://www.mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234”, true), or you can use relative urls.

Example I had:


//The XMLHttpRequest is named xmlHttp here, xmlHttp = new XMLHttpRequest()
//If the base href is set to something other than the server root, the AJAX request
//thinks the request is coming from a different server, or something.
//Permission denied to call XMLHttp.open with the following
//SET IN HTML HEAD - NOT HTTPS!
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);

//Now when the base href is set to the server root, no problems
//SET IN HTML HEAD - HTTP!
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);

Issues when www isn’t mapped to your home url

Another issue that can happen with access denied errors with your AJAX request is when your www doesn’t resolve to the same url as your root. I.E. http://www.yourdomain.com isn’t the same dns entry as http://ourdomain.com, even if they both eventually go to the same server ip.

Error: Happens when your session is in http://www.yourdomain.com and your AJAX request points to http://yourdomain.com (if your www subdomain doesn’t resolve to http://yourdomain.com).


//I'm on a http:://www.mydomain.com page, and I get an error with this line
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);
// I'm on a http:://mydomain.com page, this line will work
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);

simple addtoquery


Posted on May - 29 - 2008








Summary:

Setting up each coldfusion server instance as a Windows service using its own jvm.config. Using the debugger with multiple coldfusion server instances causes errors unless you specify a separate debugger port in a unique jvm.config file for each instance.

First Note: If you can live with having no server instances running when you initially start windows, you can just start your cf server instance using the command line, with the -config option pointing to a custom config. The rest of this article focuses on setting up multiple jvm.configs, each coldfusion instance having a different jvm.config, and setup as a Windows services that can automatically start in windows.

jrun -config jvm.config_new_server -start default

After getting the following error repeatedly, I decided to stop putting up with running multiple coldfusion instances from one jvm.config file.

FATAL ERROR in native method: JDWP No transports initialized,

jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)

ERROR: transport error 202: bind failed: Address already in use

ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)

JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized

[../../../src/share/back/debugInit.c:690]

This error stemmed from me having multiple Coldfusion server instances, and every time I started one it would throw errors that a port was already in use (The debugger port). All my instances were setup to use the same debugger port, since they all used the same jvm.config file. I got sick of remembering to stop debugging services, or edit the JVM.config to not run the debugger each time I started a different CF Instance. Obviously there are many reasons for using separate jvm.configs, notably for allocating memory resources and settings to be shared more efficiently. Here is my step-by-step process for setting up multiple coldfusion server instances to run with multiple jvm.config xml files.

Note: If you use debugging with the default server, but do not change the default server instance to use its own jvm.config, from what I can tell, it still starts up fine, even though a port in use error shows up. I think this is because the admin server and the default instance server are both using the default jvm.config, but the admin server must not really cause enough of a clash to prevent the default instance from starting, since the admin server probably does not do that much with the debugger port. I need to explore what exactly the admin instance does. It is not as full blown as the other instances, and it must just serve as a shell or base that manages the other instances.

1)Go to Windows Admin Tools -> Services. Locate the name of Coldfusion Instances that are running as services. On my computer, these services show up as “Macromedia JRun Admin Server”, “Macromedia JRun CFusion Server” (The default instance, which for me was called cfusion) and “Adobe Coldfusion 8 AS cfusion2” (I set up another server instance called ‘cfusion2’). You need to remove all services for which you want to have a debugger. This way, you can remake the service with the option to use a specific and custom JVM. For example, you could have all instances use the default jvm.config, except for one.

2)Remove the non-default services that aren’t configured to use a custom JVM (unless you want the services already installed to just use the default JVM). Do this by using the jrunsvc.exe from the command line. Same folder as the default jvm.config. For me this was c:\JRun4\bin. So once you know the name of the services you want to remove, the command goes like this:

jrunsvc -remove “Adobe Coldfusion 8 AS cfusion2”

Don’t forget the quotes if there are spaces in the Service Name.

3)Install the instances as services, each one using the -config option to point to a custom JVM.config of your creation. Here are the commands I issued:

I left the default instance alone, and made the default JVM config contain the settings I wanted for the first and default instance (jvm.config). Here is the command for installing the second coldfusion instance as a service with a config file cfusion2.jvm.config:

jrunsvc -install cfusion2 cfusion2Service “cfusion2 Service” “This is the service for
the coldfusion server instance cfusion2” -config C:\Jrun4\bin\cfusion2jvm.config

And if you had a third instance, you could do

jrunsvc -install cfusion3 cfusion3Service “cfusion3 Service” “This is the service for
the coldfusion server instance cfusion3” -config C:\Jrun4\bin\cfusion3jvm.config

I know, very original naming. The install option is followed by 3 namings for the new service of my server instance. I think these are 1)service name 2)service display name 3)service description. These are arbitrary names and descriptions that the jrunsvc command has you set.

Note: I originally had the config option point to -config cfusion3jvm.config, but my service wasn’t getting my debugger port started, and I think it may have been using the jvm.config instead of the custom one. I changed -config cfusion3jvm.config to -config C:\Jrun4\bin\cfusion3jvm.config and it worked fine. Maybe I didn’t need to do that and I was just missing something though.

Note: If you try and start the service and get the ‘Windows could not start the service … review the System Event log … refer to service-specific error code 4″, or windows does not start the service, look in the event log (Admin Tools -> Event Viewer->System) and you’ll see the error from the Service Control Manager. The service-specific error is less than useful, but for me this meant that I did not get the path or the filename correct to the config file when I created the service.

4)If you specify different debugger ports for each CF instance, setup up a different debugger in your IDE for each CF instance, since one debugger can’t run on two ports (I would assume). This goes for anything else. If you configure different things in each JVM, you have to configure anything using the different instance settings to correspond.

Of course, if you don’t want to deal with all these services, and no server instances are running when you initally start windows, you can just start your cf server instance using the command line, with the -config option pointing to a custom config.

I think it is nice to have my 2 instances (soon 3 or 4), one for each dev environment, start up on their own when windows loads, each using a different port for a debugger. Too many instances running can really eat resources though.

Useful Links:

http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_18206&sliceId=2




The errors from accidentally putting a single quote somewhere in a scheduled task name in the CF Server Admin start like this:

Server (my local dev server) may start up and serve cfm pages, but error log has a bunch of errors.

The CFAdmin gives you a “The Cron service is not available” error

The server error log shows “error while reading header <VARIOUS HEADER NAMES HERE>”

The neo-cron.xml is invalid xml

Resolution: Since you can’t get back into CFAdmin, replace the neo-cron.xml with the default one (This will delete all your schedules tasks, but you can recreate them after the cfadmin works again). Or you can correct the syntax erro




So I was pretty annoyed how hard it was to find a description of how to return an xml document from a component back to an AJAX page that had sent a request to the component. I was making a simple form, and all I wanted was to make a simple call to a remoteService, and get a simple xml response. I didn’t really want an AJAX Framework/object for this simple task.

So after returning a simple string, the coldfusion service was adding the standard wddx xml tags around the string before it was received by the client page. So I learned you have to use a return type xml, instead of a return type string. But when I did that, even though the xml document looked well-formed, and how I had intended it to look with no wddx stuff, the receiving page was seeing null in the responseXML property of the XMLHttpRequest object.

So on this AJAX page, my XMLHttpRequest variable is called xmlHttp. And all I was getting was the xml doc as text in the xmlHttp.responseText property of the xmlHttp object. I wanted the xml doc to be in xmlHttp.responseXML and not the xmlHttp.responseText.

Using firebug (great FF add-on) I examined the reponse I was getting. Turns out the header of the response showed a content type of text/html and not an xml type. I finally figured out the key. In php yu could just add a header to set the content type to xml, using the header function. That is what I had been doing. Buth with coldfusion I had no idea how to add a content type header. THE KEY WAS IN THE CFCONTENT TAG. In my component being called, before I returned the xml object I had created, I learned you could just add a cfcontent tag to change the return type’s header.





SELECT s2.*, u.* FROM Something s
INNER JOIN Something2 s2 on s2.userID = s.consultantID
INNER JOIN [User] u ON u.id = s2.userID
WHERE s.id =




SomethingInfo






#UrlEncodedFormat(firstName)#
#UrlEncodedFormat(lastName)#







My code to send the request using a coldfusion component:

xmlHttp.open("GET", "RemoteServices/ARemoteService.cfc?method=getSomethingInfo"
+ cacheEntry , true);
// define the method to handle server responses
xmlHttp.onreadystatechange = handleRequestStateChange;
// make the server request
xmlHttp.send(null);

to call a coldfusion component and get a value from a method, the url for the request is:

PathtoYourComponent/YourComponent.cfc?method=yourMethodName&
param1=param1value¶m2=param2value

Helpful Links:
http://www.coldfusionjedi.com/index.cfm/2007/2/8/Returning-XML-in-ColdFusion-for-AJAX

http://www.brucephillips.name/blog/index.cfm/2006/11/11/Use-ColdFusion-Function-Return-Type-of-XML-to-Provide-XML-to-Both-Spry-and-Flex

Cart/Session Data vs Form data


Posted on May - 23 - 2008



So I was making a form that was originally one page, to submit and order.

It got more complex when I learned I should probably get the tax/subtotal/verification from our order processor before submitting the final order.

So now I had a 2 part form. Part one: Enter line items Process part one: Calculate subtotal/tax and list info for verification Part2:Verify info and submit for final order processing.

Still, just 2 steps, not a very big deal, right? I didn’t want to worry about the session, a cart, etc. I ended up passing the info from step 1 (lineitems) and cloning it on step two into hidden form values, so these lineItems would be available when step 2 was processed.

The kicker for me to switch to use a cart was that in order for me to calculate the price from the lineItems, I needed the price and the totals to not be form data that could be manipulated by the user. Instead of adding hidden price fields on the form, and worry about that specific security issue of modifying form data pricing, I just decided to keep track of the pricing in the session, on the cart, which also reduced my amount of form value overhead, bu mades things a little more complex.

Oh well, I needed to get familiar with our shopping cart object anyways.




This error is thrown when you try and access an element in an Array that is undefined. How would this happen? Here’s what I did.

I wanted to make an array of 2 elements. I did this in a loop that ran 5 times. Instead of making an array of 2 elements, I made an array of 5 elements, only 2 of which were defined:

Here is the messed up array:

messed up array

So check your array, and make sure when it is being created that no undefined elements are created by skipping element assignments. Mae sure you don’t create an array, and then do something like:



Here, elements 1,2, and 4 will be undefined. Should be:



Great site for Photoshop Brushes


Posted on May - 22 - 2008



So I’ve discovered the power of brushes and symbols in Photoshop and Illustrator (CS3). Seriously, if you’re looking for some great graphics that are totally scalable (look photo realistic, but are vectorized) you had to familiarize yourself with brushes and symbols. Just google for some tutorials, or just use the Adobe Help, which is amazing. I love Adobe’s documentation for the most part. Even with work and developing in Coldfusion and Flex, the adobe livedocs, etc. are great.

Here’s a site with some cool brushes. I was amazed at the water drops, trees, and even the guns. It looks like a lot of people are starting to use http://www.deviantart.com too. Here’s the link I was talking about:

http://www.psbrushes.net/




I noticed when I was unit testing that when I was setting a reactor record field to zero (userrecord.setUsedFilespace(0)), and then saving the record, the database would not update the table’s value from null to zero.

Turns out, as Chris pointed out, that if a table has a column that allows nulls, any zero value will automatically be saved as NULL. So this column,of type bigint, had no way of getting a zero value into it through reactor, which would always set the zero value to null.

What we did was customize the userDAO. We changed the create and update methods. In the DAO folder of the project, the userDAO was edited. In the create and update methods we changed the code:

null=”#Iif(arguments.to.usedFilespace EQ 0 OR NOT Len(arguments.to.usedFilespace)

TO

null=”#Iif(NOT Len(arguments.to.usedFilespace)

And this allowed the updates and creates to use zero values.




So after being confused as to why I kept seeing the javascript error ‘missing ; before statement’, I realized that javascript variables can’t begin with a number.

My code was:

for (int i = 0; i < top; ++i) { eval("form." + fieldsArray[i] + ".value");
}

fieldsArray contains a string ‘0to99scans’ referring to a form input ‘0to99scans’. This should have been something like ‘zeroTo499scans’.