views:

15

answers:

1

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

            request.clearAttributes();
        response.reset();
        String 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?

+1  A: 

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.

BalusC
I thought I'd be able to reuse the request and response objects. Now that I'm creating a new one each time I'm testing, I no longer get the error. Thanks!
Queso