loadedServletsByModuleAndClassName.put(moduleDef, moduleServlets);
}
}
synchronized (moduleServlets) {
HttpServlet servlet = moduleServlets.get(className);
if (servlet != null) {
// Found it.
//
return servlet;
}
// Try to load and instantiate it.
//
Throwable caught = null;
try {
Class<?> servletClass = Class.forName(className);
Object newInstance = servletClass.newInstance();
if (!(newInstance instanceof HttpServlet)) {
logger.log(TreeLogger.ERROR,
"Not compatible with HttpServlet: " + className
+ " (does your service extend RemoteServiceServlet?)", null);
return null;
}
// Success. Hang onto the instance so we can reuse it.
//
servlet = (HttpServlet) newInstance;
// We create proxies for ServletContext and ServletConfig to enable
// RemoteServiceServlets to load public and generated resources via
// ServeletContext.getResourceAsStream()
//
ServletContext context = new HostedModeServletContextProxy(
getServletContext(), moduleDef, getShellWorkDirs());
ServletConfig config = new HostedModeServletConfigProxy(
getServletConfig(), context);
servlet.init(config);
moduleServlets.put(className, servlet);
return servlet;
} catch (ClassNotFoundException e) {
caught = e;