开发者

Spring Framework HttpRequestHandler failure

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/regionname开发者_如何学GoID  

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


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


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.


Configure your own handlerMapping bean (perhaps based on AbstractUrlHandlerMapping)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜