You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2012/08/20 10:59:37 UTC

[jira] [Commented] (WICKET-4718) ResourceStreamResource#getResourceStream() is called multiple times

    [ https://issues.apache.org/jira/browse/WICKET-4718?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13437745#comment-13437745 ] 

Martin Grigorov commented on WICKET-4718:
-----------------------------------------

The default impl of org.apache.wicket.request.resource.ResourceStreamResource#getResourceStream() is:

/**
	 * Lazy or dynamic initialization of the wrapped IResourceStream(Writer)
	 * @return the underlying IResourceStream
	 */
	protected IResourceStream getResourceStream()
	{
		return stream;
	}

Since you override it then it will do whatever you do in your implementation.

I see two solutions for your case:

1) Use org.apache.wicket.request.resource.ResourceStreamResource#ResourceStreamResource(IResourceStream) constructor and thus the 'stream' will be created just once and reused many times later.

2) Cache the created value of the 'stream' in your #getResourceStream() impl and reuse it. This will make the instantiation of 'stream' lazy.
                
> ResourceStreamResource#getResourceStream() is called multiple times
> -------------------------------------------------------------------
>
>                 Key: WICKET-4718
>                 URL: https://issues.apache.org/jira/browse/WICKET-4718
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 6.0.0-beta3
>         Environment: Mac OS X 10.7.4 Lion, Java 6, IntelliJ Idea 11.1, Tomcat 7 & Jetty 7.5.0
>            Reporter: Carsten Dräger
>
> When a ResourceStreamResource is implemented to return a IResourceStream dynamically, by returning a new instance of an extended AbstractResourceStream, that ResourceStream is instantiated multiple times when a ResourceLink is clicked.
> In my case, that ResourceStream returns an AttachmentInputStream from the Ektorp library (for CouchDB interaction). This behavior results in multiple queries (currently up to four) when I click once on a ResourceLink to that resource.
> Code Examples
> Extended ResourceStreamResource: http://pastebin.com/9BB7LEiV
> Extended IResouceStream: http://pastebin.com/Z7GvzGja

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira