Accessing File Resources from Active Web

One of the key differences in the web application environment and that of the Concerto application server is the way in which an Active Web application can access file-based resources.

Whilst the web application specification clearly defines how a web application is deployed it does leave it up to the discretion of the container whether or not the WAR file is expanded into the physical file system of the machine running the container software.  For example the public domain containers from The Apache Group (www.apache.org) decompress a WAR file into a webapps directory, and the application then runs directly from the local file system.  Other Java Application Servers like BEA WebLogic, IBM WebSphere and Silverstream do not, and the web application pages are accessed directly from the web archive file without decompression.

This has a fundamental effect on how you as a developer should write an application so that it is portable across the widest variety of web application containers.  For this reason the Active Web script objects that access files have been updated to support this model.  When deploying in a container that expands the web application archive there is no impact on the existing application; for example creating a FileWriter on /stock/stocklist.txt would work in the above example. If however the container did not expand the Web Application then the FileWriter object would fail to create the file and the application would have to be amended to act accordingly.  When these situations occur you should look to use the root_path parameter of the servlet to provide an application server portable mechanism for implementing the file access functionality.

The following table outlines the effect this behaviour has on each of the affected objects in the Active Web object model.

Script Object

Resource Access Impact

BinaryFile

On construction if the path specified in the constructor cannot be resolved to a physical path then a runtime error will occur with the message "Failed to convert path to physical file".

File

On construction if the path specified in the constructor cannot be resolved to a physical path then a runtime error will occur with the message "Failed to create real file from path"

FileWriter

FileReader

On construction if the path specified in the constructor cannot be resolved to a physical path then a runtime error will occur.

ObjectFile

On construction if the path specified in the constructor cannot be resolved to a physical path then a runtime error will occur.

 

copyTo function: Should the target filename unable to be resolved to a physical path then the function will cause a runtime error.

XMLWriter

toFile function: Should the writer be unable to create the destination file then the XMLWriter object will have its error property set to the error text.

Comment on this topic

Topic ID: 150001