tags:

views:

490

answers:

0

I want to configure connections to a JCR repository at the application server level JBoss and retrieve those settings from within my web application using JNDI. I managed to configure the JCR repository using a typical data source.

Can somebody tell me how to configure the username and password settings? Or point me to some samples? I managed to get this working in Jetty which I am using for integration testing but my its got to work in JBoss in production.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="test" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
            http://java.sun.com/xml/ns/j2ee
            http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>com.btmatthews.freelancer.webapp.servlet.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
    <resource-ref>
        <res-ref-name>jcr/imageserver/repository</res-ref-name>
        <res-type>javax.jcr.Repository</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jcr/imageserver/username</res-ref-name>
        <res-type>java.lang.String</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jcr/imageserver/password</res-ref-name>
        <res-type>java.lang.String</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>freelancer</context-root>
    <resource-ref>
        <res-ref-name>jcr/imageserver/repository</res-ref-name>
        <res-type>javax.jcr.Repository</res-type>
        <jndi-name>java:jcr/imageserver/repository</jndi-name>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jcr/imageserver/username</res-ref-name>
        <res-type>java.lang.String</res-type>
        <jndi-name>java:jcr/imageserver/username</jndi-name>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jcr/imageserver/password</res-ref-name>
        <res-type>java.lang.String</res-type>
        <jndi-name>java:jcr/imageserver/password</jndi-name>
     </resource-ref>
</jboss-web>