@Test public void addFilter_doesNotImplementFilter_expectException() { AwsServletContext ctx = new AwsServletContext(null); try { ctx.addFilter("filter", this.getClass().getName()); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().startsWith(this.getClass().getName() + " does not implement Filter")); return; } fail("Expected IllegalArgumentException"); }
@Override public FilterRegistration.Dynamic addFilter(String name, String filterClass) { try { Class<?> newFilterClass = getClassLoader().loadClass(filterClass); if (!Filter.class.isAssignableFrom(newFilterClass)) { throw new IllegalArgumentException(filterClass + " does not implement Filter"); } @SuppressWarnings("unchecked") Class<? extends Filter> filterCastClass = (Class<? extends Filter>)newFilterClass; return addFilter(name, filterCastClass); } catch (ClassNotFoundException e) { log.error("Could not find filter class", e); throw new IllegalStateException("Filter class " + filterClass + " not found"); } }
AwsServletContext implements ServletContext { @Override public FilterRegistration.Dynamic addFilter(String name, String filterClass) { try { Class<?> newFilterClass = getClassLoader().loadClass(filterClass); if (!Filter.class.isAssignableFrom(newFilterClass)) { throw new IllegalArgumentException(filterClass + " does not implement Filter"); } @SuppressWarnings("unchecked") Class<? extends Filter> filterCastClass = (Class<? extends Filter>)newFilterClass; return addFilter(name, filterCastClass); } catch (ClassNotFoundException e) { log.error("Could not find filter class", e); throw new IllegalStateException("Filter class " + filterClass + " not found"); } } }
AwsServletContext implements ServletContext { @Override public FilterRegistration.Dynamic addFilter(String name, String filterClass) { try { Class<?> newFilterClass = getClassLoader().loadClass(filterClass); if (!Filter.class.isAssignableFrom(newFilterClass)) { throw new IllegalArgumentException(filterClass + " does not implement Filter"); } @SuppressWarnings("unchecked") Class<? extends Filter> filterCastClass = (Class<? extends Filter>)newFilterClass; return addFilter(name, filterCastClass); } catch (ClassNotFoundException e) { log.error("Could not find filter class", e); throw new IllegalStateException("Filter class " + filterClass + " not found"); } } AwsServletContext(AwsLambdaServletContainerHandler containerHandler); }
AwsServletContext implements ServletContext { @Override public FilterRegistration.Dynamic addFilter(String name, String filterClass) { try { Class<?> newFilterClass = getClassLoader().loadClass(filterClass); if (!Filter.class.isAssignableFrom(newFilterClass)) { throw new IllegalArgumentException(filterClass + " does not implement Filter"); } @SuppressWarnings("unchecked") Class<? extends Filter> filterCastClass = (Class<? extends Filter>)newFilterClass; return addFilter(name, filterCastClass); } catch (ClassNotFoundException e) { log.error("Could not find filter class", e); throw new IllegalStateException("Filter class " + filterClass + " not found"); } } AwsServletContext(AwsLambdaServletContainerHandler containerHandler); static void clearServletContextCache(); @Override String getContextPath(); @Override ServletContext getContext(String s); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override int getEffectiveMajorVersion(); @Override int getEffectiveMinorVersion(); @Override @SuppressFBWarnings("PATH_TRAVERSAL_IN") // suppressing because we are using the getValidFilePath String getMimeType(String s); @Override Set<String> getResourcePaths(String s); @Override URL getResource(String s); @Override InputStream getResourceAsStream(String s); @Override RequestDispatcher getRequestDispatcher(String s); @Override RequestDispatcher getNamedDispatcher(String s); @Override @Deprecated Servlet getServlet(String s); Servlet getServletForPath(String path); @Override @Deprecated Enumeration<Servlet> getServlets(); @Override @Deprecated Enumeration<String> getServletNames(); @Override void log(String s); @Override @Deprecated void log(Exception e, String s); @Override void log(String s, Throwable throwable); @Override String getRealPath(String s); @Override String getServerInfo(); @Override String getInitParameter(String s); @Override Enumeration<String> getInitParameterNames(); @Override boolean setInitParameter(String s, String s1); @Override Object getAttribute(String s); @Override Enumeration<String> getAttributeNames(); @Override void setAttribute(String s, Object o); @Override void removeAttribute(String s); @Override String getServletContextName(); @Override ServletRegistration.Dynamic addServlet(String s, String s1); @Override ServletRegistration.Dynamic addServlet(String s, Servlet servlet); @Override ServletRegistration.Dynamic addServlet(String s, Class<? extends Servlet> aClass); @Override T createServlet(Class<T> aClass); @Override ServletRegistration getServletRegistration(String s); @Override Map<String, ? extends ServletRegistration> getServletRegistrations(); @Override FilterRegistration.Dynamic addFilter(String name, String filterClass); @Override FilterRegistration.Dynamic addFilter(String name, Filter filter); @Override FilterRegistration.Dynamic addFilter(String name, Class<? extends Filter> filterClass); @Override T createFilter(Class<T> aClass); @Override FilterRegistration getFilterRegistration(String s); @Override Map<String, ? extends FilterRegistration> getFilterRegistrations(); @Override SessionCookieConfig getSessionCookieConfig(); @Override void setSessionTrackingModes(Set<SessionTrackingMode> set); @Override Set<SessionTrackingMode> getDefaultSessionTrackingModes(); @Override Set<SessionTrackingMode> getEffectiveSessionTrackingModes(); @Override void addListener(String s); @Override void addListener(T t); @Override void addListener(Class<? extends EventListener> aClass); @Override T createListener(Class<T> aClass); @Override JspConfigDescriptor getJspConfigDescriptor(); @Override ClassLoader getClassLoader(); @Override void declareRoles(String... strings); @Override String getVirtualServerName(); }
AwsServletContext implements ServletContext { @Override public FilterRegistration.Dynamic addFilter(String name, String filterClass) { try { Class<?> newFilterClass = getClassLoader().loadClass(filterClass); if (!Filter.class.isAssignableFrom(newFilterClass)) { throw new IllegalArgumentException(filterClass + " does not implement Filter"); } @SuppressWarnings("unchecked") Class<? extends Filter> filterCastClass = (Class<? extends Filter>)newFilterClass; return addFilter(name, filterCastClass); } catch (ClassNotFoundException e) { log.error("Could not find filter class", e); throw new IllegalStateException("Filter class " + filterClass + " not found"); } } AwsServletContext(AwsLambdaServletContainerHandler containerHandler); static void clearServletContextCache(); @Override String getContextPath(); @Override ServletContext getContext(String s); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override int getEffectiveMajorVersion(); @Override int getEffectiveMinorVersion(); @Override @SuppressFBWarnings("PATH_TRAVERSAL_IN") // suppressing because we are using the getValidFilePath String getMimeType(String s); @Override Set<String> getResourcePaths(String s); @Override URL getResource(String s); @Override InputStream getResourceAsStream(String s); @Override RequestDispatcher getRequestDispatcher(String s); @Override RequestDispatcher getNamedDispatcher(String s); @Override @Deprecated Servlet getServlet(String s); Servlet getServletForPath(String path); @Override @Deprecated Enumeration<Servlet> getServlets(); @Override @Deprecated Enumeration<String> getServletNames(); @Override void log(String s); @Override @Deprecated void log(Exception e, String s); @Override void log(String s, Throwable throwable); @Override String getRealPath(String s); @Override String getServerInfo(); @Override String getInitParameter(String s); @Override Enumeration<String> getInitParameterNames(); @Override boolean setInitParameter(String s, String s1); @Override Object getAttribute(String s); @Override Enumeration<String> getAttributeNames(); @Override void setAttribute(String s, Object o); @Override void removeAttribute(String s); @Override String getServletContextName(); @Override ServletRegistration.Dynamic addServlet(String s, String s1); @Override ServletRegistration.Dynamic addServlet(String s, Servlet servlet); @Override ServletRegistration.Dynamic addServlet(String s, Class<? extends Servlet> aClass); @Override T createServlet(Class<T> aClass); @Override ServletRegistration getServletRegistration(String s); @Override Map<String, ? extends ServletRegistration> getServletRegistrations(); @Override FilterRegistration.Dynamic addFilter(String name, String filterClass); @Override FilterRegistration.Dynamic addFilter(String name, Filter filter); @Override FilterRegistration.Dynamic addFilter(String name, Class<? extends Filter> filterClass); @Override T createFilter(Class<T> aClass); @Override FilterRegistration getFilterRegistration(String s); @Override Map<String, ? extends FilterRegistration> getFilterRegistrations(); @Override SessionCookieConfig getSessionCookieConfig(); @Override void setSessionTrackingModes(Set<SessionTrackingMode> set); @Override Set<SessionTrackingMode> getDefaultSessionTrackingModes(); @Override Set<SessionTrackingMode> getEffectiveSessionTrackingModes(); @Override void addListener(String s); @Override void addListener(T t); @Override void addListener(Class<? extends EventListener> aClass); @Override T createListener(Class<T> aClass); @Override JspConfigDescriptor getJspConfigDescriptor(); @Override ClassLoader getClassLoader(); @Override void declareRoles(String... strings); @Override String getVirtualServerName(); static final int SERVLET_API_MAJOR_VERSION; static final int SERVLET_API_MINOR_VERSION; static final String SERVER_INFO; }