Getting started with the Apache Wink WebDAV JAX-RS extension

This page is the starting point for learning about the WebDAV JAX-RS extension library. The following topics are covered:

Overview

Web-based Distributed Authoring and Versioning (WebDAV) is a defined set of HTTP methods and responses to allow users to read and write documents on a web server. Most websites today use basic HTTP to allow users to easily read data using HTTP GET methods and to create and modify data using HTTP POST and PUT methods. WebDAV enhances the ability to manage, edit, and write documents by providing features to set and read document properties, lock resources, and support for collections. WebDAV defines a set of HTTP methods and request and response entity formats to form the WebDAV protocol.

The Apache Wink WebDAV JAX-RS extension library helps JAX-RS application developers build WebDAV-compliant services. It provides a JAXB data model of the WebDAV XML to help read requests and write responses, helper classes to build responses, and JAX-RS based extensions to more easily build WebDAV services.

The JAXB model is provided in the org.apache.wink.webdav.model package. Helper classes include org.apache.wink.webdav.server.WebDAVResponseBuilder, which builds appropriate WebDAV responses with various properties. In the org.apache.wink.webdav package, JAX-RS compatible @HttpMethod annotations are available for the WebDAV HTTP methods and constants for common WebDAV HTTP headers and properties. See the API documentation for more details.

Prerequisites

Read the IBM JAX-RS documentation to add the appropriate JAX-RS JARs to your classpath for your development environment. Once you've added the appropriate JAX-RS API and implementation to your development classpath, you can use the JAX-RS programming model to develop your WebDAV application.

You can check the JAX-RS documentation by clicking the appropriate link:

WebSphere Application Server Version 6.1 JAX-RS Documentation.

WebSphere Application Server Version 7.0 JAX-RS Documentation.

WebSphere Application Server Version 8.0 JAX-RS Documentation.

To build services with the Apache Wink WebDAV JAX-RS extension library, add the wink-jaxrs-webdav.jar to your web application's WEB-INF/lib directory when developing and assembling your application. You can find the wink-jaxrs-webdav.jar file in <INSTALL_ROOT>/web2mobilefep_1.1/optionalLibraries/jaxrs_1.X/webdav. For WebSphere Application Server Community Edition, you can find the wink-jaxrs-webdav.jar file in <INSTALL_ROOT>/web2mobilefep_1.1/AppServices/optionalLibraries/wink-jaxrs-webdav.

By adding the extension library to your application, you gain the WebDAV JAXB model and other helper utility methods that enhance the JAX-RS programming model.

Using the Apache Wink WebDAV JAX-RS extension library

You can use the WebDAV extension library to write JAX-RS methods and resources that can communicate using the WebDAV protocol.

Here is a sample resource method.:

@WebDAVMethod.PROPFIND
@Produces(MediaType.APPLICATION_XML)
public Response findProperties() throws IOException {
     SyndFeed feed = /* create an Apache Wink SyndFeed */;
     return WebDAVResponseBuilder.propfind(feed);
}

The previous method responds to any HTTP PROPFIND method requests, and using the WebDAVresponseBuilder, the resource method returns a response with the feed data.

A JAXB model is provided in the org.apache.wink.webdav.model Java package to help write responses and read requests. For instance, if you want to parse a WebDAV lock request, you could use the following to read the XML:

String bodyContent = /* the XML request */
Unmarshaller unmarshaller = WebDAVModelHelper.createUnmarshaller();
Lockinfo lockinfo = WebDAVModelHelper.unmarshal(unmarshaller,
                                                new StringReader(bodyContent),
                                                Lockinfo.class,
                                                "lockinfo");

In addition, you can use a few resource classes to help you get started with creating WebDAV resources.

WebDAVResource provides an @OPTIONS method that adds the WebDAV appropriate headers.:

@Path("/myresource/")
public class MyResource extends org.apache.wink.webdav.server.WebDAVResource {
    /* get an @OPTIONS annotated JAX-RS resource method implementation from WebDAVResource */

    /* implement your own WebDAV methods */
}

WebDAVLockableResource provides a few stub methods for performing WebDAV locking and unlocking. They do not perform a real lock but provide a fake lock to satisfy compatibility with certain platforms.:

@Path("/myresource2/")
public class MyResource2 extends org.apache.wink.webdav.server.WebDAVLockableResource {
    /* get @LOCK and @UNLOCK stub methods for compatibility */

    /* implement your own WebDAV methods */
}