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