views:

173

answers:

0

I've been using struts2 + the rest plugin successfully to create a simple rest api web service. I'd like to make that service accessible to Flash and Silverlight clients, which means I need to add a crossdomain.xml access file at the root of my webapp. Normally I would just copy a crossdomain.xml file into the root of my webapp and serve it as a static file.

However, this doesn't seem to work with the rest plugin, as it attempt to map the request for /crossdomain.xml to an action named CrossdomainAction action (its index() method specifically). Ok, so I create a CrossdomainAction class which just has an index() method that returns "success". Except now, the request returns the action object serialized as xml, which isn't what I want either.

Is there an easier way to do this that I'm missing?

The solution I've finally ended up with is to define a custom result with a name of "success-xml", since the rest interceptor will check for a result with that name. Of course, if I attempt to set my result location to "crossdomain.xml", it throws an exception on startup because the Convention plugin doesn't know how to handle results with an extension of "xml". So I ended up renaming my "crossdomain.xml" file to "crossdomain.html" and writing a custom Result that sets the contentType to "text/xml" and includes the crossdomain file. Pretty convoluted... surely there is something better?

I'm using struts-2.1.18.1