You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jon Evans <jo...@pobox.com> on 2007/12/19 13:16:48 UTC

Cached AbstractReader

Hi,

I'm using Cocoon 2.1.10.

I've implemented a class which extends AbstractReader. It uses some  
SOAP calls to pull some binary gif image data from a remote system. It  
implements CacheableProcessingComponent as well, and my getValidity()  
method is simply:

	private static final long VALID_FOR = 2 * 60 * 60 * 1000; // 2 hours

	public SourceValidity getValidity() {
		SourceValidity validity = new  
ExpiresValidity(System.currentTimeMillis() + VALID_FOR);
		return validity;
	}

Some of the products that I'm getting images for don't actually have  
images, so in those cases I throw a ResourceNotFoundException from my  
generate() method. The cacheing pipeline which serves the image has a  
map:handle-errors section which serves up a default image instead.

My problem is that the resource is not cached if I throw a  
MissingResourceException. How can I change the way I'm doing this so  
that even a "missing resource" response is cached? At the moment,  
products with no icons cause the remote system to be hit every time,  
and the SOAP calls are quite slow.

The only thing I can think of is to stream the default image data out  
of my reader if the product has no image, by directly opening the  
default image file from disk inside the reader. Is there a better way?

Thanks

Jon

PS happy christmas everyone!

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


RE: Cached AbstractReader

Posted by Ard Schrijvers <a....@hippo.nl>.
>From the top of my head (so might be off a little)

You should be able to wrap the src in your reader with the cached:
protocol source-factory (just start with src="cached:..." ), and make it
a asynchronous (when the remote image isn't available which is refetched
in the background, the formerly fetched image will be served) get
possibly with an expires (see cocoon.xconf, there are examples).
Obviously, extending the mechanism to serve a default image when the
remote source isn't available is trivial

Regards Ard

> 
> 
> Jon Evans wrote:
> > I've implemented a class which extends AbstractReader. It uses some 
> > SOAP calls to pull some binary gif image data from a remote system.
> > My problem is that the resource is not cached if I throw a 
> > MissingResourceException.
> > At the moment, products with no icons cause the remote system to be 
> > hit every time, and the SOAP calls are quite slow.
> >
> > The only thing I can think of is to stream the default 
> image data out 
> > of my reader if the product has no image, by directly opening the 
> > default image file from disk inside the reader.
> 
> Yes, I think this is the best course of action.
> 
> You might want to make the path to the default image a 
> configuration parameter, of course, so that you won't have to 
> recompile your reader when the path changes, or if you want 
> different default images for different products.
> 
> 
> Tobia
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 

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


Cocoon 2.2 tutorial

Posted by Robin Rigby <ro...@gondolier.org.uk>.
 
Cocoon 2.2 may be wonderful when you get to know it but meanwhile the
multiple learning curves are tiresome.  I mean maven + spring + eclipse +
cocoon.

How do I identify what is missing, here?  The third page of the tutorial [3]
works fine.  At the top of the next page [4], the web application is OK but
then I create a parent pom and I get the error below.  Eclipse won't let me
open the parent pom, so I have to run 'mvn install' from the command line.
It seems to process myBlock2 and myBlock1, then fail in myCocoonWebapp,
which works perfectly well on its own.

I have checked that org.apache.maven.plugins:maven-war-plugin:2.0.2 is in my
local repository.  Tried mvn -U.  Doesn't help.

Other threads have suggested deleting (all or part of) the repository and
starting again.  That cannot be a satisfactory solution for a system that
may one day go into production.

Is there somewhere a guide to where to look first to identify maven
dependency problems?  

Please
 
Robin 

[3] http://cocoon.zones.apache.org/dev-docs/2.2/1291_1_1.html
[4] http://cocoon.zones.apache.org/dev-docs/2.2/1362_1_1.html

[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal
'org.apache.maven.plugins:maven-war-plugin:2.0.2:war': Unable to find the
mojo 'org.apache.maven.plugins:maven-war-plugin:2.0.2:war' in the plugin
'org.apache.maven.plugins:maven-war-plugin'
Component descriptor cannot be found in the component repository:
org.apache.maven.plugin.Mojoorg.apache.maven.plugins:maven-war-plugin:2.0.2:
war.
[INFO]
------------------------------------------------------------------------



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


Re: Cached AbstractReader

Posted by Jon Evans <jo...@pobox.com>.
Hi,

On 21 Dec 2007, at 10:37, Tobia Conforto wrote:

> I'm not sure what Configurable is supposed to do (I haven't got around
> to studying Avalon yet!) but every Cocoon Reader must implement  
> setup()
> (see: http://tinyurl.com/ynkwv2 ) and if the 4th argument to setup()  
> is
> called pars, you can just do: pars.getParameter("defaultFilename");

That was it. I'd extended AbstractReader so it hid the fact that the  
setup() method was there. In fact AbstractReader puts the parameters  
in a field ready to be accessed from the generate() method.

I also found out about the ServiceableReader class at the link you  
gave, which further simplified my class.

Thanks

Jon

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


Re: Cached AbstractReader

Posted by Tobia Conforto <to...@linux.it>.
Jon Evans wrote:
> How would I have made it work as a Configurable reader? I had this in
> my sitemap:
>
> <map:read type="conceptimage" mime-type="image/gif" src="{1}"/>
>   <map:parameter name="defaultFilename"
>     value="context://images/default.gif"/>
> </map:read>

I'm not sure what Configurable is supposed to do (I haven't got around
to studying Avalon yet!) but every Cocoon Reader must implement setup()
(see: http://tinyurl.com/ynkwv2 ) and if the 4th argument to setup() is
called pars, you can just do: pars.getParameter("defaultFilename");


Tobia

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


Re: Cached AbstractReader

Posted by Jon Evans <jo...@pobox.com>.
Hi Tobia,

On Dec 20, 2007 12:47 PM, Tobia Conforto <to...@linux.it> wrote:
> Jon Evans wrote:
> > I've implemented a class which extends AbstractReader. It uses some
> > SOAP calls to pull some binary gif image data from a remote system.
> > My problem is that the resource is not cached if I throw a
> > MissingResourceException.
> > At the moment, products with no icons cause the remote system to be
> > hit every time, and the SOAP calls are quite slow.
> >
> > The only thing I can think of is to stream the default image data out
> > of my reader if the product has no image, by directly opening the
> > default image file from disk inside the reader.
>
> Yes, I think this is the best course of action.
>
> You might want to make the path to the default image a configuration
> parameter, of course, so that you won't have to recompile your reader
> when the path changes, or if you want different default images for
> different products.

Thanks, I have got it working now. I couldn't get a Configurable
component to work for some reason, so I ended up with a Parametizable
one which is just as good for my purposes because there's only one
instance of it in the sitemap. I pass in a default image url prefixed
with context:// and I look it up inside the reader with SourceResolver
when I need it. It seems to work fine.

How would I have made it work as a Configurable reader? I had this in
my sitemap:

<map:read type="conceptimage" mime-type="image/gif" src="{1}"/>
  <map:parameter name="defaultFilename"
    value="context://images/default.gif"/>
</map:read>

but from the reader's configure() method,
config.getAttribute("defaultFilename") just threw an exception.

Thanks also Ard for your suggestions.

Jon

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


Re: Cached AbstractReader

Posted by Tobia Conforto <to...@linux.it>.
Jon Evans wrote:
> I've implemented a class which extends AbstractReader. It uses some
> SOAP calls to pull some binary gif image data from a remote system.
> My problem is that the resource is not cached if I throw a
> MissingResourceException.
> At the moment, products with no icons cause the remote system to be
> hit every time, and the SOAP calls are quite slow.
>
> The only thing I can think of is to stream the default image data out
> of my reader if the product has no image, by directly opening the
> default image file from disk inside the reader.

Yes, I think this is the best course of action.

You might want to make the path to the default image a configuration
parameter, of course, so that you won't have to recompile your reader
when the path changes, or if you want different default images for
different products.


Tobia

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