当前位置: 代码迷 >> Web前端 >> WebDAV(二)Check the Sample Code jackrabbit-webapp
  详细解决方案

WebDAV(二)Check the Sample Code jackrabbit-webapp

热度:1281   发布时间:2012-07-20 10:38:30.0
WebDAV(2)Check the Sample Code jackrabbit-webapp
WebDAV(2)Check the Sample Code jackrabbit-webapp

Check out the source code from SVN
>svn checkout http://svn.apache.org/repos/asf/jackrabbit/trunk jackrabbit

Build the source code
>cd jackrabbit
>mvn clean install

Take this project as example, jackrabbit/jackrabbit-webapp. I just make it working ASAP, and them check the configuration.
Here is the web.xml file content.
<listener>
<!-- Releases all Derby resources when the webapp is undeployed. -->
<listener-class>
org.apache.jackrabbit.j2ee.DerbyShutdown
</listener-class>
</listener>

<!-- ====================================================================== -->
    <!-- R E P O S I T O R Y   S T A R T U P  S E R V L E T                     -->
    <!-- ====================================================================== -->
    <servlet>
        <servlet-name>RepositoryStartup</servlet-name>
        <description>
            Repository servlet that starts the repository and registers it to JNDI ans RMI.
            If you already have the repository registered in this appservers JNDI context,
            or if its accessible via RMI, you do not need to use this servlet.
        </description>
        <servlet-class>org.apache.jackrabbit.j2ee.RepositoryStartupServlet</servlet-class>

        <init-param>
            <param-name>bootstrap-config</param-name>
            <param-value>/bootstrap.properties</param-value>
            <description>
                Property file that hold the same initialization properties than
                the init-params below. If a parameter is specified in both
                places the one in the bootstrap-config wins.
            </description>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

<!-- ====================================================================== -->
<!-- R E P O S I T O R Y S E R V L E T -->
<!-- ====================================================================== -->
<servlet>
<servlet-name>Repository</servlet-name>
<description>
This servlet provides other servlets and jsps a common way to access
the repository. The repository can be accessed via JNDI, RMI or Webdav.
</description>
<servlet-class>org.apache.jackrabbit.j2ee.RepositoryAccessServlet</servlet-class>

<init-param>
<param-name>bootstrap-config</param-name>
<param-value>/bootstrap.properties</param-value>
<description>
Property file that hold the same initialization properties than
the init-params below. If a parameter is specified in both
places the one in the bootstrap-config wins.
</description>
</init-param>
<init-param>
          <param-name>repository.context.attribute.name</param-name>
          <param-value>sillycat.Repository</param-value>
          <description>
            If this is set, the RepositoryAccessServlet expects a Repository in the ServletContext
            attribute having this name. This allows servlets of this module to be used with repositories
            initialized by the jackrabbit-jcr-servlet module utilities.
          </description>
        </init-param>
<load-on-startup>3</load-on-startup>
</servlet>

<!-- ====================================================================== -->
<!-- J C R R E M O T I N G S E R V L E T -->
<!-- ====================================================================== -->
<servlet>
<servlet-name>JCRWebdavServer</servlet-name>
<description>
The servlet used to remote JCR calls over HTTP.
</description>
<servlet-class>org.apache.jackrabbit.j2ee.JcrRemotingServlet</servlet-class>
<init-param>
<param-name>missing-auth-mapping</param-name>
<param-value></param-value>
<description>
Defines how a missing authorization header should be handled.
1) If this init-param is missing, a 401 response is generated.
This is suitable for clients (eg. webdav clients) for which
sending a proper authorization header is not possible if the
server never sent a 401.
2) If this init-param is present with an empty value,
null-credentials are returned, thus forcing an null login
on the repository.
3) If this init-param is present with the value 'guestcredentials'
java.jcr.GuestCredentials are used to login to the repository.
4) If this init-param has a 'user:password' value, the respective
simple credentials are generated.
</description>
</init-param>
<init-param>
<param-name>resource-path-prefix</param-name>
<param-value>/sillycat</param-value>
<description>
defines the prefix for spooling resources out of the repository.
</description>
</init-param>
<!-- Init parameters specific for JcrRemotingServlet -->
<!-- <init-param> <param-name>home</param-name> <param-value></param-value>
<description>JcrRemotingServlet: Optional home directory for JcrRemotingServlet
temporary files (default: "jackrabbit")</description> </init-param> <init-param>
<param-name>temp-directory</param-name> <param-value></param-value> <description>JcrRemotingServlet:
Optional temporary directory name (under home, default: "tmp")</description>
</init-param> -->
<init-param>
<param-name>batchread-config</param-name>
<param-value>/WEB-INF/batchread.properties</param-value>
<description>JcrRemotingServlet: Optional mapping from node type
names to default depth.</description>
</init-param>
<!-- init-param> <param-name>concurrency-level</param-name> <param-value>50</param-value>
<description>Number of concurrent requests expected. Default value is 50.</description>
</init-param -->
<load-on-startup>5</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>JCRWebdavServer</servlet-name>
<url-pattern>/sillycat/*</url-pattern>
</servlet-mapping>

Not only the classes, but also the properties file bootstrap.properties
repository.home=d://work/easy/easywebdavserver/sillycat
repository.config=d://work/easy/easywebdavserver/sillycat/repository.xml
repository.name=sillycat.repository

Copy the logback.xml to resources directory.

I change the method getConfig() in RepositoryAccessServlet.java, make it read the properties file from classpath
InputStream in = getServletContext().getResourceAsStream(bstrp);
                // check if it's a class path properties
                if(in == null){
                in = this.getClass().getResourceAsStream(bstrp);
                }

Make the same changes to RepositoryStartupServlet.java
private boolean configure() throws ServletException {
// check if there is a loadable bootstrap config
Properties bootstrapProps = new Properties();
String bstrp = getServletConfig().getInitParameter(
INIT_PARAM_BOOTSTRAP_CONFIG);
if (bstrp != null) {
// check if it's a web-resource
InputStream in = getServletContext().getResourceAsStream(bstrp);
// check if it's a class path properties
            if(in == null){
            in = this.getClass().getResourceAsStream(bstrp);
            }
...snip...

And I do not think I need RMI/JNDI support, so I create repository in RepositoryStartupServlet.java and put the repository itself in Servlet Context, from RepostoryAccessServlet, I read it from the servlet context.
public void startup() throws ServletException {
if (repository != null) {
log.error("Startup: Repository already running.");
throw new ServletException("Repository already running.");
}
log.info("RepositoryStartupServlet initializing...");
try {
if (configure()) {
initRepository();
registerContext();
registerRMI();
registerJNDI();
}
log.info("RepositoryStartupServlet initialized.");
} catch (ServletException e) {
// shutdown repository
shutdownRepository();
log.error("RepositoryStartupServlet initializing failed: " + e, e);
}
}
...snip...
private void registerContext() throws ServletExceptionWithCause {
try {
getServletContext().setAttribute("sillycat.Repository", repository);
} catch (Exception e) {
throw new ServletExceptionWithCause(
"Unable to bind repository in context", e);
}
}

...

references:
http://jackrabbit.apache.org/building-jackrabbit.html
http://svn.apache.org/repos/asf/jackrabbit/trunk/
http://jackrabbit.apache.org/jackrabbit-configuration.html
http://jackrabbit.apache.org/first-hops.html
http://suigara.iteye.com/blog/1454765
http://www.ibm.com/developerworks/cn/java/j-jcr/
http://blog.csdn.net/exitzhang/article/details/5106338
http://jackrabbit.apache.org/jackrabbit-jcr-server.html
http://jackrabbit.apache.org/jackrabbit-web-application.html
http://sujitpal.blogspot.com/2007/09/spring-loaded-jackrabbit.html
http://www.infoq.com/articles/spring-modules-jcr
http://wiki.apache.org/jackrabbit/ExamplesPage
  相关解决方案