Cocoon 2.2 features a new concept for modularizing larger web applications. This allows you to have separate sitemaps mounted at different, configurable paths (like in a web.xml). You can also mount any servlet here. Inside sitemaps and other Cocoon "code" (eg. xslt, flowscript, etc., that uses Cocoon's source concept), you can call these servlets by using an URL like "servlet:foobarservlet:/resources/background-image.jpg".

Servlet Spring Bean Configuration

Example from the cocoon-servlet-service-sample block. This xml file (uniquely named cocoon-servlet-service-sample-servletService1.xml) must be in the directory "src/main/resources/META-INF/cocoon/spring" of your Cocoon 2.2 block created with Maven. The schema file for this custom bean config (the servlet: namespace prefix below is an extension provided by Cocoon) can be found here: http://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd

<?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:servlet="http://cocoon.apache.org/schema/servlet"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://cocoon.apache.org/schema/servlet http://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd">

  <bean id="org.apache.cocoon.servletservice.sample.servlet1"
        class="org.apache.cocoon.sitemap.SitemapServlet">
    <servlet:context mount-path="/cocoon-servlet-service-sample1"
             context-path="blockcontext:/cocoon-servlet-service-sample/test1">
      <servlet:init-params>
        <entry key="foo" value="bar"/>
      </servlet:init-params>
      <servlet:connections>
        <entry key="test2"
               value-ref="org.apache.cocoon.servletservice.sample.servlet2"/>
      </servlet:connections>
    </servlet:context>
  </bean>
</beans>

ServletService (last edited 2009-09-20 23:41:18 by localhost)