使用 Spring 3.0.5 和 Jackson 对 Tomcat 发出 JSON PUT 请求时出现 403
我的 Web 应用程序已开始返回 PUT 请求的 403 错误。但是,我在日志中没有看到此请求的任何调试消息,因此我对如何进一步调试它感到困惑。
该代码曾经有效,但最近发生了一些变化: 客户端是 Sencha JS:
Ext.Ajax.request({
url : '/RestWAR/personal/trailSegment/' + trailSegment.id + '.json',
method : 'PUT',
headers : {'Content-Type': 'application/json'},
jsonData : segmentDto
});
容器是 Apache Tomcat 6.0。 请求先转到 Spring Security 3.0.0.RC1,然后再转到 Spring 3.0.5。
@Controller
@RequestMapping("/personal")
public class PersonalController {
@RequestMapping(value = "trailSegment/{trailSegmentId}", method=RequestMethod.PUT)
public void updateTrailSegment(@PathVariable long trailSegmentId, @RequestBody PersonalTrailSegmentDTO trailSegmentDto) {
//...
}
}
最近的变化: Spring 版本为 3.0.0.M4,json 库为 net.sf.json-lib 1.0.2。 Spring 现在是 3.0.5,json 库现在是 Jackson Mapper ASL 1.4.2(即 Spring 推荐的)。
GET 和 POST 工作正常。只是 PUT 失败了。
如果涉及 Spring Security,那么我会看到来自 Spring Security 的调试消息,但我什么也看不到。 Tomcat 似乎正在停止该请求。
预先感谢您的任何帮助 - 特别是在调试方面。
My web application has started returning 403 errors on PUT requests. However, I'm not seeing any debug messages in the logs for this request so I'm stumped as to how to debug this further.
This code used to work but there have been a number of recent changes:
Client is Sencha JS:
Ext.Ajax.request({
url : '/RestWAR/personal/trailSegment/' + trailSegment.id + '.json',
method : 'PUT',
headers : {'Content-Type': 'application/json'},
jsonData : segmentDto
});
The container is Apache Tomcat 6.0.
The request goes to Spring Security 3.0.0.RC1 before going to Spring 3.0.5.
@Controller
@RequestMapping("/personal")
public class PersonalController {
@RequestMapping(value = "trailSegment/{trailSegmentId}", method=RequestMethod.PUT)
public void updateTrailSegment(@PathVariable long trailSegmentId, @RequestBody PersonalTrailSegmentDTO trailSegmentDto) {
//...
}
}
Recent changes:
Spring was on 3.0.0.M4 and the json library was net.sf.json-lib 1.0.2.
Spring is now 3.0.5 and the json library is now Jackson Mapper ASL 1.4.2 (i.e. what Spring recommends).
GETs and POSTs are working fine. It's just PUTs that are failing.
If Spring Security were involved then I would be seeing debug messages from Spring Security but I see nothing at all. It appears that Tomcat is stopping the request.
Thanks in advance for any help - especially in regards to debugging this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在几分钟前将其作为评论发布,现在我回想起当我们点击此内容时,我记得我发现 此线程(参数从 PUT 中消失)关于当时的问题。通读它,Tomcat 开发人员似乎将 HTTP 规范解释为 PUT 不应该支持参数:
-
I just posted that as a comment a few minutes ago, now that I thought back when we hit this, I remembered I found this thread (Parameters disappear from PUTs) about the issue back then. Reading through it, it seems the Tomcat-developers interpreted the HTTP-specification to mean that PUT should not support parameters:
-
问题是从
updateTrailSegment()
方法返回 null。这会导致 Spring 尝试使用InternalResourceView
与请求中内容的 url 映射请求 - 即/RestWAR/personal/trailSegment/1761
。InternalResourceView
意味着它尝试将该 URL 解析为应用程序内的路径。因为没有 - 它失败了。修复方法是使用作为返回类型:
ExtResponse 只是一个简单的 POJO,用于返回响应代码。
现在完整的方法是:
The problem was returning null from the
updateTrailSegment()
method. This causes Spring to attempt to map the request usingInternalResourceView
with a url of what's in the request - i.e./RestWAR/personal/trailSegment/1761
. TheInternalResourceView
means that it attempts to resolve that URL as a path within the application. As there is none - it fails.The fix is to use as the return type:
ExtResponse is just a simple POJO to return a response code.
The full method is now: