WebDAV Server Example with Oracle Back-end, Java
The sample provides Class 2 WebDAV server implementation that can be hosted in Apache Tomcat, GlassFish, JBoss, WebLogic, WebSphere or application server. All data including file content, documents structure and custom attributes is stored in Oracle database. The IT Hit WebDAV Ajax Library is used to display and browse server content on a default web page as well as to open documents for editing from a web page and save back directly to server.
- Oracle Database 10g or later version. Express, Standard or Enterprise Edition.
- Apache Tomcat 7.0+ or GlassFish v4.1.1+ or WebLogic 12c+ or JBoss Wildfly 9+ or WebSphere 18.104.22.168+.
- Java 1.8.
Running the sample
- Create the database. The Oracle database script is located in \samples\oraclestorage\db\OracleStorage.sql file. This script creates tables and populates them with data so your WebDAV server initially has several folders and files. To run the script login to Oracle administration web interface, go to SQL->SQL Scripts->Create, then paste content of OracleStorage.sql to script field, specify a script name and click Run.
It is also recommended to increase the datafile. After creating the database run the following command:
alter database datafile ' C:\oraclexe\oradata\XE\SYSTEM.DBF' resize 4g;
This is especially required if you would like to test WebDAV server running Oracle XE with IT Hit AJAX File Browser.
- Set license. Download your license file here. To set the license edit license section in \oraclestorage\WEB-INF\web.xml and specify the path to the license.XML file. The IT Hit Java WebDAV Server Library is fully functional and does not have any limitations. However, the trial period is limited to 1 month. After the trial period expires the Java WebDAV Server will stop working.
- Download the IT Hit WebDAV Ajax Library. You can do this with NPM command line tool, which is included with Node.js. Install the Node.js and navigate to \oraclestorage\WEB-INF\wwwroot\ folder. Run:
- Configure the application server. Here we will configure WebDAV server to run on the website root (http://server.com/). Note: While you can configure WebDAV server to run on site non-root (for instance on http://server.com/webdavroot/) some WebDAV clients (such as some old versions or Mini-redirector, Microsoft Web Folders and MS Office 2007 and earlier) will fail to connect to non-root server. They submit configuration requests to server root and if they does not get the response they will not be able to connect. See also Making Microsoft Office to Work with WebDAV Server and Opening Microsoft Office Documents and Other Types of Files for Editing From a Web Page.
- In the case of Tomcat:
Copy \oraclestorage folder to <Your Tomcat location>\Tomcat x.x\webapps folder. Add the following lines under the <Host> tag in <Your Tomcat location>\Tomcat x.x\conf\server.xml:
<Context path="" debug="0" docBase="oraclestorage"> <Resource name="jdbc/Oracle" auth="Container" type="javax.sql.DataSource" username="system" password="pwd" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:XE" maxActive="8" maxIdle="4" factory="org.apache.commons.dbcp.BasicDataSourceFactory"/> </Context>
Specify Oracle database login credentials in Context tag. Check you service instance Id in server url.
Finally, restart the Tomcat for configuration changes to take effect.
To see if your server is running type the root URL of your WebDAV site in a browser and you will see the list of folders. Now connect to the server with any WebDAV client.
If you experience any problems examine the log created by tomcat: <Your Tomcat location>\Tomcat x.x\logs\localhost.xxxx-xx-xx.log.
- In the case of Glassfish:
- Create oracle connection pool.
Copy \oraclestorage\WEB-INF\lib\ojdbc6.jar to <GLASSFISH_HOME>/domains/domain1/lib/ext folder. Note that "domain1" is a default Glassfish domain. The domain may be different for specific deployments.
Open administrative console of the Glassfish server.
From the main tree (Common Tasks) expand Resources and go to JDBC > Connection Pools. Create a Connection pool:
- JNDI name = Oracle
- resource_type = javax.sql.ConnectionPoolDataSource
- Database Vendor = Oracle
Specify following additional properties (replace following values with your specific):
- url = jdbc:oracle:thin:@localhost:1521:XE
- user = system
- password = password
- xa-driver-does-not-support-non-tx-operations = true
Test connection with Ping button.
- Create DataSource.
From the main tree (Common Tasks) expand Resources and go to JDBC > JDBC Resources.
Press New and provide the following information:
- JNDI Name: JDBC/Oracle (must be called exactly like this).
- Pool Name: The pool name created in the previous section.
Press OK, JDBC-resource will be created.
- Deploy oracle storage application.
From the main tree (Common Tasks) goto Applications.
Press Deploy and specify following properties:
- Local Packaged File or Directory That Is Accessible from the Enterprise Server = <path to oracle storage directory>
- Type = Web Application
- Context Root = /
Note: sample can be deployed to a non-root context, but some clients work only with servers deployed to root the context.
- Application Name = oraclestorage
- Launch sample.
From the main tree (Common Tasks) go to Applications.
Press Launch on oracle storage application.
If everything was set up properly you should see a sample page with a list of sample files and folders. Now connect to the server with any WebDAV client.
If anything goes wrong please consult log usually located at <GLASSFISH_INSTANCE_ROOT>/logs/server.log.
- Create oracle connection pool.
- In the case of Tomcat:
The Project Classes
On the diagram below you can see the classes in WebDAV OracleStorage project.
To adapt the sample to your needs, you will modify these classes to read and write data from and into your storage. You can find more about this in Creating a Class 1 WebDAV Server and Creating Class 2 WebDAV Server article as well as in the class reference documentation.
How Things Get Stored – Overview of the Oracle Back-end
The database consists of 3 entities as depicted in the figure below.
All the information about files and folders along with their content is stored here. Following is the list of columns with a brief description of each field.
The Lock table stores lock applied to items. You can find more about locking in the Creating Class 2 WebDAV Server article.
All the information about the properties pertaining to each item is stored in Properties table.