PDA

View Full Version : HTTP PUT fails in Ext.Ajax.request



crashedsnow
18 Dec 2009, 5:18 AM
Hi folks,

I've got a Java back end implementing a RESTful web service in which I have a PUT method (HTTP PUT that is) handling an insert of data.

If I send a PUT request using a Java API (eg Jersey) my back end code works as expected, but when I create an Ajax request using ExtJS (latest release version) I get no parameters coming through in the Http request.

My ExtJS call looks like this:




Ext.Ajax.request({
url: this.saveUrl,
success: this.saveCallback,
failure: this.saveError,
scope:this,
disableCaching:true,
params: values,
method:'PUT',
headers: {
'Object-Type' : objectType,
'Accept': 'application/json'
}
});



The "values" parameter is a JS array. This code works if I change to POST method (ie the params get sent as expected), but if I change to PUT (and change server code accordingly) the params do not seem to be sent.

Interestingly they DO show up in the console in Firebug, but somehow don't make it to the server in the HttpServletRequest object.

Is there something else I need to specify in the Ajax request? form encoding param perhaps?

Thanks

Animal
18 Dec 2009, 5:20 AM
What does the packet look like in Fiddler?

crashedsnow
18 Dec 2009, 5:24 AM
Good question.. I'm using Tamper data in FF, but obviously won't work for my Java client code.. I'll get some fiddler action happening..

crashedsnow
18 Dec 2009, 5:32 AM
Dunno how to use Fiddler.. doesn't seem to pick up local connections. I'll need to work out how to use it. The request in FF from tamper data looks like this:




Host=localhost:8080
User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6
Accept=application/json
Accept-Language=en-us,en;q=0.5
Accept-Encoding=gzip,deflate
Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive=300
Connection=keep-alive
X-Requested-With=XMLHttpRequest
Object-Type=user
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
Referer=http://localhost:8080/mrfserver/struts/test.action
Content-Length=301
Cookie=JSESSIONID=F1912627CC3C5E905845FE516EE7D241
POSTDATA=objectType=user&userId=-1&account=-1&firstName=System&lastName=User&username=system&password=password&altEmail=hjkhj&timezone=d%255C&currency=&country=&registeredFromIP=&dateCreated=2009-12-03%252012%253A24%253A28%2520AM%2520EST&dateModified=2009-12-15%25208%253A56%253A34%2520PM%2520EST&status=ACTIVE




POSTDATA contains my params.. but somehow they don't make it to the server (running Tomcat 6)

crashedsnow
18 Dec 2009, 5:54 AM
OK.. I got fiddler working.

It seems that the Java client API puts all the params on the URL (like a GET request):

PUT /mrfserver/rest/core/domain/?lastName=TestLast&username=TestUsername&account=-1&firstName=TestFirst&password=TestPassword HTTP/1.1

Whereas ExtJS puts it in the form data. I think from my reading that the Java library is the correct way, although the HTTP spec is suitably vague:

"The URI in a POST request identifies the resource that will handle the enclosed entity"

"The URI in a PUT request identifies the entity enclosed with the request"

So.. does this mean I need to assemble my own URI if I want to submit a PUT request using ExtJS?

Of course I can do this.. but it's a bit of a pain. I think that because ExtJS is detecting the "params" value, it always just dumps this into the POSTDATA content of the request.

Animal
18 Dec 2009, 6:11 AM
That's what it should do. Ext is behaving correctly.