I started the standalone.jar on port 8081 with the following and now
I am trying to access it from a servlet.  Yet, I get an Exception
where it can't `getSession` in my SessionFactory class. I am not sure
what is going on. The one thing I checked is the looked so that it is
"jcr/repository". I also checked that the ClientRepositoryFactory class
is in my dependencies. Could it be the way I am creating the context.xml?

See below for details.

Thanks,

Brian

The following is the exception shown on the jsp page.

```
org.apache.jasper.JasperException: An exception occurred processing 
[/listing.jsp] at line [33]

30: }
31: %>
32: <%
33: Session jcrSession = SessionFactory.getSession();
34: Node root = jcrSession.getRootNode();
35: %>
36: <pre>

javax.naming.NamingException: Unexpected exception resolving reference
        org.apache.naming.NamingContext.lookup(NamingContext.java:884)
        org.apache.naming.NamingContext.lookup(NamingContext.java:158)
        org.apache.naming.NamingContext.lookup(NamingContext.java:850)
        org.apache.naming.NamingContext.lookup(NamingContext.java:172)
        gov.ca.brea.jcrweb05.SessionFactory.getSession(SessionFactory.java:33)
```

web.xml
```
<resource-env-ref>
    <description>Content Repository</description>
    <resource-env-ref-name>jcr/repository</resource-env-ref-name>
    <resource-env-ref-type>javax.jcr.Repository</resource-env-ref-type>
</resource-env-ref>
```

META-INF/context.xml
```
<Context path="/jcrweb05/" >
<Resource name="jcr/repository" auth="Container"
    type="javax.jcr.Repository"
    factory="org.apache.jackrabbit.rmi.client.ClientRepositoryFactory"
    url="http://localhost:8081/rmi"/>

</Context>
```

SessionFactory.java
```
public class SessionFactory {

    public static Session getSession() throws RepositoryException, 
NamingException {
        //org.apache.jackrabbit.rmi.client.ClientRepositoryFactory a;
        InitialContext ctx = new InitialContext();
        Context env = (Context) ctx.lookup("java:comp/env");

        Repository repository = (Repository) env.lookup("jcr/repository");

        Session session = repository.login(
                new SimpleCredentials("admin", "admin".toCharArray()));
        return session;
    }
}
```

JSP that accesses the session
```
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.jcr.Node"%>
<%@page import="javax.jcr.Session"%>
<%@page import="gov.ca.brea.jcrweb05.SessionFactory"%>
<%@page import="javax.jcr.NodeIterator"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JackRabbit Repository</title>
    </head>
    <body>
        <h1>This is what is in the JackRabbit Repository Two</h1>

<%
// Fails HERE
Session jcrSession = SessionFactory.getSession();
Node root = jcrSession.getRootNode();
%>

    </body>
</html>
```

My dependencies in pom.xml. I think I have a lot of extra dependencies
here.
```
   <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
                <!-- The JCR API --> 
        <dependency> 
            <groupId>javax.jcr</groupId> 
            <artifactId>jcr</artifactId> 
            <version>2.0</version> 
        </dependency>
        
        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-core -->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-core</artifactId>
            <version>2.20.3</version>
        </dependency>
        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-jcr-rmi -->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-jcr-rmi</artifactId>
            <version>2.19.6</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.26</version>
        </dependency>
        
        <!-- Use Log4J for logging --> 
        <dependency> 
            <groupId>org.slf4j</groupId> 
            <artifactId>slf4j-log4j12</artifactId> 
            <version>1.7.26</version> 
        </dependency> 
        
        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-jcr-server 
-->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-jcr-server</artifactId>
            <version>2.19.6</version>
        </dependency>
        
        <!-- 
https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>

        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-spi-commons 
-->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-spi-commons</artifactId>
            <version>2.19.6</version>
        </dependency>
        
        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-jcr-commons 
-->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-jcr-commons</artifactId>
            <version>2.19.6</version>
        </dependency>

        <!-- 
https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-webdav -->
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-webdav</artifactId>
            <version>2.19.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.22</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.12.1</version>
        </dependency>

    </dependencies> 
```
-- 
Brian Lavender
http://www.brie.com/brian/

"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."

Professor C. A. R. Hoare
The 1980 Turing award lecture

Reply via email to