public void registerServlet ( @ Nonnull final Class < ? extends Servlet > aServletClass , @ Nonnull @ Nonempty final String sServletPath , @ Nonnull @ Nonempty final String sServletName , @ Nullable final Map < String , String > aServletInitParams ) { ValueEnforcer . notNull ( aServletClass , "ServletClass" ) ; ValueEnforcer . notEmpty ( sServletPath , "ServletPath" ) ; for ( final ServletItem aItem : m_aServlets ) { // Check path uniqueness if ( aItem . getServletPath ( ) . equals ( sServletPath ) ) throw new IllegalArgumentException ( "Another servlet with the path '" + sServletPath + "' is already registered: " + aItem ) ; // Check name uniqueness if ( aItem . getServletName ( ) . equals ( sServletName ) ) throw new IllegalArgumentException ( "Another servlet with the name '" + sServletName + "' is already registered: " + aItem ) ; } // Instantiate servlet final Servlet aServlet = GenericReflection . newInstance ( aServletClass ) ; if ( aServlet == null ) throw new IllegalArgumentException ( "Failed to instantiate servlet class " + aServletClass ) ; final ServletConfig aServletConfig = m_aSC . createServletConfig ( sServletName , aServletInitParams ) ; try { aServlet . init ( aServletConfig ) ; } catch ( final ServletException ex ) { throw new IllegalStateException ( "Failed to init servlet " + aServlet + " with configuration " + aServletConfig + " for path '" + sServletPath + "'" ) ; } m_aServlets . add ( new ServletItem ( aServlet , sServletPath ) ) ; }
Register a new servlet