struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Watson <>
Subject [S2] A very nice feature of the S2 REST plugin
Date Mon, 26 Jan 2009 23:59:09 GMT

I just wanted to point out a very nice feature in the REST plugin that
probably isn't deliberate but is mighty handy so this is a request not
to change it!

As a bit of background, we've developed a RIA in Flex that talks to a
backend using the REST plugin. You're probably all aware that Flex
doesn't really do REST. In fact it doesn't do it at all so it's been
the bane of my life for some months now.

One of the biggest problems for us is that Flex considers anything
other than a 200 response as an error (including a 201). Which has
meant we initially couldn't create any resources when running the Flex
app in IE7 (it also can't see that actual response code or any
headers!). The solution we came up with to work around this was to
pass in a url param that tells us the client is Flex, and based on
this if it's a successful POST we return a special bit of XML in the
response body that tells it what it's created (it can't see the
location header) and a 200 response code.

Now the REST plugin will not send back content if the response is 200
so I thought I was going to have to modify the source. As it turns out
though, the REST plugin uses the HttpHeaders objects status to decide
this. We already use an extended implementation of the
DefaultHttpHeaders though and what I've found is that in the apply
method I can set the HttpServletResponse status to 200 (this goes to
the client) but leave the ExtendedHttpHeaders status set to 201 which
means struts still returns the content. How happy am I today?

So *please* don't go changing this.

It's a very nice workaround to a problem that would normally be a
show-stopper for anyone trying to use Flex with the REST plugin.

I'd be happy to write a wiki page or something on how to use the REST
plugin with Flex if you think it'd be helpful - just point me at where
you'd like it.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message