| 1 |
<%-- |
| 2 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
contributor license agreements. See the NOTICE file distributed with |
| 4 |
this work for additional information regarding copyright ownership. |
| 5 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
(the "License"); you may not use this file except in compliance with |
| 7 |
the License. You may obtain a copy of the License at |
| 8 |
|
| 9 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
Unless required by applicable law or agreed to in writing, software |
| 12 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
See the License for the specific language governing permissions and |
| 15 |
limitations under the License. |
| 16 |
--%><%@page import="org.apache.jackrabbit.util.Text"%><% |
| 17 |
request.setAttribute("title", "Local Repository Access"); |
| 18 |
%><jsp:include page="header.jsp"/> |
| 19 |
<p> |
| 20 |
The content repository within this web application can be accessed |
| 21 |
locally by other web applications within the same servlet container. |
| 22 |
Local access is much faster than <a href="remote.jsp">remote access</a>. |
| 23 |
</p> |
| 24 |
<p> |
| 25 |
The content repository is made available both through JNDI and the |
| 26 |
web application context. |
| 27 |
</p> |
| 28 |
|
| 29 |
<h3>Accessing the repository through JNDI</h3> |
| 30 |
<p> |
| 31 |
By default the repository is only made available in a dummy JNDI directory |
| 32 |
local to this web application. However, you can make the repository globally |
| 33 |
available if your servlet container allows a web application to modify the |
| 34 |
global JNDI directory or you are using some other JNDI directory that can |
| 35 |
manage unserializable Java objects. |
| 36 |
</p> |
| 37 |
<p> |
| 38 |
To bind the the repository to such a JNDI directory, you need to modify |
| 39 |
the <code>java.naming</code> parameters in either the /WEB-INF/web.xml |
| 40 |
deployment descriptor or the jackrabbit/bootstrap.properties file. You need |
| 41 |
to redeploy this web application to activate the changes. |
| 42 |
</p> |
| 43 |
<p> |
| 44 |
Use the following code to access a repository bound in a JNDI directory: |
| 45 |
</p> |
| 46 |
<pre> |
| 47 |
<b>import</b> javax.jcr.Repository; |
| 48 |
<b>import</b> javax.naming.Context; |
| 49 |
<b>import</b> javax.naming.InitialContext; |
| 50 |
|
| 51 |
Context context = <b>new</b> InitialContext(...); |
| 52 |
Repository repository = (Repository) context.lookup(...); |
| 53 |
</pre> |
| 54 |
|
| 55 |
<h3>Accessing the repository through servlet context</h3> |
| 56 |
<p> |
| 57 |
This web application makes the repository available as the |
| 58 |
<code>javax.jcr.Repository</code> attribute in the application context. |
| 59 |
If your servlet container supports cross-context access, you can |
| 60 |
access the repository directly using that attribute. |
| 61 |
</p> |
| 62 |
<p> |
| 63 |
For example in <a href="http://tomcat.apache.org/">Apache Tomcat</a> |
| 64 |
you can enable cross-context access by setting the <code>crossContext</code> |
| 65 |
attribute to true in the <Context/> configuration. |
| 66 |
</p> |
| 67 |
<p> |
| 68 |
Use the following code to access a repository through the servlet context: |
| 69 |
</p> |
| 70 |
<pre> |
| 71 |
<b>import</b> javax.jcr.Repository; |
| 72 |
<b>import</b> javax.servlet.ServletContext; |
| 73 |
|
| 74 |
ServletContext context = ...; // <em>context of your servlet</em> |
| 75 |
ServletContext jackrabbit = |
| 76 |
context.getContext("<em><%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %></em>"); |
| 77 |
Repository repository = (Repository) |
| 78 |
context.getAttribute(Repository.<b>class</b>.getName()). |
| 79 |
</pre> |
| 80 |
|
| 81 |
<h3>Using the jackrabbit-jcr-servlet component</h3> |
| 82 |
<p> |
| 83 |
The <em>jackrabbit-jcr-servlet</em> component contains utility classes |
| 84 |
for use within JCR web applications. With that component you can hide |
| 85 |
both the above and the <a href="remote.jsp">remote access</a> options |
| 86 |
from your code, and use just the following to access a repository: |
| 87 |
</p> |
| 88 |
<pre> |
| 89 |
<b>import</b> javax.jcr.Repository; |
| 90 |
<b>import</b> org.apache.jackrabbit.servlet.ServletRepository; |
| 91 |
|
| 92 |
<b>public class</b> MyServlet <b>extends</b> HttpServlet { |
| 93 |
|
| 94 |
<b>private final</b> Repository repository = <b>new</b> ServletRepository(<b>this</b>); |
| 95 |
|
| 96 |
// ... |
| 97 |
|
| 98 |
} |
| 99 |
</pre> |
| 100 |
<p> |
| 101 |
See the jackrabbit-jcr-servlet documentation for more details. |
| 102 |
</p> |
| 103 |
<jsp:include page="footer.jsp"/> |