开发者

Maven Test on servlet receiving an IllegalStatException: Cannot reset buffer - response already committed

开发者 https://www.devze.com 2023-01-17 04:21 出处:网络
During the test phase of my maven build I ave the following code in one @test method: request.clearAttributes();

During the test phase of my maven build I ave the following code in one @test method:

        request.clearAttributes();
        response.reset();
        Str开发者_Python百科ing story_uuid = qit.getQI().getStory_uuid();
        assertNotNull(story);
        request.setParameter("story_uuid", story_uuid);
        request.setParameter("activity", "get");
        queue.doPost(request, response);
        assertEquals(response.getErrorMessage(), HttpServletResponse.SC_OK, response.getStatus());


        request.clearAttributes();
        response.reset();    //**THIS RESET HERE**//
        request.setParameter("story", story_uuid);
        request.setParameter("activity", "revert");
        queue.doPost(request, response);
        assertEquals(response.getErrorMessage(), HttpServletResponse.SC_OK, response.getStatus());

The line response.reset() with the //**THIS RESET HERE**// causes the following error:

java.lang.IllegalStateException: Cannot reset buffer - response is already committed

Should I not be using one method to have multiple calls to my servlet?


The reset() only works when the response is not committed yet. It basically clears the output buffer. You cannot send multiple responses on a single request. This totally violates the HTTP specification. For each request a client sends, the server can send only one fullworthy response back. When the response is been committed, you're at a point of no return. If you want to send a new response back, then you need to let the client fire a brand new request so that you can send a new response back.

0

精彩评论

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