jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Bergöö <jacob.ber...@gmail.com>
Subject Re: Connecting to different repositories
Date Tue, 28 Apr 2009 13:46:14 GMT

Hi again,
Now, I am building my own factory that, depending on a property, are
connection to either a local repository or a remote repository. The Problem
now is that I get
"org.springframework.transaction.CannotCreateTransactionException: Could not
open JCR session for transaction;" 

My configuration looks like this:


    <bean id="jcrPropertyPlaceholder"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location"
value="classpath:jcr-persistence-config.properties"/>
    </bean>

    <bean id="devRepository"
class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
        <property name="configuration"
value="${jcr.repository.config.file}"/>
        <property name="homeDir" value="${jcr.repository.home.dir}"/>
    </bean>
	

    <bean id="repository"
class="com.xxxx.persistence.repository.RepositoryResolver">
        <property name="repositoryUrl" value="${rmi.path}"/>
        <property name="buildForDevelopment"
value="${build.For.Development}"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <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="username"/>
                <constructor-arg index="1">
                    <bean factory-bean="password"
factory-method="toCharArray"/>
                </constructor-arg>
            </bean>
        </property>
    </bean>

   <bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
        <property name="sessionFactory" ref="jcrSessionFactory"/>
        <property name="allowCreate" value="true"/>
    </bean>

    <bean id="password" class="java.lang.String">
        <constructor-arg index="0" value="password"/>
    </bean>

    <bean id="transactionManager"
class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
        <property name="sessionFactory" ref="jcrSessionFactory"/>
    </bean>

    <!-- rmi server -->
    <!-- use Spring's RMI classes to retrieve the RMI registry -->
    <bean id="rmiRegistry"
class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"/>
    <bean id="rmiServer"
class="org.springmodules.jcr.jackrabbit.RmiServerRepositoryFactoryBean">
        <property name="repository" ref="repository"/>
        <property name="remoteAdapterFactory">
            <bean
class="org.apache.jackrabbit.rmi.server.ServerAdapterFactory"/>
        </property>
        <property name="registry" ref="rmiRegistry"/>
        <property name="rmiName" value="jackrabbit"/>
    </bean>



The Java class:

import javax.jcr.Repository;

import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

public class RepositoryResolver implements FactoryBean {
	
	private static final Logger logger =
LoggerFactory.getLogger(RepositoryResolver.class);
	
	@Autowired
	private Repository devRepository;

	private String repositoryUrl;
	private boolean buildForDevelopment;
	
	private Repository currentRepository;
	
	public RepositoryResolver() {
		super();
	}

	public void setRepositoryUrl(String repositoryUrl) {
		this.repositoryUrl = repositoryUrl;
	}

	public void setBuildForDevelopment(boolean buildForDevelopment) {
		this.buildForDevelopment = buildForDevelopment;
	} 
	
	public Repository createRepository(){
		return null;
	}

	@Override
	public Object getObject() throws Exception {
		if (currentRepository == null) {
			if (buildForDevelopment) {
				currentRepository = devRepository;
			} else {
				ClientRepositoryFactory factory = new ClientRepositoryFactory();
				try {
					currentRepository = factory.getRepository(repositoryUrl);
					logger.info("Connecting to repository = " +
currentRepository.getDescriptor(currentRepository.REP_NAME_DESC));
					//currentRepository = new
org.apache.jackrabbit.rmi.repository.RMIRemoteRepository(repositoryUrl);
				} catch (Exception e) {
					e.printStackTrace();
				} 
			}
		}
		return currentRepository;
	}

	@Override
	public Class getObjectType() {
		if (currentRepository != null) {
			return currentRepository.getClass();
		} else {
			return null;
		}
	}

	@Override
	public boolean isSingleton() {
		return true;
	}
	
}

And finally the property file:

# PROJECT TYPE (DEV or TEST/PRODUCTION
build.For.Development=false

# DEV REPOSITORY SETUP 
jcr.repository.config.file=classpath:jcr-repository-config.xml
jcr.repository.home.dir=file:./target/trex_jcr_repo

# RMI CONNECTION STRING
rmi.path=rmi://[some.ip.number]:[some.port.number]/jackrabbit.repository

the Exception I get is this:

 
WARN  DefaultRemoter - Method execution failed:
org.springframework.transaction.CannotCreateTransactionException: Could not
open JCR session for transaction; nested exc
eption is java.lang.IllegalArgumentException: transactions are not supported
by your Jcr Repository
        at
org.springmodules.jcr.jackrabbit.LocalTransactionManager.doBegin(LocalTransactionManager.java:163)
        at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTra
nsactionManager.java:374)
        at
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(Transaction
AspectSupport.java:263)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy14.getTemplateTree(Unknown Source)
        at
com.teliasonera.ct.t2.service.impl.T2ServiceImpl.getTemplateTree(T2ServiceImpl.java:55)
        at
com.teliasonera.ct.t2.trex.TrexService.getTemplateTree(TrexService.java:58)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
        at
org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
        at
org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
        at
org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
        at
org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
        at
org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
        at
org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
        at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
        at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
        at
org.mortbay.jetty.security.ConstraintsSecurityHandler.handle(ConstraintsSecurityHandler.java:220)
        at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:822)
        at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:305)
        at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:229)
        at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:113)
        at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:550)
        at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:890)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:743)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:215)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:407)
        at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:421)
        at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: java.lang.IllegalArgumentException: transactions are not
supported by your Jcr Repository
        at
org.springmodules.jcr.jackrabbit.LocalTransactionManager.doBegin(LocalTransactionManager.java:120)
        ... 38 more


Is there no support for transactions over RMI? And in that case, can I use
JNDI or something else? does anyone know how to solve this?

Thanks in advance
Jacob




Alexander Klimetschek wrote:
> 
> On Fri, Apr 24, 2009 at 4:01 PM, Jacob Bergöö <jacob.bergoo@gmail.com>
> wrote:
>>
>> Thanks for the quick reply,
>> have you heard that this has been done before or does everybody else only
>> work with one repository? How do you switch between different states in
>> your
>> development process (dev, test, prod)?
> 
> I've done it some time ago with Spring as well, but not for different
> stages, but for switching the backend depending on the requesting user
> account of the webapplication. It's not that hard to write custom
> factories in spring and wiring them together. But nowadays I am no
> longer working with Spring ;-)
> 
>> do you have any more code examples on how to do the rmi connection?
> 
> See the page for the jcr-rmi component:
> http://jackrabbit.apache.org/jackrabbit-jcr-rmi.html
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Connecting-to-different-repositories-tp23216439p23277490.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message