1. Get DNA and all dependencies into your Tomcat classpath
- I hacked this by adding an assembly into dna-jcr-tck that built a jar-with-dependencies, but then i had to hack out the javax/servlet folder in the JAR or Tomcar wouldn't load the JAR
2. Create a resource reference in Tomcat
- I edited conf/context.xml to add this stanza:
- Theoretically, I could have put a similar stanza in server.xml and just added a ResourceLink to it in context.xml
3. Create a test web application with a resource reference in its web.xml
- I used this in web.xml
Repository
jcr/local
javax.jcr.Repository
- Note that the value of resource-env-ref-name matches the value of the name attribute on the tag in the prior step. This is a must.
4. Write your web page.
- My web page follows below. Note the hackish use of IDTrust to create the JAAS realm. To make this work, I had to move the security folder (containing jaas.conf.xml, tck_users.properties, and tck_roles.properties) into my %CATALINA_HOME% directory. I tried moving the security folder into the conf directory, but it was not visible to the JSP page in that location.
<%@ page import="
javax.naming.*,
javax.jcr.*,
org.jboss.security.config.IDTrustConfiguration
" %>
<%!
static {
// Initialize IDTrust
String configFile = "security/jaas.conf.xml";
IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
try {
idtrustConfig.config(configFile);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
%>
<%
Session sess = null;
try {
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Repository repo = (Repository) envCtx.lookup("jcr/local");
sess = repo.login(new SimpleCredentials("readwrite", "readwrite".toCharArray()));
out.println(sess.getRootNode().getPrimaryNodeType().getName());
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
if (sess != null) sess.logout();
}
%>