@Override
    @SuppressWarnings("unchecked")
    public void forward(ServletRequest servletRequest, ServletResponse servletResponse)
            throws ServletException, IOException {
        if (lambdaContainerHandler == null) {
            throw new IllegalStateException("Null container handler in dispatcher");
        }
        if (servletResponse.isCommitted()) {
            throw new IllegalStateException("Cannot forward request with committed response");
        }

        try {
            // Reset any output that has been buffered, but keep headers/cookies
            servletResponse.resetBuffer();
        } catch (IllegalStateException e) {
            throw e;
        }

        if (isNamedDispatcher) {
            lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, ((AwsServletRegistration)servletRequest.getServletContext().getServletRegistration(dispatchTo)).getServlet());
            return;
        }

        servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD);
        setRequestPath(servletRequest, dispatchTo);
        lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest));
    }
@Test
    void forwardRequest_nullHandler_throwsIllegalStateException() throws InvalidRequestEventException {
        AwsProxyRequest proxyRequest = new AwsProxyRequestBuilder("/hello", "GET").build();
        HttpServletRequest servletRequest = requestReader.readRequest(proxyRequest, null, new MockLambdaContext(), ContainerConfig.defaultConfig());
        AwsProxyRequestDispatcher dispatcher = new AwsProxyRequestDispatcher(FORWARD_PATH, false, null);
        try {
            dispatcher.forward(servletRequest, new AwsHttpServletResponse(servletRequest, new CountDownLatch(1)));
        } catch (ServletException e) {
            fail("Unexpected ServletException");
        } catch (IOException e) {
            fail("Unexpected IOException");
        } catch (Exception e) {
            assertTrue(e instanceof IllegalStateException);
            return;
        }
        fail();
    }