Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
jcr + jackrabbit + Model 3 Implementation + Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jcr + jackrabbit + Model 3 Implementation + Spring MVC

    This is a newbie question. I have been looking into Jackrabbit for a couple of weeks for a new project.

    I am trying to implement a web app using Jackrabbit and Spring MVC.
    I am accessing a Jackrabbit Server deployed in the method 3 architecture using the jcr-rmi interface.

    I am using the jcr spring bean configuration specified on another thread:

    Code:
    <bean id="jcrSessionFactory"
    	class="org.springmodules.jcr.JcrSessionFactory">
    	<property name="repository" ref="repository" />
    	<property name="credentials">
    		<bean class="javax.jcr.SimpleCredentials">
    			<constructor-arg index="0" value="bogus" />
    			<constructor-arg index="1" value="null" />
    		</bean>
    	</property>
    </bean>
    
    <bean id="jcrTransactionManager"
    	class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
    	<property name="sessionFactory" ref="jcrSessionFactory" />
    </bean>
    
    <!-- transaction proxy for Jcr services/facades -->
    <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    	<property name="proxyTargetClass" value="true" />
    	<property name="transactionManager" ref="jcrTransactionManager" />
    	<property name="transactionAttributes">
    		<props>
    			<prop key="save*">PROPAGATION_REQUIRED</prop>
    			<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
    		</props>
    	</property>
    </bean>
    
    <bean id="jcrSessionFactoryProxy" parent="txProxyTemplate" >
    	<property name="target">
    		<ref bean="jcrSessionFactory"/>
    	</property>
    </bean>
    I couldn't find a repository factory that accepted a rmi url, so I created my own.
    This extends the org.apache.jackrabbit.rmi.client.ClientRepositoryF actory.
    The bean config and source code is:
    Code:
    <bean id="repository"
    	class="com.jackrabbit.spring.RemoteClientRepositoryFactory">
    	<property name="rmiURI"
    		value="//192.168.1.5:1099/jackrabbit.repository" />
    </bean>
    
    package com.jackrabbit.spring;
    
    import javax.jcr.Repository;
    import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;
    
    public class RemoteClientRepositoryFactory extends org.springmodules.jcr.RepositoryFactoryBean{
    	
    	private String rmiURI;
    	private ClientRepositoryFactory factory = new ClientRepositoryFactory();
    
    	static {
    		try {
    			System.setProperty("java.rmi.server.useCodebaseOnly", "true");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	protected Repository createRepository() throws Exception {
            Repository repository = factory.getRepository(rmiURI);
    		return repository;
    	}
    	
    	public void setRmiURI(String rmiURI) {
    		this.rmiURI = rmiURI;
    	}
    
    	protected void resolveConfigurationResource() throws Exception {
    	}
    }
    I am storing i18n label content in the jackrabbit repository (as well as other stuff) and created a
    org.springframework.context.MessageSource that is backed by a the jackrabbit repository (with an in-memory cache).

    When I startup the tomcat instance I get the error 'No session bound to thread, and configuration does not allow creation of non-transactional one here'.
    I am not sure if this error is related to the rmi repository or that I am attempting to access the repository in a MessageSource that is defined in the SpringMVC servlet.xml configuration.

    The stack trace is
    Code:
    java.lang.IllegalStateException: No session bound to thread, and configuration does not allow creation of non-transactional one here
    	org.springmodules.jcr.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:74)
    	org.springmodules.jcr.SessionFactoryUtils.getSession(SessionFactoryUtils.java:119)
    	org.springmodules.jcr.support.JcrDaoSupport.getSession(JcrDaoSupport.java:104)
    	org.springmodules.jcr.support.JcrDaoSupport.getSession(JcrDaoSupport.java:89)
    	com.ubs.jackrabbit.DefaultRepositoryDAO.getAllLabels(DefaultRepositoryDAO.java:73)
    	com.ubs.jackrabbit.JackrabbitMessageSource.initLabels(JackrabbitMessageSource.java:74)
    	com.ubs.jackrabbit.JackrabbitMessageSource.getMessage(JackrabbitMessageSource.java:46)
    	org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:697)
    	org.springframework.context.support.MessageSourceResourceBundle.handleGetObject(MessageSourceResourceBundle.java:62)
    	java.util.ResourceBundle.getObject(ResourceBundle.java:320)
    	java.util.ResourceBundle.getString(ResourceBundle.java:286)
    	org.apache.taglibs.standard.tag.common.fmt.MessageSupport.doEndTag(MessageSupport.java:171)
    	org.apache.jsp.WEB_002dINF.jsp.structure.main_jsp._jspx_meth_fmt_message_0(main_jsp.java:139)
    	org.apache.jsp.WEB_002dINF.jsp.structure.main_jsp._jspService(main_jsp.java:62)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1051)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:727)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    I am a bit stuck at this point?

    Is this a valid way to use the rmi reposiotory? Can someone suggest a solution? It is not a requirement to be transactional, the website will be quite static.

  • #2
    You are trying to use a thread-bound session which does not exist.
    If you are using transactions, then the TM will bind the JCR session - if you are not (which I assume is your case), then you can use OpenSessionInViewFilter/Interceptor or JcrInterceptor which can bind the session to the thread for the execution of the current call stack.
    Note that the JCR package is very similar to the one for Hibernate/Toplink/JDO.

    P.S. I've created a JIRA issue to integrate the Jackrabbit RMI client into the Spring Modules codebase.

    Comment


    • #3
      FYI, MOD-191 is fixed and will be part of the upcoming Spring Modules 0.6 release. The docs has also been updated - you can use the example there to configure Jackrabbit's RMI server/client without the need of any custom classes (spring can deal with them just fine though I've added a class in Spring Modules to ease the server setup procedure).

      Comment


      • #4
        I too get IllegalStateException initializing service...

        I am trying to use jcr-spring module for my tiny service. I get the same exception. I am using the spring modules 0.6 with spring 2.0 and jackrabbit 1.1.

        I seem to be following all the instructions from Costin. I cannot get proceed further. My service configuration is below:



        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
        efault-lazy-init="true">
        <import resource="applicationContext-jackrabbit.xml" />

        <bean id="jcrSessionFactory"
        class="org.apache.portals.graffito.jcr.spring.Jack rabbitSessionFactory">
        <property name="repository" ref="repository" />
        <property name="credentials">
        <bean class="javax.jcr.SimpleCredentials">
        <constructor-arg index="0" value="superuser" />
        <!-- create the credentials using a bean factory -->
        <constructor-arg index="1">
        <bean factory-bean="password"
        factory-method="toCharArray" />
        </constructor-arg>
        </bean>
        </property>

        <!-- register namespaces -->
        <property name="namespaces">
        <props>
        <prop key="graffito">
        http://incubator.apache.org/graffito
        </prop>
        </props>
        </property>
        <property name="eventListeners">
        <list>
        <bean
        class="org.springmodules.jcr.EventListenerDefiniti on">
        <property name="listener">
        <bean
        class="org.springmodules.examples.jcr.DummyEventLi stener" />
        </property>
        </bean>
        </list>
        </property>
        </bean>

        <!-- create the password to return it as a char[] -->
        <bean id="password" class="java.lang.String">
        <constructor-arg index="0" value="superuser" />
        </bean>

        <bean id="jcrMappingDescriptor"
        class="org.apache.portals.graffito.jcr.mapper.impl .DigesterMapperImpl">
        <constructor-arg index="0"
        value="e:/jcr/catalog/jcrmapping.xml" />
        </bean>

        <bean id="jcrMappingTemplate"
        class="org.apache.portals.graffito.jcr.spring.JcrM appingTemplate">
        <constructor-arg index="0" ref="jcrSessionFactory" />
        <constructor-arg index="1" ref="jcrMappingDescriptor" />
        <property name="allowCreate" value="false" />
        </bean>

        <bean id="baseTransactionProxy"
        class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
        abstract="true">
        <property name="transactionManager">
        <ref bean="jcrTransactionManager" />
        </property>
        <property name="transactionAttributes">
        <props>
        <prop key="*">PROPAGATION_REQUIRED</prop>
        </props>
        </property>
        </bean>

        <!-- User Service -->
        <!-- User DAO object: Jcr implementation -->
        <bean id="userDao" class="catalog.model.dao.impl.jcr.UserDaoImpl">
        <property name="jcrMappingTemplate">
        <ref bean="jcrMappingTemplate" />
        </property>
        </bean>

        <!-- User Service Defintion -->
        <bean id="userServiceImpl"
        class="catalog.model.service.impl.jcr.UserServiceI mpl"
        init-method="init">
        <property name="userDao">
        <ref local="userDao" />
        </property>
        <property name="smtpHost">
        <value>SMTP_HOST_ADDRESS</value>
        </property>
        <property name="defaultSenderAddress">
        <value>DEFAULT_SENDER_ADDRESS</value>
        </property>
        <property name="defaultSenderName">
        <value>DEFAULT_SENDER_NAME</value>
        </property>
        <property name="receiverAddresses">
        <list>
        <value>RECEIVER_ADDRESS1</value>
        <value>RECEIVER_ADDRESS2</value>
        </list>
        </property>
        </bean>

        <!-- Transactional proxy for the User Service -->
        <bean id="userService"
        class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
        parent="baseTransactionProxy">
        <property name="proxyInterfaces">
        <value>catalog.model.service.UserService</value>
        </property>
        <property name="target">
        <ref local="userServiceImpl" />
        </property>
        <property name="transactionAttributes">
        <props>
        <prop key="*">PROPAGATION_REQUIRED</prop>
        </props>
        </property>
        </bean>
        </beans>


        Any help about this would be appreciated.

        Thanks -Ram

        Comment

        Working...
        X