ohhh see I was adding contexts one at a time, in a loop rather than all
at once (we really should encapsulate the context in the adapter as a
constructor param, since its mandatory for and relative to the
grizzlyadapter :) )
heres how I have been doing it:
This
is the bean that holds servlets/GrizzlyAdapters and their relitive
contexts, I refer to this as a ServletServer as it makes more sence (to
me) to load servlets into a server.
-----------------------------------
public class ServletServer{
private HashMap<String, ServletAdapter> ServletAdapters = new HashMap<String, ServletAdapter>();
public ServletServer(Servlet ServletClass, String ServletContext) {
addServlet(ServletContext, ServletClass);
}
public ServletServer() {
}
/**
* Adds a new servlet to this server, will overwrite an existing instance if
* the contexts collide.
*
* @param Context <b the context/uri for this servlet >
* @param ServletInstance
*/
public void addServlet(String ServletContext, Servlet ServletInstance){
ServletAdapter sa = new ServletAdapter();
sa.setServletInstance(ServletInstance);
// sa.setRootFolder(OortFileUtils.instance.getObjectsDirectory(ServletInstance));
sa.setHandleStaticResources(true);
sa.addInitParameter("default-encoding", "UTF-8");
sa.setContextPath(ServletContext);
sa.setProperty("load-on-startup","1");
this.ServletAdapters.put(ServletContext, sa);
}
public HashMap<String, ServletAdapter> getServletAdapters() {
return ServletAdapters;
}
}
And here is the controller code that loads these adapters into the GrizzlyWebserver from the bean
-------------------------------------------------
public void doLoadServletServer(ServletServer servletServer){
HashMap<String, ServletAdapter> servletStore = servletServer.getServletAdapters();
for(String context: servletStore.keySet()){
ServletAdapter sa = servletStore.get(context);
// String RootFolder = OortFileUtils.getObjectsDirectory(servletStore.get(context));
// sa.setRootFolder(RootFolder);
loadServletAdapter(sa);
}
}
private void loadServletAdapter(ServletAdapter sa){
OortDebug.out.print("About to load servlet: "+sa.getContextPath()+" to root folder: "+sa.getRootFolder() , this);
this.Server.addGrizzlyAdapter(sa, new String[]{sa.getContextPath()});
}