PageBox |
|
|
|
|
|
Presentation | Download | User guide | Implementation | Epimetheus | euroLCC | Prometheus |
Pandora implementationForewordObjectiveThis document presents the implementation of Pandora. Pandora is not a comprehensive application. Pandora fully implements aspects specific to a PageBox-enabled application but it doesn’t implements things like an administration and a mean allowing adding new articles. This limitation makes the implementation easier to understand and adapt. Pandora can be used as the skeleton of a real application. AudienceProgrammers who want to implement a PageBox-enabled Web application or adapt an existing application for a PageBox deployment. Design choices
The reference implementation of Pandora uses the MySQL database (tested with MySQL 3.23.53) and the MySQL Connect/J 2 JDBC driver. Data modelPandora uses three tables:
article describes the referenced articles. An article has a unique ID, a name and a unit price. The article table also contains the available number of articles (qty) and the number of article sold on this Pandora instance. command describes the commands. A command has a unique ID, data allowing charging a customer (name), data allowing delivering the command (addr,) the URL of the Payment facility Web service (payment,) the URL of the Delivery facility Web service (delivery) and the date when the command was made. name can contain the user ID, the user name, a billable account or an identifier returned by a payment facility. addr can contain the user address and mail address, the user office # and telephone #. Pandora doesn’t interpret the content of name and addr: the name and addr fields can have different formats on different Pandora instances. The only requirement is that the name format is understood by the payment facility and that the addr format is understood by the delivery facility. item describes an item of a command. An item is uniquely identified by a command ID and by an article ID. An item has also a number of articles (qty.) ComponentsThe Pandora deliverables include:
Pandora uses the PageBox API. See the PageBox API documentation for more details. Use casesDistributed applicationThe distributed application implements a user interface that allows customers creating commands, adding, updating or deleting items in the command and committing commands.
Central applicationThe distributed application periodically sends the filed commands to the central application. Then the central application issues payment and delivery requests and returns an updated inventory to the distributed application.
Sandbox checkingPageBox version 0.0.7 implement a Java 2 security. With this security a deployed application cannot read and write files everywhere, run commands, use native code or create and use a class loader. Sandbox checking is a working example allowing PageBox administrators to check that the security is properly set. The distributed and the central applications and the payment/delivery mockup call this facility. CheckSandboxCheckSandbox exercises the sandbox in its constructor. The constructor calls the following methods:
checkReadcheckRead tries to read the file whose path was given as parameter and to log lines found in the file. checkWritecheckWrite tries to write "CheckSandbox" in the file whose path was given as parameter and then to delete this file. checkCmdcheckCmd uses the Runtime to try executing the command given as parameter and waiting for its completion. checkLoadcheckLoads tries calling the static write method of the CheckLoad class. checkClassLoadercheckClassLoader tries
CheckLoadCheckLoad implements a minimalist native interface:
loadLibrary loads the library defined in CheckSandbox.chkLib when write is called for the first time (when the statics of CheckLoad are created.) CheckClassLoaderCheckClassLoader extends ClassLoader. Its most important class is loadClass that gets called each time a program (or the JVM) requires a class load. loadClass loads classes from the directory given to the constructor and caches them in a classes map for subsequent requests. Distributed applicationThe distributed application contains eight components:
CommandCtrl retrieves a CommandBean instance from the Session, parses the user request and updates the CommandBean instance. Then CommandCtrl forwards the request to common.jsp using RequestDispatch.forward. common.jsp retrieves the CommandBean instance from the Session and calls its properties to display the form. NeighborCtrl
neighbor.jsp retrieves the NeighborBean instance from the request attribute and calls its getClones method to display the URLs of the distributed application installed from the same Repository. command.jspcommand.jsp shows a form that:
CommandBean.javaCommandBean implements the following read-only properties for command.jsp:
CommandBean implements its properties using an article map called articles and an item map called items. CommandCtrl.javaCommandCtrl is a servlet and implements the servlet init, doGet and doPost methods. Both doGet and doPost implement the object creation logic:
createCb uses the PageBox API to read the article list from the database and initiate the CommandBean instance. Then doGet and doPost store the CommandBean instance in the Session object. The distributed application uses HTTP POST. Therefore doPost must also parse the user request. The user request can be:
Before looking at these methods we must present how CommandCtrl handles the database tables.
The Article class is defined like this:
Where:
Initially the article table and therefore the Articles objects contain what the installation class has set. Then each time it calls the Update Web service Publish gets an updated article list and updates the article table. The distributed application cannot sell more than qty but when concurrent customers ask for the same article in different sessions. See the presentation of the demo for a full explanation of this mechanism. The Item class is defined like this:
Where qty is the number of articles with a given article ID in the command. updateupdate retrieves the Item object corresponding to the selected item and updates its qty field with the number entered by the user. update rejects the update request if the requested quantity is higher than the qty of the article. addIf there is already an Item object for this article, add adds to its qty the number entered by the user. Add rejects the add request if the total quantity is higher than the qty of the article. If there is no Item object for this article, add creates an Item object and sets its qty with the number entered by the user. add rejects the add request if the requested quantity is higher than the qty of the article. deletedelete removes the Item object corresponding to the selected item from the items Map. checkReferrerThe distributed application doesn’t implement a authentication mechanism of its own or provided by the Application server. Instead it trusted referrer sites that can prove their identity. CheckReferrer first checks if the user information is already stored in the Session. User information is made of four fields and four Session attributes:
If the user information is not yet stored in the Session checkReferrer assumes that the user is coming from a trusted application that has properly set the user information in HTTP POST data and proven that it is a trustable referrer. checkReferrer expects that the user request contains six fields:
checkReferrer verifies that the name is signed with the certificate passed in parameter, which implies that the referrer owns the private key corresponding to the certificate. The referrer site page shows an example of valid link to the distributed application. Then checkReferrer stores the user information in Session attributes. Note: In a production environment you must also check that the certificate was issued by a trusted authority. commitcommit records the command stored in CommandBean in the command and item tables. It also updates the article table. commit
Publish.javaPublish extends Thread: its run method runs in an independent thread created when Publish is instantiated at the first invocation of CommandCtrl. Publish sends the commands recorded in the command and item tables in batch to the central server using an Update Web service. The Update Web service implements the UpdateIF interface:
Publish has three methods, its constructor, its run method and an update method. PublishThe Publish constructor retrieves the URL of the Update Web service in a central.txt file. Then it instantiates an Update Web service stub, sets its URL and starts the Thread. Then run is called. runrun calls the update method every period. period is a context parameter. updateupdate
Note: In a production implementation the article table would probably contain a validity range: An article would have a price and an available quantity between a date A and a date B. It would be possible to remove an article. These functions are easy to implement but wouldn’t improve the clarity of the Pandora example. Install.javaThe Install class implements the InstallIF interface and is called by the PageBox once the archive has been installed on the target Application server and before the archive is dynamically deployed on the Application server. For more information about the Installation interface see the developer guide and the installation guide. The same installation class is used by all applications. However only the distributed and the central application need a database update. The table below summarizes the use of the installation class features by the applications:
If it doesn’t contain the update placeholder the application web.xml file is not updated. If the PageBox administrator has not configured the JDBC info in rules.xml, the database update is not performed (case of the payment and delivery applications.) installThe install method is a method of the InstallIF interface. The install method is called by PageBox to perform a post installation. In case of update the install method of the Pandora installation class drops the article table with the dropArticle method and re-create/populate the article table with the createArticle method. In case of new installation the install method of the Pandora installation:
uninstallThe uninstall method is a method of the InstallIF interface. The uninstall method is called by PageBox to perform a de-installation. In case of de-installation for update uninstall does nothing. Otherwise uninstall drops all Pandora tables with the drop method. dropdrop calls dropArticle to drop the article table and drops the command and item tables. createcreate creates the command and item tables and calls the createArticle method to create and populate the article table. dropArticledropArticle drops the article table. createArticlecreateArticle creates the article table. Then it reads an article.csv file from the archive directory. article.csv must contain four columns separated by commas:
For each row in the article.csv file createArticle inserts a record in the article table. updateWebXmlupdateWebXml illustrates configuration updates in installation classes. The web.xml is expected to contain a workdir context parameter with an update placeholder:
updateWebXml replaces <!--Install_wordir--> by the archive directory. Here is how it works. updateWebXml
Referrer site pagesThe referrer site pages are designed to simulate an actual authentication mechanism. The referrer environment is made of three components:
login.jsplogin.jsp displays a form with four text area:
When the user clicks on the Login button login.jsp stores these data in Session attributes. link.jsplink.jsp implements two mechanisms:
When it is called link.jsp retrieves the user name from a Session attribute, instantiates a LinkBean object and sets its name property. Both mechanisms described above are actually implemented in a goto script and in a PandoraForm hidden form. The automatic redirect is triggered by <body onload="goto();"> whereas the link is triggered by <a onClick="goto();" goto is implemented like this:
action contains the URL of CommandCtrl. In the code above we can set a relative URL because the Referrer site components are packaged in the distributed application. On production systems the referrer site and the distributed applications are not hosted by the same Web application and often even by the same Web site. In these cases the URL has to be a full URL. To pass the information needed by CommandCtrl.checkReferrer the PandoraForm hidden form is coded like this:
Where lb is the LinkBean instance. LinkBean.javaLinkBean implements a constructor, a Name write property and two read properties, Cert and Signature. LinkBeanThe LinkBean constructor takes four parameters:
Note: In a production environment the keystore and the (name, password) uples should not be accessible even in read mode to prevent security and repudiation problems. In the future we plan to support the automated distribution of link pages with PageBox. These pages will then be used in existing Web applications. It can imply some enhancements of the installation process. Here is an example of invocation from link.jsp:
The constructor loads the key store and retrieves the certificate and private key from the key store. setNamesetName stores the name in a member variable. getCertgetCert returns the certificate. getSignaturegetSignature signs the name with the private key and returns the signature. Central applicationThe central application
Therefore the central application can also be deployed using PageBox and the same installation class as the distributed application. The main part of the central application is the implementation of the Update Web service, UpdateImpl. UpdateImpl.javaUpdateImpl implements the UpdateIF and the ServiceLifecycle interfaces. The main methods of UpdateImpl are init and update. initinit is a method of the ServiceLifeCycle interface. init is called just before the first Web service invocation. init retrieves the directory of the Central application from a context variable, workdir. Then init creates a PageBox API instance and creates a stub for the Query Web service of the payment and delivery facilities. updateupdate is the method of the UpdateIF interface (and of the Update Web service.) update uses the PageBox API to get a database connection. Then for each Command object in the orders array update:
The Art class is defined like this:
update stores in the arts map the quantity of articles sold and still available for sale. Next for each article in arts update updates the quantity sold and available in the corresponding record in the article table. Eventually update reads the article table to build the Article array returned by the Web service. Payment/deliveryThe payment and delivery mockups implement the Query Web service and use the PageBox API. Therefore the payment and delivery mockups can also be deployed using PageBox and the same installation class as the distributed and central applications. The Query Web service has the following interface:
Where
The main part of the central application is the implementation of the Query Web service, QueryImpl. QueryImpl.javaQueryImpl implements the QueryIF and the ServiceLifecycle interfaces. The main methods of QueryImpl are init and query. initinit is a method of the ServiceLifeCycle interface. init is called just before the first Web service invocation. init retrieves the directory of the Central application from a context variable, workdir. Then init creates a PageBox API instance. queryquery is the method of the QueryIF interface (and of the Query Web service.) In this mockup query simply logs the request and returns a fake status.
Contact:support@pagebox.net |
|