首页 > 关于我们 > 技术文摘
OA办公:如何使用Tomcat搭建WebDav文件存储服务器
发布时间:

O2OA服务器支持使用webdav协议来存储二进制文件.

Tomcat默认是支持WebDAV的,且默认为禁用状态.

可以开启Tomcat的webdav作为文件存储服务器.

开启步骤如下:

1.在tomcat的webapp是目录下创建一个webdav目录作为项目.

2.在webdav目录下创建WEB-INF/web.xml

web.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>webdav</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>webdav</servlet-name>
        <servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <!-- Read-Write Access Settings -->
        <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <!-- URL Mapping -->
    <servlet-mapping>
        <servlet-name>webdav</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>webdav</web-resource-name>
            <!-- Detect WebDAV Methods in URL For Whole Application -->
            <url-pattern>/*</url-pattern>
            <http-method>PROPFIND</http-method>
            <http-method>PROPPATCH</http-method>
            <http-method>COPY</http-method>
            <http-method>MOVE</http-method>
            <http-method>LOCK</http-method>
            <http-method>UNLOCK</http-method>
        </web-resource-collection>
        <!-- Restrict access by role -->
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>webdav</realm-name>
    </login-config>
    <security-role>
        <description>WebDAV User</description>
        <role-name>webdav</role-name>
    </security-role>
</web-app>

3.在tomcat/conf目录下的tomcat-users.xml文件中添加webdav访问用户

4.启动Tomcat

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
  <role rolename="webdav"/>
  <user username="admin" password="admin" roles="webdav"/>
</tomcat-users>

5.在o2server/configSample目录下拷贝externalStorageSources.json到o2server/config目录

修改配置指向webdav

{
  "file": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/file/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "processPlatform": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/processPlatform/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "mind": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/mind/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "meeting": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/meeting/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "calendar": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/calendar/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "okr": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/okr/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "cms": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/cms/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "bbs": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/bbs/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "report": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/report/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "strategyDeploy": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/strategyDeploy/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "teamwork": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/teamwork/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ],
  "structure": [
    {
      "protocol": "webdav",
      "username": "admin",
      "password": "admin",
      "host": "127.0.0.1",
      "port": 8080.0,
      "prefix": "/repository/default/structure/",
      "enable": true,
      "weight": 100.0,
      "name": "251",
      "deepPath": false,
      "###protocol": "协议,可选值ftp,webdav###",
      "###username": "登录用户名.###",
      "###password": "登录密码.###",
      "###host": "主机地址.###",
      "###port": "端口.###",
      "###prefix": "前缀路径.###",
      "###enable": "是否启用###",
      "###weight": "设置权重.###",
      "###name": "存储节点名,对应存储名称,谨慎修改.###",
      "###deepPath": "是否使用更深的路径.###"
    }
  ]
}

6.在o2server/config目录下将node_xxx.xxx.xxx.xxx.json中的storage服务器设置为禁用.

  "storage": {
    "enable": false,
    "port": 20040.0,
    "sslEnable": false,
    "name": "251",
    "accounts": [],
    "prefix": "",
    "deepPath": false,
    "###enable": "是否启用,对于二进制流文件,比如附件,图片等存储在单独的文件服务器中,可以支持多种文件服务器,默认情况下使用ftp服务器作为文件服务器,每个节点可以启动一个文件服务器以提供高性能.###",
    "###port": "ftp服务器端口,此端口可以不对外开放,仅有ApplicationServer进行访问,并不直接对用户提供服务.###",
    "###sslEnable": "是否启用ssl传输加密,如果启用将使用config/keystore文件作为密钥文件.使用config/token.json文件中的sslKeyStorePassword字段为密钥密码,sslKeyManagerPassword为管理密码.###",
    "###name": "名称,多个节点中不能重名,默认为251.###",
    "###accounts": "二进制流文件是分多个账号分段存储的,可以单独设置每个分类的存储配置,一般不需要设置.###",
    "###passivePorts": "ftp传输有主动和被动之分,如果使用了被动传输,设置被动端口范围,默认为29000-30000.###",
    "###prefix": "路径前缀.###",
    "###deepPath": "使用更深的路径###"
  }

7.启动服务器o2server服务已经将存储转向tomcat服务器所提供的webdav服务.

📎tomcat-users.xml

📎webdav.zip