HTTP PUT request on CB handler

Hi folks,

I'm trying to access a handler method using a PUT request, however the parameters in the request are undefined when my handler tries to access them. Running GET, POST, and DELETE, works no problem. Only PUT seems to be an issue?

Has anyone else seen this issue? If it's a bug, then I'd like to log it today.

Thanks.

Nolan

Can you put your routes, there is no reason for this, unless you are doing something weird.

The parameters come from the query string, if you are talking about the content of the http request, then you need to retrieve it like this:

getHTTPRequestData().content

Does that make sense.

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

Hi Luis,

Thanks for your email.

Here are my routes:

// ********** Group endpoints *********** //
addRoute(pattern="/user/:userid/groups/:groupid",
handler=“Group”,
action={
GET = “getGroup”,
PUT = “updateGroup”,
DELETE = “removeGroup”
});

addRoute(pattern="/user/:userid/groups/",
handler=“Group”,
action={
POST = “createGroup”,
GET = “getUserGroups”
});

These successfully map to my methods in my handler.

Handler code: (just including the relevant code not all code in the handler)

this.allowedMethods = {getGroup=‘GET’,getUserGroups=‘GET’,createGroup=‘POST’,updateGroup=‘PUT’,removeGroup=‘DELETE’};

function updateGroup(event){
var rc = event.getCollection();

rc.results.setData(‘update group - #rc.groupname#’);
/*
event.paramValue(‘contacts’,’’);

validationResult = validateThis.validate(theObject=rc,objectType=“GroupCreate”);
if(!validationResult.hasErrors() ){
rc.group = entityLoadByPK(‘Group’,rc.groupid);
rc.group.populate(rc);
rc.group.save();

//TODO: app contacts to GroupUser, validate user contacts exists prior to saving
if(listLen(rc.contacts)){

}

rc.results.setData(groupService.getGroup(rc.group.getGroupID()));
}else{
//return validation errors
rc.results.setStatus(403);
rc.results.setData(ArrayToList(validationResult.getFailureMessages(),’,’));
}

*/

}

setData() is an implicit setter in RESTResultsModel. In my PUT request I have several parameters - groupname is one of them. When I run the PUT I get an exception saying that groupname is not defined in rc. When I run a POST with the same parameters (on a method which allows POST) I am able to reference by rc.groupname. Are you saying that for PUT’s, the data needs to be accessed by getHTTPRequestData().content instead as rc.{variablename}?

Thanks very much.

Best,

Nolan

Hi Nolan, can you show me how you are doing the requests? I have no problem’s passing argument parameters to a PUT operation, I was talking about content, if you are using the content portion of http requests, not parameters.

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

Hi Luis,

Sorry for the confusion. I hope I have this right this time. Attached is an image of my request and response using the Poster Firefox plugin. I have a parameter called name (the group name) and the body content of the request also is populated. I am able to read the content in my handler via GetHTTPRequestData().content. is this the way it needs to be accessed or should I be able to access the data via rc.name?

Greatly appreciated.

Best,

Nolan

I am not sure about this Nolan, I cannot reproduce it. There has to be something amiss here, maybe try another tool?

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

Hi Luis,

I was able to replicate the same issue using this eclipse plugin: http://www.ywebb.com/eclipse-restful-http-client-plugin-http4e/ . Great plugin btw.

Just so I know what I’m looking for, can you confirm that a parameter in a PUT request can be referenced as rc.param, or do I need to reference by GetHTTPRequestData().content?

Thanks.

Nolan

A PUT request when sending parameters via the URL or cfhttp or whatever, comes into the request collection. The content is usually the raw content submitted not the paremeters.

I created a video for you so you can see that it works for me.

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

PUTTest.mp4 (2 MB)

By the way, what you see in the video is a sneek peek at ColdBox Relax.

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