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:

http://localhost:8888/img/create/image/creator/3276800?filename=/tmp/3276800-tribc-eap-areal-view.jpg

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.

<code>
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;
  }

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

  @Override
  public void execute()
  {
    try
    {
      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();

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

</code>

I have defined a bean like:

<bean name="generator:new-image"
      class="com.tribc.img.cocoon.servlet.component.NewImageGenerator"
      scope="prototype">
    <property name="imageFacade" ref="tribc-images-imageFacade" />
</bean>


--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
Triacle Biocomputing         | WWW: www.triacle-bc.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org

Reply via email to