cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre Juffer <>
Subject Re: [ cocoon3 ] map parameters
Date Mon, 07 Nov 2011 12:55:29 GMT
On 11/07/2011 02:21 PM, Robby Pelssers wrote:
> Hi Andre,
> Are you sure these @Path annotations are correct?
> In your sitemap you specify the pattern "create/image/creator/*"

Hi Robby,

I think you are looking at the wrong email. The code you are referring 
to is from a different email posted last week concerning an ImageResource.

The whole image thing works as follows:

1. Block A provides for a form to upload images. The form may contain 
other fields as well (this is application/block specific and not of any 
concern to the image database in block B).
2. Upon submission, block A processes the form (this is the 
ImageResource). It attaches the 'creatorId' and some other info and 
moves the image to a temporal folder (stored in 'filename'). Tested and 
works fine.
3. Block A calls block B (the image database) with 'creatorId' and 
'filename' as parameters.
4. Block B uses a NewImageGenerator to store the image in a database. 
Assigns an ID to it as well. This all is accomplished by calling a 
ImageFacade. Tested and works fine.
5. Returns XML representation to block A.
6. Block A returns XML or JSON information or whatever is required to 
the client, including a URL for use in e.g. a <img src="..." />.
7. Client displays image.

The above works very fine, apart from the creatorId issue when calling 
block B by block A (step 3 above). But I have resolved this now by 
including 'creatorId' as a regular request parameter instead. By doing 
so, the image is properly stored in the database, and the client sees 
the uploaded image. This confirms that the above works as expected.

Earlier, for testing purposes, I was calling block B directly (so, 
skipping step 1 and 2) to test the database image insertion in block B 
and to tests steps 3 to 5 by using a request like:


In the original implementation (as explained in my first email in this 
matter), I noticed that the creatorId inside the Generator was always 
zero if -NOT- including it as a regular request parameter, as I do now.

Below is the code for the Generator (removed some portions for clarity). 
I based it on 
org.apache.cocoon.servlet.component.RequestParametersGenerator, which is 
in the cocoon-servlet module.

package com.tribc.img.cocoon.servlet.component;

import com.tribc.images.interfaces.facade.ImageFacade;
import com.tribc.images.interfaces.facade.dto.ImageDTO;

import org.apache.cocoon.pipeline.component.Starter;
import org.apache.cocoon.sax.AbstractSAXProducer;
import org.apache.cocoon.sax.SAXConsumer;
import org.apache.cocoon.servlet.util.HttpContextHelper;
import org.apache.cocoon.sitemap.InvocationException;
import org.xml.sax.helpers.AttributesImpl;
import org.apache.commons.lang.Validate;

import javax.servlet.http.HttpServletRequest;

import java.util.Map;
import java.util.HashMap;

  * Creates new images.
  * @author Andr&#233; Juffer, Triacle Biocomputing
public class NewImageGenerator extends AbstractSAXProducer implements 
Starter {

   private ImageFacade imageFacade;
   private Map<String, Object> parameters;

   public NewImageGenerator()
     this.imageFacade = null;
     this.parameters = new HashMap<String, Object>();

   public void setImageFacade(ImageFacade imageFacade)
         this.imageFacade = imageFacade;

   public void setup(Map<String, Object> parameters) {
       this.parameters = parameters;

   public void execute()
       String filename = (String) this.parameters.get("filename");
       Validate.notNull(filename, "filename must not be null.");
       Validate.notEmpty(filename, "filename must not be empty");

       String creatorId = (String) this.parameters.get("creatorId");
       Validate.notNull(creatorId, "creatorId must not be null.");
       Validate.notEmpty(creatorId, "creatorId must not be empty.");

       ImageDTO dto = this.imageFacade.newImage(filename, creatorId);

       SAXConsumer saxConsumer = this.getSAXConsumer();

          // Create XML response here using the returned dto.
          // Ommitted for clarity.
     catch (Exception exception) {
       throw new InvocationException(exception.getMessage(), exception);


I have defined a bean like:

<bean name="generator:new-image"
     <property name="imageFacade" ref="tribc-images-imageFacade" />

Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email:
University of Oulu, Finland  | WWW:
StruBioCat                   | WWW:
Triacle Biocomputing         | WWW:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message