views:

126

answers:

3

We have an application which communicates via REST requests made by clients.

The REST requests contain "region name" and a "ID" as parameters

So, a request would look something like this (for a DELETE)

http://host:port/regionnameID  

These REST requests between regions in a federation are properly URL encoded

I find that these request fail if the region name has a slash ("/") in it.

Then, the request would look like so

http://host:port/region/nameID  

This is due to incorrect interpretation of the Rest URL by HttpRequesthandler when there is a '/' in the region name.

Now, we have no control over clients sending REST request with "/" in the Region name.

Is there any method / configuration / workaround that can be done to prevent the HttpRequestHandler from returning 404

A: 

Configure your own handlerMapping bean (perhaps based on AbstractUrlHandlerMapping)

Stephen Denne
A: 

This is a bit of a dirty problem. What I would try to do here is to use the Spring @RequestMapping annotation. There is some documentation on it here: http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html

You can specific ant wildcards in the value you pass @RequestMapping. If you have a limited number of regions, then you can map them all to a single method as follows: @RequestMapping(value={"/region1*","/region2*","/region3**")

In your controller method, you will have to add additional logical for parsing out the nameID.

If you have a large number of regions, I would then create a separate Spring Web app (servlet) just to handle these requests. That app would have a cached lookup table of regions.

Chris J
+1  A: 

you should rewrite your urls with urlrwrite and use query parameters internal.

<rule>
 <name>Inbound:</name>
 <from>^(.*)ID$</from>
 <to last="true">delete?regionName=$1</to>
</rule>

Add your urlrewrite Filter in front of all other filters in web.xml

Janning
(+1) nice suggestion, that
skaffman