Can you determine whether the zipfile contains an installation manual before
you show the user a link for it? If there is no manual, don't show the link
(or show something else). That seems like a better user experience and
simplifies the resource implementation.

Alternatively, in your resource request handling try using
RestartResponseException (instead of ResourceStreamNotFoundException) to
redirect them back to the original page, after using
Session.get().error("...") to generate a feedback message.

On Wed, Aug 17, 2011 at 12:43 AM, hfriederichs <h.friederi...@ohra.nl>wrote:

> Hello to you all,
>
> First of all, I apologise for submitting this post for the second time, but
> the first didn't use the correct user group.
>
> I'm adding a new feature to a Wicket application that manages
> JEE-applications (I'm using 1.4.18). For example, it's possible to install
> and configure a JEE-appliation on an Application server. If a user chooses
> to do so, he enters a unique application code and submits: a zipfile
> containing the application, it's documentation and configuration is
> downloaded via http from a Nexus repository, and installed with
> soap/jmx/mbeans on the application server.
>
> What I have added, is a button that - once clicked - opens an installation
> manual in msword that is part of the aforementioned zipfile. The general
> idea is: take a zipinputstream, read it until the installation manual is
> found, then hand the inputstream over to a wicket IResourceStream that
> provides the getInputStream for a Wicket WebResource. I think it's a quite
> elegant solution; it's all streaming, no temporary files etcetera.
> And it works marvelously, that is, if the zipfile actually containes a
> installation manual. My problem is twofold:
> When pressing the button without entering an application code (so there is
> no inputstream and no installation manual) wicket produces:
> org.apache.wicket.WicketRuntimeException: Could not get resource stream
>        at org.apache.wicket.Resource.init(Resource.java:217)
>        at org.apache.wicket.Resource.onResourceRequested(Resource.java:117)
>        at
>
> org.apache.wicket.markup.html.link.ResourceLink.onResourceRequested(ResourceLink.java:108)
>        ... 36 more
> That's to be expected, but the user is confronted with a white screen, and
> I
> can't catch this Exception.
> Secondly, if there is a zipinputstream, but no installation manual found in
> it, all I can do is throw a ResourceStreamNotFoundException (see my code
> below), but then again,  I can't catch it, and again there is a white
> screen
> for the user.
>
> What is need, I think, is to override onResourceRequested() in Resource,
> but
> that is a final method... And the onclick happens after
> onResourceRequested()...
>
> So what I want, is to handle the ResourceStreamNotFoundException in a
> user-friendly way, by showing an info or error message in the wicket
> feedbackpanel.
>
> The code:
> (So the user enters an application code an presses the new button:)
>
> <td><input type="button" wicket:id="downloadinstallationmanual"
> value="Download Installatiehandleiding" /></td>
>
> The button is counterparted by a ResourceLink in a Wicket-Form:
>
> private Link<String> downloadInstallationmanualButton = null;
>
> ...
>
> final InstallationManualWebResource installationManualWebResource = new
> InstallationManualWebResource(this);
> installationManualWebResource.setCacheable(false);
> downloadInstallationmanualButton = new
> ResourceLink<String>("downloadinstallationmanual",
> installationManualWebResource);
> downloadInstallationmanualButton.setOutputMarkupId(true);
> add(downloadInstallationmanualButton);
>
> The above mentioned
> InstallationManualWebResource is a subclass of WebResource, and overrides
> the usual methods:
>
>    @Override
>    public IResourceStream getResourceStream() {
>       installationManualResourceStream = new
> InstallationManualResourceStream(getZipInputStream());
>       return installationManualResourceStream;
>    }
>
>    @Override
>    protected void setHeaders(WebResponse response) {
>        super.setHeaders(response);
>        if (installationManualResourceStream.getInstallatieHandleidingName()
> != null)
>
> response.setAttachmentHeader(installationManualResourceStream.getInstallatieHandleidingName());
>    }
>
> At it's turn InstallationManualResourceStream implements IResourceStream:
>
> In it's constructor, the zipinputstream is read until an installation
> manual
> is found. If so, a boolean installationManualFound is set to true, and
> file-attributes are set (name, size, time). The implementation is
> straightforward:
>
> @Override
>    public void close() throws IOException {
>
>        zipFile.close();
>
>    }
>
>    @Override
>    public String getContentType() {
>        return "application/msword";
>    }
>
>    @Override
>    public InputStream getInputStream() throws
> ResourceStreamNotFoundException {
>        if (!installationManualFound) throw new
> ResourceStreamNotFoundException("No installation manual in zipfile");
>        return zipFile;
>    }
>
>    @Override
>    public Locale getLocale() {
>        return new Locale("nl", "NL");
>    }
>
>    @Override
>    public long length() {
>        return size;
>    }
>
>    @Override
>    public void setLocale(Locale locale) {
>
>    }
>
>    @Override
>    public Time lastModifiedTime() {
>        return Time.milliseconds(time);
>    }
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-Handle-ResourceStreamNotFoundException-tp3749331p3749331.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to