DOJO/JSON requests in ColdFusion
Recently I was putting together a sample app for my presentation at AjaxWorld, and I decided to use the DOJO ajax library and ColdFusion together. However, there was one problem, DOJO does everything with JSON requests/response, instead of url/form variables and XML and it does it in such a way that you can't easily get to it from CF.
What I mean by that, DOJO will send the JSON request arguments in a string, in the body of the HTTP get request. Now this is perfectly valid in HTTP, however it is rare. And it means that the values don't end up in a FORM or URL variable either. So getting the JSON string can be tricky.
So I've put together a simple UDF that you can use to get this JSON request, technically anything in the http body of a request. Soon I'll put this on cflib, but for now, here it is. Hope it helps.
(Special thanks to Christian Cantrell, the byte array code is from his blog).
<cfscript>
var size=GetPageContext().getRequest().getInputStream().available();
var emptyByteArray = createObject("java", "java.io.ByteArrayOutputStream").init().toByteArray();
var byteClass = createObject("java", "java.lang.Byte").TYPE;
var byteArray = createObject("java","java.lang.reflect.Array").newInstance(byteClass, size);
GetPageContext().getRequest().getInputStream().readLine(byteArray, 0, size);
createObject('java', 'java.lang.System').out.println("{GetJSONRequest} ByteArray.ToString=" &ToString( byteArray ) );
return ToString( byteArray );
</cfscript>
</cffunction>
<cfset jsonstring = getJSONRequest()>

Here is the CFJSON CFC Implementation:
http://www.infoaccelerator.net/client/index.cfm/20...
Thanks!
~Rob
So the better example would be:
<code>
<cfset jsonobject = cfjsonDecode( getJSONRequest() )>
</code>
Now a json decoder writing in straight java would probably be faster. Just look at the CF7 function toScript(), when it's creating an "actionscript" string that is almost the same as a json string (curly brackets, etc..). So the speed of toScript() is a good comparison of a java udf vs a cfml udf. I did notice that it was a lot slower to encode a large result set with JSON, can't remember the library I used, then creating XML with cfsavecontent and using xml instead. So writing something native is probably worth the effort.
I wish I knew about JSON when I wrote toScript() in CF7 I would of structured the arguments a little differently and add json support too. Guess we'll have to convince the CF team to add native json support as a new function ;)
You can also snag the content by using the native getHttpRequestData() function--which returns a struct. In the struct is a key called "content" which should contain any text delivered in the body of the HTTP request.
You really don't need Java at all--which some users may not be able to use due to Sandboxing.
<a href="http://www.jupla.com/">video izle</a>
<a href="http://www.jupla.com/">izle</a>
<a href="http://www.jupla.com/">komik videolar</a>