Handle ResourceStreamNotFoundException in ResourceLink

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Handle ResourceStreamNotFoundException in ResourceLink

The button is counterparted by a ResourceLink in a Wicket-Form:

private Link<String> downloadInstallationmanualButton = null;


final InstallationManualWebResource installationManualWebResource = new InstallationManualWebResource(this);
downloadInstallationmanualButton = new ResourceLink<String>("downloadinstallationmanual", installationManualWebResource);

The above mentioned
InstallationManualWebResource is a subclass of WebResource, and overrides the usual methods:

    public IResourceStream getResourceStream() {
       installationManualResourceStream = new InstallationManualResourceStream(getZipInputStream());
       return installationManualResourceStream;

    protected void setHeaders(WebResponse 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:

    public void close() throws IOException {

    public String getContentType() {
        return "application/msword";

    public InputStream getInputStream() throws ResourceStreamNotFoundException {
        if (!installationManualFound) throw new ResourceStreamNotFoundException("No installation manual in zipfile");
        return zipFile;

    public Locale getLocale() {
        return new Locale("nl", "NL");

    public long length() {
        return size;

    public void setLocale(Locale locale) {


    public Time lastModifiedTime() {
        return Time.milliseconds(time);

Hello to you all,

I'm adding a new feature to a Wicket application that manages JEE-applications. 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, ia 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:)

<input type="button" wicket:id="downloadinstallationmanual" value="Download Installatiehandleiding" />