Announcement Announcement Module
Collapse
No announcement yet.
Unable to execute samples Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to execute samples

    When I try to execute a simple JCR call, a java.lang.NullPointerException is thrown.

    This is my application-context.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    
    	<!-- Register Annotation-based Post Processing Beans -->
    	<context:annotation-config />
    
    	<!-- <bean id="repository" class="org.springframework.extensions.jcr.jackrabbit.RepositoryFactoryBean"> -->
    	<bean id="repository" class="org.springframework.extensions.jcr.jackrabbit.TransientRepositoryFactoryBean">
    		<property name="configuration" value="classpath:repository.xml" />
    		<property name="homeDir" value="file:/tmp/repository" />
    	</bean>
    
    	<bean id="sessionFactory" class="org.springframework.extensions.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" value="pass"/>
    			</bean>
    		</property>
    	</bean>
    
    	<bean id="jcrTemplate" class="org.springframework.extensions.jcr.JcrTemplate">
    		<property name="sessionFactory" ref="sessionFactory" />
    		<property name="allowCreate" value="true" />
    	</bean>
    </beans>
    And this is my sample code:
    Code:
    public class TestServlet extends HttpServlet {
      private static Logger log = LoggerFactory.getLogger(TestServlet.class);
      private static final long serialVersionUID = 8388111332983911121L;
      JcrTemplate template;
    
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        try {
          saveSmth();
        } catch (Exception e) {
          e.printStackTrace();
        }
    
        try {
          new conejo().saveBoto();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    	
      public void saveSmth() {
        template.execute(new JcrCallback() {
          public Object doInJcr(Session session) throws IOException, RepositoryException {
            Node root = session.getRootNode();
            log.info("starting from root node " + root);
            Node sample = root.addNode("sample node");
            sample.setProperty("sample property", "bla bla");
            log.info("saved property " + sample);
            session.save();
            return null;
          }
        });
      }
    	
      public class conejo extends JcrDaoSupport {
        public void saveBoto() throws DataAccessException {
          Session session = getSession();
    	
          try {
            Node root = session.getRootNode();
            log.info("starting from root node " + root);
            Node sample = root.addNode("sample node");
            sample.setProperty("sample property", "bla bla");
            log.info("saved property " + sample);
            session.save();
          } catch (RepositoryException ex) {
            throw convertJcrAccessException(ex);
          }
        }
      }
    }

  • #2
    Hi mokiki, can you paste the entire stacktrace?
    Thanks!

    Comment


    • #3
      The problem was my poor Spring knowledge: I made a new to obtain a new instance instead of getting the initialized bean from spring.

      Actually my main problem is described in the "Node lock and session lock token" thread. Would be great any tip on this

      Comment

      Working...
      X