@Test public 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(); }
@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 { servletResponse.resetBuffer(); } catch (IllegalStateException e) { throw e; } if (isNamedDispatcher) { lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); return; } servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD); setRequestPath(servletRequest, dispatchTo); lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); }
AwsProxyRequestDispatcher implements RequestDispatcher { @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 { servletResponse.resetBuffer(); } catch (IllegalStateException e) { throw e; } if (isNamedDispatcher) { lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); return; } servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD); setRequestPath(servletRequest, dispatchTo); lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); } }
AwsProxyRequestDispatcher implements RequestDispatcher { @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 { servletResponse.resetBuffer(); } catch (IllegalStateException e) { throw e; } if (isNamedDispatcher) { lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); return; } servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD); setRequestPath(servletRequest, dispatchTo); lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); } AwsProxyRequestDispatcher(final String target, final boolean namedDispatcher, final AwsLambdaServletContainerHandler handler); }
AwsProxyRequestDispatcher implements RequestDispatcher { @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 { servletResponse.resetBuffer(); } catch (IllegalStateException e) { throw e; } if (isNamedDispatcher) { lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); return; } servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD); setRequestPath(servletRequest, dispatchTo); lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); } AwsProxyRequestDispatcher(final String target, final boolean namedDispatcher, final AwsLambdaServletContainerHandler handler); @Override @SuppressWarnings("unchecked") void forward(ServletRequest servletRequest, ServletResponse servletResponse); @Override @SuppressWarnings("unchecked") @SuppressFBWarnings("SERVLET_QUERY_STRING") void include(ServletRequest servletRequest, ServletResponse servletResponse); }
AwsProxyRequestDispatcher implements RequestDispatcher { @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 { servletResponse.resetBuffer(); } catch (IllegalStateException e) { throw e; } if (isNamedDispatcher) { lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); return; } servletRequest.setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.FORWARD); setRequestPath(servletRequest, dispatchTo); lambdaContainerHandler.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, getServlet((HttpServletRequest)servletRequest)); } AwsProxyRequestDispatcher(final String target, final boolean namedDispatcher, final AwsLambdaServletContainerHandler handler); @Override @SuppressWarnings("unchecked") void forward(ServletRequest servletRequest, ServletResponse servletResponse); @Override @SuppressWarnings("unchecked") @SuppressFBWarnings("SERVLET_QUERY_STRING") void include(ServletRequest servletRequest, ServletResponse servletResponse);  }