PDA

View Full Version : How to get jackrabbit work in tomcat with spring


doraetus
Apr 5th, 2006, 05:25 AM
I tried to set up the jackrabbit in tomcat 5.0.28, but i get "[Fatal
Error] :1:1: Content is not allowed in prolog." error when i tried to lookup a
repository. Below are my setting.


in server.xml of tomcat:

<Context path="/rabbittest" docBase="rabbittest" debug="0" reloadable="true"
crossContext="true">
<Resource name="jcr/repository" auth="Container"
type="javax.jcr.Repository"/>

<ResourceParams name="jcr/repository">
<parameter>
<name>factory</name>
<value>org.apache.jackrabbit.core.jndi.BindableRepository Factory</value
>
</parameter>
<parameter>
<name>configFilePath</name>
<value>F:/Java/jakarta-tomcat-
5.0.28/webapps/rabbittest/docMan</value>
</parameter>
<parameter>
<name>repHomeDir</name>
<value>F:/Java/jakarta-tomcat-
5.0.28/webapps/rabbittest/docMan/rep</value>
</parameter>
</ResourceParams>
</Context>


in 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>

in my applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- JNDI Document Repository for J2EE environments -->
<bean id="docRepository"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jcr/repository</value>
</property>
</bean>
</beans>

Please Help and Advice. Thank you.

Costin Leau
Apr 5th, 2006, 05:54 AM
there is a nice setup of jackrabbit with Tomcat on jackrabbit website: jackrabbit.apache.org. I suggest you try that one to make sure that jackrabbit is started and binded to JNDI.
Retrieving the object from there is pretty straight forward with the JNDI template (like you did).

doraetus
Apr 5th, 2006, 06:10 AM
That the problem.. I followed exactly the steps in jackrabbit website for the web-app setup, but i still get the same error when i retrieve the repository in a servlet.

So i wonder anyone can successfully set up jackrabbit repository in tomcat.

my servlet:
//j2se
import java.io.*;
import java.util.*;

//j2ee
import javax.naming.*;
import javax.servlet.*
import javax.jcr.*;

public class RabbitServlet extends HttpServlet {


public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

System.out.println ("in rabbit servlet");
PrintWriter out = res.getWriter();
try {
out.println ("testing rabbit");
System.out.println ("b4 getting repository");
InitialContext context = new InitialContext();
Context environment = (Context) context.lookup("java:comp/env");
Repository repository = (Repository) environment.lookup("jcr/repository");
System.out.println ("after getting repository");
out.flush();

}
catch (Exception e) {
throw new ServletException ("Unable to output file.");
}
finally {
try {
out.close ();
}
catch (Exception e) {
}
}
}

public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
doPost (req, res);
}
}

Costin Leau
Apr 5th, 2006, 06:18 AM
I haven't worked with Jackrabbit inside Tomcat's JNDI so I can't really help. Try the jackrabbit mailing list and search their posts - they should be able to provide some assistance.

doraetus
Apr 5th, 2006, 06:23 AM
Thanks, i had tried that, but still not able to find a solution. :confused:

Costin Leau
May 12th, 2006, 04:01 PM
By the error message it seems that you XML is invalid - you have forbitdden characters in the XML header (the <xml..> DTD part).

doraetus
May 15th, 2006, 09:53 PM
already found the error..

actually is one of the setting in server.xml file.
i should set the full path including the file name instead of just the full path name for configFilePath parameter. :)

<parameter>
<name>configFilePath</name>
<value>F:/Java/jakarta-tomcat-5.0.28/webapps/rabbittest/docMan/repository.xml</value>
</parameter>