To ensure that the connection to the SIMULIA Execution Engine is established before any API calls are made, you can have the Web application implement a ServletContextListener class with the following ServletContextListener method: public void contextInitialized(ServletContextEvent arg0) This method is called by the servlet container before any servlet or filter in the Web application is initialized. Next, perform one-time initialization. This class must be named in the web.xml file in a <listener-class> tag. For example: <listener> <listener-class>com.mycompany.MyServletContextHandler</listener -class> </listener> The initialization method must do the following:
How step 2 and step 3 above are done depends on how the Web application is to be configured. The Web application developer must decide how the Web administrator will specify the names of local directories and the name and port number of the SIMULIA Execution Engine. In some cases it may be acceptable to hard-code these values (e.g., in a services deployment for a particular customer). The developer may choose to obtain them from JVM system properties (specified by the Web server administrator), or the developer may retrieve them from the web.xml deployment file. It is up to the Web application developer to determine how and when the application will be configured. The SysFiper class contains all the methods necessary to initialize the APIs. The local directory names are supplied on the SysFiper.setFiperEnv() method, and the server connection is initialized on the SysFiper.initConnection() method. There are three ways in which the Web application can supply server connection information by calling different forms of the initConnection() method on SysFiper:
The following is a sample ServletContextListener.contextInitialized() method. It obtains the Isight installation directory name from the Web deployment descriptor (web.xml file). The name of the SIMULIA Execution Engine server is hard-coded in this case: public void contextInitialized(ServletContextEvent arg0) { //Perform one-time application initialization. try { // Lookup the location of the Fiper installation // in the environment settings, as defined // in the web.xml deployment descriptor. Context env = (Context)new InitialContext().lookup ("java:comp/env"); String esiHome = (String)env.lookup("esihome"); // Init the Fiper system environment, disallow native code in server SysFiper.setFiperEnv(esiHome, null, false); // Setup connection properties for Fiper server Properties connProps = new Properties (); connProps.put ("server", "stingray"); // IP DNS name of Fiper server connProps.put ("port", "2809"); // IIOP port (bootstrap address) connProps.put ("Sys_ServerSupportDir", "websphere"); //Server dir // Init the Fiper ACS connection SysFiper.initConnection (connProps); } catch (Throwable t) { // The ServletContextListener interface defines no THROWS clause on // this method, so we can only throw runtime exceptions. Most web // containers will report this in their log or console file. throw new RuntimeException (“Failed to initialize Fiper API.”, t); } } The installation directory name in this example is read from the servlet context. The web.xml deployment descriptor must have the “esihome” environment setting specified. For example, in the Eclipse development environment the settings are specified on the Variables tab of the Web Deployment editor. The environment variables are entries in the web.xml file:
<env-entry>
<env-entry-name>esihome</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>C:\SIMULIA\Isight\2017</env-entry-value>
</env-entry>
The SIMULIA Execution Engine connection properties are placed directly into a Properties object and passed to the SysFiper.initConnection() method. The property names are exactly the same as those that would appear in a CPR file. In this example, the server name and port number are hard-coded. Once this initialization has been completed, the servlet can make any SIMULIA Execution Engine API calls. For example, the following servlet will display the ID of the user and the list of jobs the user has run. // Import Java SDK classes import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; // Import J2EE classes import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // Import Fiper classes import com.engineous.sdk.pse.JobInfoValue; import com.engineous.sdk.pse.SysPSE; /** * Sample Fiper servlet that returns a web page containing the * current user’s ID and list of Fiper jobs. */ public class MyFiperServlet extends javax.servlet.http.HttpServlet { /** * Defer to POST method */ protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost (request, response); } /** * Generate HTML response to the browser. */ protected void doPost (HttpServletRequest request, HttpServletResponse response throws ServletException, IOException { // Prepare to write HTML response response.setContentType (“text/html”); PrintWriter out = response.getWriter(); // HTML header tags out.println (“<html><head><title>Sample Fiper Web Application</title> </head>”); out.println (“<body>”); try ( // Call Fiper APIs to get user ID String userId = SysPSE.getPSE().getUserId(); out.println (“FIPER user = ” + userId); // Call Fiper APIs to get list of jobs for this user Iterator jobList = SysPSE.getPSE().getJobList(userID).iterator(); while (jobList .hasNext () ) { JobInfoValue jobInfo = (JobInfoValue)jobList.next (); out.println (“<br>Job ”+jobInfo.getID()) ; } } catch (Throwable t) { out.println (“<br>Error: ”+t.toString () + “</b>”); } // Finish the HTML out.println (“</body></html>”); out.close (); } } |