Hi,

I've started using Wicket for a new project and am very pleased with the
framework.  Congratulations to the developers for eliminating the XML bingo
that some other frameworks impose.

I need to stream a file back to the client browser and I tried to adapt some
old Tapestry/servlet code which provided the same functionality. Using Wicket,
I was able to successfully send the file but I have run into the following two
issues:

1. I can't seem to set the Content-disposition for the returned file so that
the name of the file can be specified to the browser.

2. I see a Jetty server stack trace on every file upload which seems related to
the closing of the response file descriptor.


Is there a different code pattern I should be using?

I am using the following code pattern on a Wicket page.  The user has indicated
the desired file and this code gets executed from the link's onClick() handler:


public void uploadFile(DownloadDocument document) {
           Response resp = getResponse();
       resp.setContentType(document.getMimeType());
       resp.setContentLength(new Long(document.getSize()).intValue());
       
       OutputStream out = resp.getOutputStream();
        
       byte[] data = new byte[8096];
       InputStream in = document.getInputstream();
       
       /*  How do I do this in wicket ?
       
       resp.setHeader("Content-disposition",  
               "attachment; filename=" +
               document.getFileName());
       */
       
       
       int count = 0;
       while ((count = in.read(data)) > -1)
       {
           out.write(data, 0, count);
       }
       
       in.close();
       out.close(); 
}

Here is the entire stack trace I see on every file upload. Server performance
and application availability semm to be unaffected.

10:16:02.655 WARN!! Exception for
/download/download?secure=tShMZd%2FHxwObG2%2BMcwiQhZ4cGCFO5aoJy2WyvT6tRcKVYd9PXUVYWf7f4INUmTDiyo1OyY4gBQs9LTfvi7%2BpYQ%3D%3D
java.lang.IllegalStateException: Commited
        at org.mortbay.http.HttpResponse.sendRedirect(HttpResponse.java:448)
        at
org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttpResponse.java:432)
        at wicket.protocol.http.WebResponse.redirect(WebResponse.java:156)
        at 
wicket.protocol.http.WebRequestCycle.redirectTo(WebRequestCycle.java:200)
        at 
wicket.RequestCycle.redirectToExceptionErrorPage(RequestCycle.java:631)
        at wicket.RequestCycle.onRuntimeException(RequestCycle.java:592)
        at wicket.RequestCycle.respond(RequestCycle.java:671)
        at wicket.RequestCycle.request(RequestCycle.java:376)
        at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:221)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:358)
        at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
        at 
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
        at org.mortbay.http.HttpContext.handle(HttpContext.java:1807)
        at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525)
        at org.mortbay.http.HttpContext.handle(HttpContext.java:1757)
        at org.mortbay.http.HttpServer.service(HttpServer.java:879)
        at org.mortbay.http.HttpConnection.service(HttpConnection.java:790)
        at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:961)
        at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
        at 
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:218)
        at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:300)
        at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:511)


Thanks for any help,

--Johann



                
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to