Skip to main content

Posts

Showing posts with the label Cocoon

Cocoon authentication

This article will guide you through the steps showing how to use the Authentication Framework in a Cocoon 2.2 application. Maven dependencies. Spring configuration. Sitemap. Login page and controls. Maven dependencies You need the following dependency in your pom.xml : <dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-auth-impl</artifactId> <version>1.0.0</version> </dependency> Spring configuration Authentication Framework has a flexible configuration based on a concepts of applications and security handlers . There can be several applications defined and running at the same that are simply independent security zones of your web application. The security details of an application are specified using a security handler. There are several implementations provided and you're free to implement your own. Here is the SimpleSecurityHandler used that takes the hardcoded credentials: <?xml versio

Using XML Catalogs in Cocoon

In this article I'm going to show a common use case of XML Catalogs . Their usage is not only recommended to avoid certain issues but can also drastically improve the performance. I'll start with explaining the issue that I've faced recently and will conclude with the resolution. Issue To start with, I've got the following exception: java.io.IOException: Server returned HTTP response code: 429 for URL: http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd The HTTP code 429 stands for "Too Many Requests" that can appear when: The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes Just to provide some context, I have an Apache Cocoon based application that does a lot of XSLT processing with Saxon . It appears that every time Saxon reads an xml document with a DTD reference, it tries to fetch the DTD source for validation. Obviously, if the processing rate is high enough and there is no caching, you can cre

Cocoon refactorings

I've been maintaining a complex Cocoon application for a couple of years now. Unfortunately, as the code gets older, it requires more and more time for maintenance unless you keep it clean and neat from the beginning. Finally I've found time to refactor the project gradually and I'll try to keep it this way. In this article I'm going to review the steps I've taken to improve the code and build quality. Remove duplicated resources I've started with removing duplicated and unused resources (mostly images and icons). Many of them were duplicated across the application in several Cocoon blocks. So I had to keep common resources in a single shared block and modify references from other blocks accordingly. For this I've added the following sitemap rule into all blocks: <map:match pattern="shared/resource/external/**"> <map:read src="servlet:shared:/resource/external/{1}"/> </map:match> This single improvement decre

Using JavaScript hashCode to enable Cocoon caching of POST requests

I've just faced an issue with the Cocoon caching related to POST requests. Let me describe the use case here. We use a custom XQueryGenerator to execute XQuery code over Sedna XML Database and then process the XML results in the Cocoon pipeline. For the sake of performance, I configured the pipeline caching based on the expiration timeout of 60 seconds for all XQuery invocations: <map:pipeline id="cached-services" type="expires" internal-only="true"> <map:parameter name="cache-expires" value="60"/> <map:parameter name="cache-key" value="{request:sitemapURI}?{request:queryString}"/> <map:match pattern="cached-internal-xquery/**"> <map:generate src="cocoon:/xquery-macro/{1}" type="queryStringXquery"> <map:parameter name="contextPath" value="{request:contextPath}"/> </map:generate>

Using Jetty 6 to run a Cocoon block

This article explains how to set up maven jetty plugin 6 for rapid development of Cocoon applications (this part is based on the official tutorial about cocoon maven plugin ). The article also describes an interesting pitfall reported here by Robby Pelssers. Modify project pom file In order to enable Jetty support you need to add the following plugins into your project pom file: <!-- Prepares block resources and classes for Jetty plugin --> <plugin> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-maven-plugin</artifactId> <version>1.0.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>prepare</goal> </goals> <configuration> <useConsoleAppender>true</useConsoleAppender> </configuration> </execution> </executions> </plugin> <!-- Runs current coc

Using YUI3 Panel to send server transaction request from client-side

This article presents a nice way how to save some user-defined input on server and make browser wait for it before proceeding with navigation. This will be shown in a context of my use case that consists in a Cocoon Java application that allows exporting page in PDF format. Exported page is being generated by a specific Java Servlet as soon as the client browser redirects to the corresponding URL. Now assume that the end user wants to set a custom title for the exported page. Thus, we need some kind of interruption when the user clicks on the 'Export' link. It'll be implemented using nice  YUI3-based Transaction utility  and YUI3 Panel shown below: Initialize YUI3 To get started with YUI3, you should perform two steps: Load the YUI javascript file on your web page. Create and configure a new YUI instance. Please refer to this manual for code snippets. The only difference is that we'll use two modules: io and panel . Module io is required for transaction

How to efficiently cache static resources in a web application

This article is about an efficient technique of caching static resources on the client side (user's browser). There are quite many ways to implement caching including HTTP headers. A common disadvantage of them is that as soon as some resource is cached by the browser, it won't be updated until it's expired. Thus, the server loses control over the browser caching mechanism for some period of time. As a result we have to adjust the expiration time period or updating frequency somehow. The better alternative is the case when it's only the server that is in charge of the browser caching mechanism. Actually the idea has been borrowed here . If we append a GET parameter with some changing value (like a timestamp or a version) for a static resource URL, it'll force the browser to get the fresh version of the resource from the server. If we keep the parameter value steady, the resource will be taken from the browser cache. Finally this article is about implementation.

DynamicReports and Cocoon integration

This is one more tutorial on how to exploit DynamicReports reporting library in an existing web application. This time the application is based on  Cocoon 2.2 framework. This post is a continuation to the previous posts: Choosing Java reporting tool - part 2 and DynamicReports and Spring MVC integration . The complete code won't be provided here but only the essential code snippets together with usage remarks. First of all I'm writing the plan of this how to: Description of existing application data flow. Adding project dependencies. Implementing export servlet. Implementing XSLT extension for the export data source. Implementing XSLT for postprocessing. Modifying JX template. Modifying Cocoon sitemap. Description of existing application data flow Cocoon framework organizes data flow using the concept of pipelines. For details please refer to Cocoon documentation . My application uses the following component sequence in a pipeline: Standard JX template gener