You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by viz06 <vi...@yahoo.com> on 2008/06/12 16:24:02 UTC
Namespace registration
I am using spring modules to set up jcr repository. and facing couple of
issues:
1. I am not able to register the namespace 'mypc' and have to manually
modify ns_reg.properties to set the namespace.
2. I have setup few spring enabled test cases which run to completion and
creates the correct node structure, when I run the same test second time
around all my previous nodes shows a different namespace prefix of 'fn'. I
am unable to figure out from where it is getting this namespace prefix.
Here is part of my spring config
<bean id="repository"
class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
<!-- normal factory beans params -->
<property name="configuration"
value="classpath:repository.xml" />
<property name="homeDir" value="file:c:/repo"/>
</bean>
<!-- Session Factory -->
<bean id="jcrSessionFactory"
class="org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory">
<property name="repository" ref="repository"/>
<property name="credentials">
<bean class="javax.jcr.SimpleCredentials">
<constructor-arg index="0" value="bogus"/>
<constructor-arg index="1">
<bean factory-bean="password"
factory-method="toCharArray"/>
</constructor-arg>
</bean>
</property>
<property name="namespaces">
<props>
<prop key="mypc">http://www.mypc.com/mypc</prop>
</props>
</property>
<property name="contentType" value="text/x-jcr-cnd"/>
<property name="nodeDefinitions">
<list>
<value>classpath:mypc-custom-node-types.cnd</value>
</list>
</property>
</bean>
Thanks
--
View this message in context: http://www.nabble.com/Namespace-registration-tp17801235p17801235.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
Just FYI, because I came across the sources for the spring modules:
The implementation of JackrabbitSessionFactory.registerNodetypes() (in
spring modules 0.9, see [1]) does not catch the
InvalidNodeTypeDefException that is thrown when a nodetype already
exists. It should be fixed by surrounding
nodeTypeManager.registerNodeTypes(resource.getInputStream(),
contentType); with a try-catch statement.
Someone should send a patch to the spring modules guys. In the
meantime, you can simply extend from JackrabbitSessionFactory and
overwrite the registerNodetypes() method that catches the exception.
[1] https://springmodules.dev.java.net/source/browse/springmodules/projects/jcr/src/java/org/springmodules/jcr/jackrabbit/JackrabbitSessionFactory.java?hideattic=0&rev=1.3&view=markup
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
RE: Namespace registration
Posted by Jared Graber <ja...@IACcap.com>.
I am having the same problem and from what I can tell (I could be wrong)
the jcr spring module isn't calling the correct method.
It calls the method:
registerNodeTypes(InputStream in, String contentType)
instead of
registerNodeTypes(InputStream in, String contentType, boolean
reregisterExisting)
I think if it called the 2nd method with true as the value of
reregisterExisting it would work.
-Jared
-----Original Message-----
From: Alexander Klimetschek [mailto:aklimets@day.com]
Sent: Friday, June 13, 2008 11:29 AM
To: users@jackrabbit.apache.org
Subject: Re: Namespace registration
On Fri, Jun 13, 2008 at 4:20 PM, viz06 <vi...@yahoo.com>
wrote:
> Basically test fails as spring config is unable to load
jcrSessionFactory.
Well, then it's a bug in the spring modules. You should file a bug
with that project if it is not fixed yet (don't know). The
already-exists exception is normal and expected behaviour. It's a bit
tricky since it stops import of the entire CND file if one of the
contained node types is already registered, but normally it should not
be a big issue, cause that should only be part of development.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jun 13, 2008 at 4:20 PM, viz06 <vi...@yahoo.com> wrote:
> Basically test fails as spring config is unable to load jcrSessionFactory.
Well, then it's a bug in the spring modules. You should file a bug
with that project if it is not fixed yet (don't know). The
already-exists exception is normal and expected behaviour. It's a bit
tricky since it stops import of the entire CND file if one of the
contained node types is already registered, but normally it should not
be a big issue, cause that should only be part of development.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Namespace registration
Posted by viz06 <vi...@yahoo.com>.
Alex,
Basically test fails as spring config is unable to load jcrSessionFactory.
I should have provided the complete log, here it goes
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'jcrSessionFactory' defined in class path resource
[applicationContext-jackrabbit.xml]: Invocation of init method failed;
nested exception is javax.jcr.RepositoryException: Invalid node type
definition: {http://www.mypc.com/mypc}Folder already exists:
{http://www.mypc.com/mypc}Folder already exists
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1362)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
at java.security.AccessController.doPrivileged(Native Method)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
at
org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:243)
at
org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:212)
at
org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:187)
at
org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
at
org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
at junit.framework.TestCase.runBare(TestCase.java:128)
at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.jcr.RepositoryException: Invalid node type definition:
{http://www.mypc.com/mypc}Folder already exists:
{http://www.mypc.com/mypc}Folder already exists
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:319)
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:499)
at
org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory.registerNodeTypes(JackrabbitSessionFactory.java:67)
at
org.springmodules.jcr.JcrSessionFactory.afterPropertiesSet(JcrSessionFactory.java:126)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)
... 30 more
Caused by: org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException:
{http://www.mypc.com/mypc}Folder already exists
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.internalRegister(NodeTypeRegistry.java:1281)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.internalRegister(NodeTypeRegistry.java:1251)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.registerNodeTypes(NodeTypeRegistry.java:222)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.registerNodeTypes(NodeTypeRegistry.java:207)
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:453)
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:314)
... 35 more
Thanks Again
--
View this message in context: http://www.nabble.com/Namespace-registration-tp17801235p17824551.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jun 13, 2008 at 4:04 PM, viz06 <vi...@yahoo.com> wrote:
> at
> org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:314)
Who is calling this? The Spring JCR Module should catch the
already-exists exception and not fail in this case. But it probably
only logs this exception and your system should work - does it?
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Namespace registration
Posted by viz06 <vi...@yahoo.com>.
Thanks guys for your input,
I am able to get this working, but if I run the test 2nd time around it
complains about
Caused by: org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException:
{http://www.mypc.com/mypc}Folder already exists
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.internalRegister(NodeTypeRegistry.java:1281)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.internalRegister(NodeTypeRegistry.java:1251)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.registerNodeTypes(NodeTypeRegistry.java:222)
at
org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.registerNodeTypes(NodeTypeRegistry.java:207)
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:453)
at
org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.registerNodeTypes(NodeTypeManagerImpl.java:314)
which tells me that its trying to re-register the node type again.
How can I avoid this?
Thanks
--
View this message in context: http://www.nabble.com/Namespace-registration-tp17801235p17824189.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jun 13, 2008 at 8:30 AM, Jukka Zitting <ju...@gmail.com> wrote:
>> The namespace declarations in the cnd file are not automatically registered.
>
> In fact they are, ever since Jackrabbit 1.1 (see JCR-349 [1]). As far
> as I can tell, Spring Modules has used that feature since release 0.8.
I wasn't sure about this fact so I had a look at the code, but I only
looked at CompactNodeTypeDefReader, not at NodeTypeManagerImpl, where
it actually happens for all cases of node type registration ;-)
Good to know!
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Namespace registration
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Fri, Jun 13, 2008 at 12:24 PM, viz06 <vi...@yahoo.com> wrote:
> Are you implying that I don't have to explicitly register the namespace if I
> specify it in my CND file?
Yes, the namespace should get automatically registered.
> If so I must be doing something wrong that is causing this.
What versions of Jackrabbit and Spring Modules are you using?
Namespace registration should work with Jackrabbit 1.1+ and Sling
Modules 0.8+.
BR,
Jukka Zitting
Re: Namespace registration
Posted by viz06 <vi...@yahoo.com>.
Jukka,
Are you implying that I don't have to explicitly register the namespace if I
specify it in my CND file? If so I must be doing something wrong that is
causing this.
Thanks
--
View this message in context: http://www.nabble.com/Namespace-registration-tp17801235p17819618.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Namespace registration
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Fri, Jun 13, 2008 at 1:44 AM, Alexander Klimetschek <ak...@day.com> wrote:
> The namespace declarations in the cnd file are not automatically registered.
In fact they are, ever since Jackrabbit 1.1 (see JCR-349 [1]). As far
as I can tell, Spring Modules has used that feature since release 0.8.
[1] https://issues.apache.org/jira/browse/JCR-349
BR,
Jukka Zitting
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Jun 12, 2008 at 6:56 PM, viz06 <vi...@yahoo.com> wrote:
> Issue 1) While attempting registering nodeType (mypc.cnd file) I get the
> exception 'mypc' is not a registered namespace prefix.
The namespaces have to be registered before you import node type
definition files. The namespace declarations in the cnd file are not
automatically registered.
> What is the standard way of registering namespaces?
Doing it with the standard JCR API:
NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
registry.registerNamespace("ns", "http://server.com/my-namespace/");
Note that re-registering an existing namespace gives an exception.
Also see the Javadocs:
http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/NamespaceRegistry.html
In the case of the spring jcr module, the namespaces can be defined in
the spring config - which you already did. Maybe the additional
parameters like "forceNamespacesRegistration" are important
(https://springmodules.dev.java.net/docs/reference/0.8/html/jcr.html).
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Namespace registration
Posted by viz06 <vi...@yahoo.com>.
Thanks Alexander for replying.
Issue 1) While attempting registering nodeType (mypc.cnd file) I get the
exception 'mypc' is not a registered namespace prefix.
Here is the snippet of mypc.cnd
<mypc= 'http://www.mypc.com/mypc'>
[mypc:Folder] > nt:base, mix:referenceable
- mypc:name (string) mandatory
+ *(mypc:Folder)
+ *(mypc:Document)
This works ok if I update the ns_reg.properties manually and insert 'mypc'
namespace (which of-course is not the right way).
What is the standard way of registering namespaces?
--
View this message in context: http://www.nabble.com/Namespace-registration-tp17801235p17804724.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Namespace registration
Posted by Alexander Klimetschek <ak...@day.com>.
Hi!
On Thu, Jun 12, 2008 at 4:24 PM, viz06 <vi...@yahoo.com> wrote:
> 1. I am not able to register the namespace 'mypc' and have to manually
> modify ns_reg.properties to set the namespace.
Could you elaborate on not being able to register the namespace? Do
you get an exception?
If it is a configuration problem with spring jcr modules, please ask
on the according spring mailing list, since the Jackrabbit project
does not develop any code for Spring/JCR itself.
> 2. I have setup few spring enabled test cases which run to completion and
> creates the correct node structure, when I run the same test second time
> around all my previous nodes shows a different namespace prefix of 'fn'. I
> am unable to figure out from where it is getting this namespace prefix.
If this is related to 1., it might be because you modified the
ns_reg.properties directly. Jackrabbit stores indices to namespaces
inside the persisted data, so messing with the properties files can
actually switch the entire namespace for all nodes of a namespace.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com