/**
* Instantiates the Grizzly 2 Web Server
*/
private void instantiateGrizzlyWebServer() {
final ServletHandler handler = new ServletHandler();
Servlet servletInstance;
if( servletClass != null) {
try {
servletInstance = (Servlet) servletClass.newInstance();
} catch (InstantiationException ex) {
throw new TestContainerException(ex);
} catch (IllegalAccessException ex) {
throw new TestContainerException(ex);
}
handler.setServletInstance(servletInstance);
}
for(Class<? extends EventListener> eventListener : eventListeners) {
handler.addServletListener(eventListener.getName());
}
for(String contextParamName : contextParams.keySet()) {
handler.addContextParameter(contextParamName, contextParams.get(contextParamName));
}
for(String initParamName : initParams.keySet()) {
handler.addInitParameter(initParamName, initParams.get(initParamName));
}
if(contextPath != null && contextPath.length() > 0) {
if( !contextPath.startsWith("/") ) {
handler.setContextPath("/" + contextPath);
} else {
handler.setContextPath(contextPath);
}
}
if(servletPath != null && servletPath.length() > 0) {
if( !servletPath.startsWith("/") ) {
handler.setServletPath("/" + servletPath);
} else {
handler.setServletPath(servletPath);
}
}
// Filter support
if ( filters!=null ) {
try {
for(WebAppDescriptor.FilterDescriptor d : this.filters) {
handler.addFilter(d.getFilterClass().newInstance(), d.getFilterName(), d.getInitParams());
}
} catch (InstantiationException ex) {
throw new TestContainerException(ex);
} catch (IllegalAccessException ex) {
throw new TestContainerException(ex);