Hello Cocoon developers,

We are using Apache Cocoon 2.2 for a project and I've found a bottleneck in
our template system. We use servlet service components to render our pages
in the same way you can see for Style Block. The current Cocoon Welcome
block is an example.

This way of rendering is very useful but as currently the servlet services
components doesn't implement CacheableServiceComponent interface, all the
request will be processed completely at the end.

For our usecase, here is an example:

<map:match pattern="x">
  <map:generate ...
  <map:transform ...
  <map:include ...
  <map:serialize type="servletService">
    <map:parameter name="service"
value="servlet:style:/service/common/simple-page2html"/>
  </map:serialize>
</map:match>

The most expensive part is the serialization process because we use i18n,
Link rewriter and some transformations. We can configure everything to be
cacheable but at the end, the serialization process must be performed
entirely. I've simply extended the current ServletServiceSerializer in
CachingServletServiceSerializer adding the cache key as requested service
URL and NOPValidity as validity object. This approach has a problem, due to
the nature of the servlet service components we need to move all the
dynamically generated content from our GUI block since if we detect that
the content hasn't changed, the CachingServletServiceSerializer will not
perform any process and will return the cached content. Also, as there's a
little hack for serializer output mime type, if you want to use the new
component you must set the serialization content type explicitly. See
http://article.gmane.org/gmane.text.xml.cocoon.devel/73261

<map:match pattern="x">
  <map:generate ...
  <map:transform ...
  <map:include ...
  <map:serialize type="caching-servletService" mime-type="text/html">
    <map:parameter name="service"
value="servlet:style:/service/common/simple-page2html"/>
  </map:serialize>
</map:match>

For our usecase seems to fit well and will allow us to enable the powerful
cocoon caching system for a lot of pages. IMO, it's a problem when you want
to use the ServletServiceSerializer to have a clean and common output for
the template system and you can't use the caching even with static files.

Attached is the patch for cocoon-servlet-service-components block.

Salu2.
Index: core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/CachingServletServiceSerializer.java
===================================================================
--- core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/CachingServletServiceSerializer.java	(revisión: 0)
+++ core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/CachingServletServiceSerializer.java	(revisión: 0)
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servletservice.postable.components;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+import org.xml.sax.SAXException;
+
+public class CachingServletServiceSerializer extends ServletServiceSerializer
+		implements CacheableProcessingComponent {
+	
+	private String cacheKey;
+	
+	public Serializable getKey() {
+		return this.cacheKey;
+	}
+
+	public SourceValidity getValidity() {
+		return NOPValidity.SHARED_INSTANCE;
+	}
+
+	@Override
+	public void setup(SourceResolver resolver, Map objectModel, String src,
+			Parameters par) throws ProcessingException, SAXException,
+			IOException {
+		super.setup(resolver, objectModel, src, par);
+		try {
+			this.cacheKey = par.getParameter("service");
+		} catch (ParameterException e) {
+			throw new ProcessingException(e);
+		}
+	}
+
+}
Index: core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml
===================================================================
--- core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml	(revisión: 685509)
+++ core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml	(copia de trabajo)
@@ -31,4 +31,15 @@
       -->
     <pipeline:component mime-type="application/dummy-mime-type"/>
   </bean>
+  
+  <bean name="org.apache.cocoon.serialization.Serializer/caching-servletService"
+        class="org.apache.cocoon.servletservice.postable.components.CachingServletServiceSerializer" scope="prototype">
+    <!--
+      - This method returns dummy mime type to satisfy pipeline's requirement to have mime type determined at setup phase.
+      - In this serializer case it's not possible to satisfy this requirement so dummy value is returned and real is set in the
+      - method org.apache.cocoon.servletservice.postable.components.ServletServiceSerializer#endDocument()
+      - See http://article.gmane.org/gmane.text.xml.cocoon.devel/73261 for post explaining current (hacky) solution
+      -->
+    <pipeline:component mime-type="application/dummy-mime-type"/>
+  </bean>
 </beans>

Reply via email to