public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
//dynamic register /SampleServlet3Dynamic and security constraint
Dynamic servlet3Dynamic = servletContext.addServlet("SampleServlet3Dynamic", SampleServlet3.class);
servlet3Dynamic.addMapping("/SampleServlet3Dynamic", "/TestDynamic");
HttpConstraintElement httpConstraintElement = new HttpConstraintElement();
List<HttpMethodConstraintElement> httpMethodConstraintElements = new ArrayList<HttpMethodConstraintElement>();
httpMethodConstraintElements.add(new HttpMethodConstraintElement("GET", new HttpConstraintElement(ServletSecurity.TransportGuarantee.NONE, "RoleC")));
ServletSecurityElement servletSecurityElement = new ServletSecurityElement(httpConstraintElement, httpMethodConstraintElements);
Set<String> uneffectedUrlPatterns = servlet3Dynamic.setServletSecurity(servletSecurityElement);
if (uneffectedUrlPatterns.size() == 0) {
throw new RuntimeException("/SampleServlet3Dynamic should be returned as it is defined in the web.xml file");
}
servlet3Dynamic.addMapping("/TestDynamicAfter");
}