package org.cipres.webapp.guigen.servlet; import java.io.*; import javax.servlet.ServletException; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.http.*; import org.cipres.guigen.*; import org.cipres.communication.Facilitator; import org.cipres.helpers.RegistryForApplet; import org.cipres.helpers.RegistryForAppletInitializer; import org.cipres.guigen.command.ServiceCommands; import org.cipres.guigen.command.ServiceCommandsLoader; import org.cipres.helpers.CommandObjectWrapper; /** * */ public class GuigenServlet extends HttpServlet { final static String paramFileRoot = "WEB-INF/classes/conf"; RegistryForApplet appletRegistry; // one time init happens here, before the servlet processes requests. public void init(ServletConfig config) throws ServletException { super.init(config); try { System.out.println("CIPRES_ROOT is " + System.getenv("CIPRES_ROOT")); System.out.flush(); Facilitator.initialize("GuigenServlet"); appletRegistry = RegistryForAppletInitializer.createRegistryForApplet(); } catch(Exception e) { throw new ServletException(e); } } /** * */ public void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setContentType("application/x-java-serialized-object"); System.out.println("HI TERRI XXX"); System.out.flush(); /* The applet tells us the name of a service commands file to use. What we do is - extract the name of the top level tool, look up that tool in the registry and send the guixml for the tool back to the applet as a CmdParam object, also send the ServiceCommands so the applet can use them to initialize the gui. - also send the name of the top level tool and its uid so that the applet can include that info in the CommandObject it sends back. GuigenSevlet2 takes the CommandObject and turns it into a parameter file that can be run by RunServiceApp. */ InputStream in = request.getInputStream(); ObjectInputStream inputFromApplet = new ObjectInputStream(in); String cmdxml = (String) inputFromApplet.readObject(); inputFromApplet.close(); ServletContext ctx = getServletContext(); String root = ctx.getRealPath("/"); String filename = root + "/" + paramFileRoot + "/" + cmdxml; String topLevelTool, topLevelUiid; File f = new File(filename); // Read in the service commands file. System.out.println("READING IN XML FILE: " + f.getAbsolutePath()); ServiceCommands sc = ServiceCommandsLoader.deserialize(f); topLevelTool = sc.getServiceUid(); topLevelUiid = sc.getServicePanelName(); System.out.println("top level tool and id from " + cmdxml + " is " + topLevelTool + ", " + topLevelUiid); System.out.flush(); // Get the guixml from the registry as a CmdParam object. CmdParam uiparam = appletRegistry.getUiXmlBean(topLevelTool); // Send the info to the applet. OutputStream outstr = response.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(outstr); oos.writeObject(uiparam); // Send serialized CommandParam object that represents the uixml oos.writeObject(appletRegistry); // Send a registry wrapper that guigen running in the applet will use if the uixml // contains any fields that call for choosing a service. oos.writeObject(topLevelTool); // Send the "name" of the service. oos.writeObject(topLevelUiid); // Send the registry entry for the service. oos.writeObject(sc); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); } } }