|
| 1 | + |
| 2 | +<h1 class="d-xl-block d-none">WebDAV Server Example with Collection Synchronization support</h1> |
| 3 | +<p><span>This sample is a fully functional Class 2 WebDAV server that stores all data in the file system. It supports collection synchronization as per RFC 6578. The <a title="AJAX Library" href="https://www.webdavsystem.com/ajax/">IT Hit WebDAV Ajax Library</a> 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 the server. It is provided in Java and Kotlin, with identical functionality.</span></p> |
| 4 | +<h2>Requirements</h2> |
| 5 | +<ul> |
| 6 | +<li>Java 1.8.</li> |
| 7 | +<li>Apache Tomcat 7.0+ or GlassFish v4.1.1+ or WebLogic 12c+ or JBoss WildFly 9+ or WebSphere 16.0.0.2+.</li> |
| 8 | +<li>Windows OS</li> |
| 9 | +<li>NTFS</li> |
| 10 | +</ul> |
| 11 | +<p>You will also need the <a title="AJAX Library" href="https://www.webdavsystem.com/ajax/">IT Hit WebDAV Ajax Library</a> to display JavaScript UI on a default web page. You can install it from NPM using NPM command line tool, see below. Node.js is <strong>ONLY</strong> required to download the JavaScript files used in the project. Node.js is <strong>NOT</strong> required to run the server.</p> |
| 12 | +<h2>Running the sample</h2> |
| 13 | +<ol> |
| 14 | +<li><strong>Set license.</strong> Download your license file <a href="https://www.webdavsystem.com/javaserver/download/">here</a>. To set the license, edit the 'license' section in \collectionsync<em>\WEB-INF\web.xml</em> and specify the path to the <em>license.lic</em> file. <br> |
| 15 | +<pre class="brush:xml;auto-links:false;toolbar:false"><init-param> |
| 16 | +<param-name>license</param-name> |
| 17 | +<param-value>C:\License.lic</param-value> |
| 18 | +</init-param></pre> |
| 19 | +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.</li> |
| 20 | +<li><strong>Download the IT Hit WebDAV Ajax Library.</strong> You can do this with NPM command-line tool, which is included with Node.js. Install the <a href="https://nodejs.org/en/download/">Node.js</a> and navigate to <code class="code">\collectionsync\WEB-INF\wwwroot\js\</code> folder. Run: |
| 21 | +<pre class="brush:html;auto-links:false;toolbar:false">npm install webdav.client</pre> |
| 22 | +This will download IT Hit WebDAV Ajax Library files into your project. Note that Node.js itself is <strong>NOT</strong> required to run the server, it is used <strong>ONLY</strong> to install the required JavaScript files.</li> |
| 23 | +<li><strong>Configure the storage folder.</strong> By default, this sample publishes documents from the <code class="code">WEB-INF/Storage</code> folder. For the sake of configuration simplicity, documents are extracted from project resources during the first run. You can publish documents from any other folder specifying a path in the 'root' section in <code class="code">web.xml</code>:<br> |
| 24 | +<pre class="brush:xml;auto-links:false;toolbar:false"><init-param> |
| 25 | +<param-name>root</param-name> |
| 26 | +<param-value>C:\Storage\</param-value> |
| 27 | +</init-param></pre> |
| 28 | +</li> |
| 29 | +<li><strong>Configure the application server.</strong> Here we will configure WebDAV server to run on the website root (<code class="code">http://server.com/</code>). <span class="warn"><strong>Note:</strong> While you can configure WebDAV server to run on site non-root (for instance on <code class="code">http://server.com/webdavroot/</code>) 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 do not get the response they will not be able to connect. See also <a title="Working with MS Office" href="https://www.webdavsystem.com/javaserver/doc/ms_office_read_only/">Making Microsoft Office to Work with WebDAV Server</a> and <a title="Opening Docs" href="https://www.webdavsystem.com/ajax/programming/open-doc-webpage/opening_ms_office_docs/">Opening Microsoft Office Documents and Other Types of Files for Editing From a Web Page</a>.</span> |
| 30 | +<ul> |
| 31 | +<li><strong>In the case of Tomcat:</strong><br>Copy <em>\collectionsync</em> folder to <em><Your Tomcat location>\Tomcat x.x\webapps</em> folder. Add the following lines under the <Host> tag in <em><Your Tomcat location></em><em>\Tomcat x.x\conf\server.xml</em>:<br> |
| 32 | +<pre class="brush:csharp;auto-links:false;toolbar:false"><Context path="" debug="0" docBase="collectionsync"> |
| 33 | +</Context></pre> |
| 34 | +<p><span>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 </span><a href="https://www.webdavsystem.com/server/access/">connect to the server with any WebDAV client</a><span>.</span></p> |
| 35 | +<p>If you experience any problems examine the log created by tomcat: <code class="code"><Your Tomcat location>\Tomcat x.x\logs\localhost.xxxx-xx-xx.log</code>.</p> |
| 36 | +</li> |
| 37 | +<li><strong>In the case of Glassfish:</strong><ol type="a"> |
| 38 | +<li>Deploy the collectionsync application. |
| 39 | +<p>From the main tree (<em>Common Tasks</em>) goto <em>Applications</em>.</p> |
| 40 | +<p>Press <em>Deploy</em> and specify following properties:</p> |
| 41 | +<p> - Local Packaged File or Directory That Is Accessible from the Enterprise Server = <path to collectionsync directory></p> |
| 42 | +<p> - Type = Web Application</p> |
| 43 | +<p> - Context Root = /</p> |
| 44 | +<p> Note: sample can be deployed to a non-root context, but some clients work only with servers deployed to root the context.</p> |
| 45 | +<p> - Application Name = collectionsync</p> |
| 46 | +</li> |
| 47 | +<li>Launch the sample. |
| 48 | +<p>From the main tree (<em>Common Tasks</em>) go to <em>Applications</em>.</p> |
| 49 | +<p>Press <em>Launch</em> on collectionsync application.</p> |
| 50 | +<p>If everything was set up properly you should see a sample page with a list of sample files and folders. Now <a href="https://www.webdavsystem.com/server/access/">connect to the server with any WebDAV client</a>.</p> |
| 51 | +<p>If anything goes wrong please consult log usually located at <em><GLASSFISH_INSTANCE_ROOT>/logs/server.log.</em></p> |
| 52 | +</li> |
| 53 | +</ol></li> |
| 54 | +<li><strong>In the case of JBoss WildFly:</strong><ol type="a"> |
| 55 | +<li>By default WildFly restricts access to certain packages from Java SDK. So you need to allow <strong>com.sun.nio.file</strong> package in the <strong>sun/jdk </strong>module by adding the following line in the module.xml file: |
| 56 | +<pre class="brush:xml;auto-links:false;toolbar:false"><path name="com/sun/nio/file"/></pre> |
| 57 | +<p>Restart WildFly.</p> |
| 58 | +</li> |
| 59 | +<li>Deploy the collectionsync application. |
| 60 | +<p>Create folder collectionsync<em>.war </em>under <em><em><WILDFLY_ROOT>/deployments.</em></em></p> |
| 61 | +<p>Copy content of <em>samples/collectionsync </em>to <em><em><em><<em><em>WILDFLY_ROOT</em></em>>/deployments/collectionsync<em>.war.</em></em></em></em></p> |
| 62 | +<p>Create file collectionsync<em>.war.dodeploy in <em><em><<em><em>WILDFLY_ROOT</em></em>>/deployments/collectionsync<em>.war.</em></em></em></em></p> |
| 63 | +<p><span>If everything was set up properly you should see a sample page on the WildFly root context with a list of sample files and folders. Now </span><a href="https://www.webdavsystem.com/server/access/">connect to the server with any WebDAV client</a><span>.</span></p> |
| 64 | +<p>If anything goes wrong please consult log usually located at <em><<em><em>WILDFLY_ROOT</em></em>>/log/server.log.</em></p> |
| 65 | +</li> |
| 66 | +</ol></li> |
| 67 | +</ul> |
| 68 | +</li> |
| 69 | +</ol> |
| 70 | +<h2>The Project Classes</h2> |
| 71 | +<p>On the diagram below you can see the classes in the WebDAV Collectionsyncproject:</p> |
| 72 | +<p><img id="__mcenew" alt="" src="https://www.webdavsystem.com/media/2195/syncdiagram.png" rel="124998"></p> |
| 73 | +<p>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 <a title="Creating WebDAV Server" href="https://www.webdavsystem.com/javaserver/doc/">Creating a Class 1 WebDAV Server</a> and <a title="Class 2 / 3 Server" href="https://www.webdavsystem.com/javaserver/doc/create_class_2_webdav_server/">Creating Class 2 WebDAV Server</a> article as well as in the <a href="http://java.webdavsystem.com/">class reference documentation</a>.</p> |
| 74 | +<p> </p> |
| 75 | +<h3>See Also:</h3> |
| 76 | +<ul> |
| 77 | +<li><a title="Running" href="https://www.webdavsystem.com/javaserver/server_examples/running_webdav_samples/">Running the WebDAV Samples</a></li> |
| 78 | +<li><a title="Troubleshooting" href="https://www.webdavsystem.com/javaserver/server_examples/troubleshooting/">WebDAV Server Samples Problems and Troubleshooting</a></li> |
| 79 | +<li><a title="Creating WebDAV Server" href="https://www.webdavsystem.com/javaserver/doc/">Creating a Class 1 WebDAV Server</a> </li> |
| 80 | +<li><a title="Class 2 / 3 Server" href="https://www.webdavsystem.com/javaserver/doc/create_class_2_webdav_server/">Creating a Class 2 WebDAV Server</a></li> |
| 81 | +</ul> |
| 82 | +<p> </p> |
| 83 | +<p class="p1" style='color: rgba(0, 0, 0, 0.85); line-height: normal; font-family: ".SF NS"; font-size: 26px; margin-bottom: 0px; margin-left: 0px; font-stretch: normal; font-feature-settings: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-variation-settings: normal;'>collectionsync</p> |
| 84 | +<h3 class="para d-inline next-article-heading">Next Article:</h3> |
| 85 | +<a title="Java WebDAV Server for Android" href="https://www.webdavsystem.com/javaserver/server_examples/android/">Java WebDAV Server Example for Android</a> |
| 86 | + |
0 commit comments