2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.jackrabbit
.remote
;
19 import java
.io
.IOException
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.SimpleCredentials
;
23 import javax
.servlet
.ServletException
;
24 import javax
.servlet
.http
.HttpServletRequest
;
25 import javax
.servlet
.http
.HttpServletResponse
;
27 import org
.apache
.commons
.logging
.Log
;
28 import org
.apache
.commons
.logging
.LogFactory
;
29 import org
.apache
.jackrabbit
.server
.SessionProvider
;
30 import org
.apache
.jackrabbit
.webdav
.simple
.ResourceConfig
;
31 import org
.apache
.jackrabbit
.webdav
.simple
.SimpleWebdavServlet
;
32 import org
.argeo
.ArgeoException
;
33 import org
.springframework
.core
.io
.Resource
;
35 public class WebDavServlet
extends SimpleWebdavServlet
{
37 private static final long serialVersionUID
= 1L;
38 private final static Log log
= LogFactory
.getLog(WebDavServlet
.class);
40 private final Repository repository
;
41 private final Resource resourceConfiguration
;
43 public WebDavServlet(Repository repository
, Resource configuration
) {
44 this.repository
= repository
;
45 this.resourceConfiguration
= configuration
;
49 public void init() throws ServletException
{
52 if (resourceConfiguration
!= null) {
53 ResourceConfig resourceConfig
= new ResourceConfig(null);
55 resourceConfig
.parse(resourceConfiguration
.getURL());
56 } catch (IOException e
) {
57 throw new ArgeoException("Cannot parse resource configuration "
58 + resourceConfiguration
, e
);
60 setResourceConfig(resourceConfig
);
65 protected void service(HttpServletRequest request
,
66 HttpServletResponse response
) throws ServletException
, IOException
{
67 if (log
.isTraceEnabled())
68 log
.trace("Received request " + request
);
69 super.service(request
, response
);
71 if (log
.isTraceEnabled()) {
72 log
.trace("Webdav response: " + response
);
77 public Repository
getRepository() {
82 public SessionProvider
getSessionProvider() {
83 return new CachingSessionProvider(new SimpleCredentials("demo",
84 "demo".toCharArray()));