How to fix Jersey POST request parameters warning?

后端 未结 9 913
暗喜
暗喜 2020-12-08 06:50

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.

WARNING: A servlet POST request,

相关标签:
9条回答
  • 2020-12-08 07:25

    Finally got rid of this by making sure I had Content-Type: application/json in my request headers (obviously, on the client side)

    0 讨论(0)
  • 2020-12-08 07:33

    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);
                    }
                }
            };
        }
    
    0 讨论(0)
  • 2020-12-08 07:36

    In my case I've fixed this error when I've changed the Object Date to String in the method.

    Error:

    @POST
    @Path("/myPath")
    @Produces(MediaType.APPLICATION_JSON)
    public List<MyObject> myMethod(@FormParam("StartDate") Date date) throws Exception {
    

    Fixed

    @POST
    @Path("/myPath")
    @Produces(MediaType.APPLICATION_JSON)
    public List<MyObject> myMethod(@FormParam("StartDate") String date) throws Exception {
    
    0 讨论(0)
提交回复
热议问题