CB and PUT method

Hi guys,

I back on an earlier thread that discussed CB's handling of PUT requests.

http://groups.google.com/group/coldbox/browse_thread/thread/ac4cf6721f22b31c

The topic has come up again with a developer I'm working with and I'm hoping you guys can chime in with your thoughts.

In Luis' video he uses event.getHTTPContent() to get the content of the PUT request. My question is.... for PUT requests, does this CB method grab the key value pairs/params from ColdFusions getHTTPRequestData().content variable or does it read the variables as query string variables??

I"m running into issues with this when receiving a request from an iPhone app. When the iPhone app sends a PUT request, there are no query string variables appended to the URL (params), the content is only sent in the body. When I perform the same PUT using my eclipse plugin, the PUT params are appended to the URL and ColdBox is happy because these are pulled into the request collection. Everything has worked fine for my tests but now i'm wondering if the plugin i'm using is incorrect because it's appending the parameters into the query string.

Can anyone confirm how event.getHTTPContent() is reading the variables for a PUT? i.e from getHTTPRequestData().content or from the query string?

Also, if you could point me in the direction of where getHTTPContent() lies in CB's package path that would be helpful. I haven't been able to find it yet.

Thanks.

Nolan

I back on an earlier thread that discussed CB’s handling of PUT requests.

http://groups.google.com/group/coldbox/browse_thread/thread/ac4cf6721f22b31c

The topic has come up again with a developer I’m working with and I’m hoping you guys can chime in with your thoughts.

In Luis’ video he uses event.getHTTPContent() to get the content of the PUT request. My question is… for PUT requests, does this CB method grab the key value pairs/params from ColdFusions getHTTPRequestData().content variable or does it read the variables as query string variables??

This is incorret Nolan, the getHTTPContent() is only used when the content of the HTTP request is available. Maybe with a PUT or POST when doing a binary content or xml content or such. The rest of the parameters are considered URL parameters which come in to the request collection. These are query string variables. In all reality PUT and POST are very similar in nature, therefore their query strings come into the request collection with no problem at all.

I"m running into issues with this when receiving a request from an iPhone app. When the iPhone app sends a PUT request, there are no query string variables appended to the URL (params), the content is only sent in the body. When I perform the same PUT using my eclipse plugin, the PUT params are appended to the URL and ColdBox is happy because these are pulled into the request collection. Everything has worked fine for my tests but now i’m wondering if the plugin i’m using is incorrect because it’s appending the parameters into the query string.

Now, this is different, what iPhone library are you using for the REST calls? If this is the case, where the library adds them as name-value pairs in the content of the HTTP request, you will have to massage the data manually. This is very very easy. All you have to do is have an interceptor listening at preProcess() and be able to get the content and then parse it out into a data structure which you can append back to the collection. Here is some pseudo code:

contentstring = event.getHTTPContent();
inMap = {};
for(var x=1; x lte listLen(contentString, “&”); x++){
// loop through each iteration and create name value pairs
inMap[ getToken( listGetAt(contentString,x,"&"), 1) ] = getToken( listGetAt(contentString,x,"&"), 2) ;

}

// Then roll it into the request collcetion
event.collectionAppend(inMap);

That’s it

Hi Luis,

Thanks for your reply. The iPhone library being used is the standard NSHTTPRequest api. So I guess the difference is that the plugin I’m using in eclipse is appending the params as a query string and the iPhone api is not. Thanks for sending over the code. I had to make the following modifications, but was able to (FINALLY) get the PUT working between the iPhone app and CB on the server.

Here is the updated preProcess interceptor

function preProcess(event,interceptData){
var rc = event.getCollection();
contentString = event.getHTTPContent();
inMap = {};
for(var x=1; x lte listLen(contentString, “&”); x++){
nameValuePair = listGetAt(contentString,x,"&");
// loop through each iteration and create name value pairs
inMap[getToken(nameValuePair,1,"=")] = urlDecode(getToken(nameValuePair,2,"="));
}
event.collectionAppend(inMap);

}

Thanks for your help on this.

Cheers,

Nolan

can you contribute this to forgebox?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Yes. I’ve never done that before but will figure it out! :wink: Have a great weekend and thanks again.

Nolan