如何修复Jersey POST请求参数警告? [英] How to fix Jersey POST request parameters warning?

查看:1746
本文介绍了如何修复Jersey POST请求参数警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jersey建立一个非常简单的REST API,并且在我的日志文件中有一个我不确定的警告.

I'm building a very simple REST API using Jersey, and I've got a warning in my log files that I'm not sure about.

警告:一个Servlet POST请求,用于 URI http://myserver/mycontext/myapi/users/12345?action = delete , 包含表单参数 请求主体,但请求主体具有 已被servlet或 Servlet过滤器访问请求 参数.仅资源方法 使用@FormParam将作为 预期的.资源方法消耗 请求主体通过其他方式将 不能按预期工作.

WARNING: A servlet POST request, to the URI http://myserver/mycontext/myapi/users/12345?action=delete, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

我的Web应用程序仅定义了Jersey servlet,映射到/myapi/*

My webapp only has the Jersey servlet defined, mapped to /myapi/*

如何停止这些警告?

推荐答案

对我来说,警告显示为POST application/x-www-form-urlencoded.而且我正在使用Spring Boot,它具有一个HiddenHttpMethodFilter,它在执行其他操作之前先执行getParameter.所以我最终做了这个讨厌的重写:

For me the warning was showing for POST application/x-www-form-urlencoded. And I am using Spring Boot which has an HiddenHttpMethodFilter that does a getParameter before anything else... So I ended up doing this nasty override:

@Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
        return new HiddenHttpMethodFilter() {
            @Override
            protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                    FilterChain filterChain) throws ServletException, IOException {
                if ("POST".equals(request.getMethod())
                        && request.getContentType().equals(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
                    filterChain.doFilter(request, response);
                } else {
                    super.doFilterInternal(request, response, filterChain);
                }
            }
        };
    }

这篇关于如何修复Jersey POST请求参数警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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