Archive

Posts Tagged ‘apache-jackrabbit’

Chaining Apache CXF, JackRabbit using SpringModules

September 11th, 2009 Shrihari No comments

Apache CXF integration with Spring and SpringModules support for Apache JackRabbit provides a nice combination for chaining command of actions to be delegated across layers of the enterprise application tiers . Here is a quick tip as how to do this. A more detailed tutorial has been hosted at http://bit.ly/TmmJx

1) Web application configuration (/WEB-INF/web.xml) snippet (as specified below) loads Apache CXF configuration (classpath:cxf.xml) and delegates to CXF container

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:cxf.xml</param-value>
 </context-param>

 <servlet>
 <servlet-name>CXFServlet</servlet-name>
 <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
 <servlet-name>CXFServlet</servlet-name>
 <url-pattern>/service/*</url-pattern>
 </servlet-mapping>

2) Apache CXF’s configuration (cxf.xml) loads the Spring context configuration

 <import resource="classpath:META-INF/cxf/cxf.xml" />
 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
 <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
 <import resource="classpath:jcrcontext.xml"/>

where the SpringModules JCRContext configuration loads the JackRabbit’s RepositoryFactoryBean

<bean id="repository" class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
  <property name="configuration" value="classpath:repository.xml"/>
  <property name="homeDir" ref="./target/myrepository"/>
 </bean>

 <bean id="sessionFactory"  class="org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory">
  <property name="repository" ref="repository" />
  <property name="credentials" ref="simpleCredentials"/>
 </bean>

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

 <bean id="simpleCredentials" class="javax.jcr.SimpleCredentials">
  <constructor-arg index="0" value="bogus"/>
  <constructor-arg index="1">
   <bean factory-bean="password" factory-method="toCharArray"/>
  </constructor-arg>
 </bean>

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

This chaining can be extended to any depth and a myriad range of implementation stacks could be acheived, if a container (Spring, Seam, Guice) offer support for seamless intra-container configuration and component resolution.