Spring 3.0.5和Jackson向Tomcat发出关于JSON PUT请求的403 [英] 403 on JSON PUT request to Tomcat with Spring 3.0.5 and Jackson

查看:85
本文介绍了Spring 3.0.5和Jackson向Tomcat发出关于JSON PUT请求的403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序已开始在PUT请求上返回403错误.但是,我在该请求的日志中没有看到任何调试消息,因此对于如何进一步调试它感到困惑.

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.

该代码曾经可以使用,但是最近进行了许多更改: 客户是Sencha JS:

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
});

容器是Apache Tomcat 6.0. 该请求在转到Spring 3.0.5之前先转到Spring Security 3.0.0.RC1.

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) {
    //...
    }
}

最近的更改: 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的建议).

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).

GET和POST运行正常.只是PUT失败了.

GETs and POSTs are working fine. It's just PUTs that are failing.

如果涉及到Spring Security,那么我会看到来自Spring Security的调试消息,但我什么也看不到.看来Tomcat正在停止请求.

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.

推荐答案

问题是从updateTrailSegment()方法返回null.这会导致Spring尝试使用InternalResourceView和请求中的URL(即/RestWAR/personal/trailSegment/1761)映射请求. InternalResourceView表示它尝试将URL解析为应用程序中的路径.由于没有-失败.

The problem was returning null from the updateTrailSegment() method. This causes Spring to attempt to map the request using InternalResourceView with a url of what's in the request - i.e. /RestWAR/personal/trailSegment/1761. The InternalResourceView 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:

@ResponseBody ExtResponse

ExtResponse只是返回响应代码的简单POJO.

ExtResponse is just a simple POJO to return a response code.

完整的方法现在是:

@RequestMapping(value = "trailSegment/{trailSegmentId}", method=RequestMethod.PUT)
public @ResponseBody ExtResponse updateTrailSegment(@PathVariable long trailSegmentId, @RequestBody PersonalTrailSegmentDTO trailSegmentDto) {
    trailSegmentDto.setId(trailSegmentId);
    PersonalTrailSegment trailSegment = trailSegmentAssembler.assembleDomain(trailSegmentDto);
    trailSegmentDataGateway.update(trailSegment);
    return new ExtResponse("true", "");
}

这篇关于Spring 3.0.5和Jackson向Tomcat发出关于JSON PUT请求的403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆