1 Reply Latest reply on Dec 3, 2007 10:26 AM by Marcus Schmidke

    Download binary files

    Marcus Schmidke Newbie

      Currently, I am searching the forums how to serve downloadable binary data in a Seam application.

      I found out so far that there are at least two possibilities:

      1. By action as described in http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamResourceLoader

      2. By Seam's built in resource mechanism based on AbstractResource class.

      Which way should I prefer? I think (2) is much more elegant, but I need to access my Persistence Context which does not seem to be possible (at least I do not understand enough of the BypassInterceptors-beginRequest-endRequest-stuff I copied from CaptchaImage :-) )


        • 1. Re: Download binary files
          Marcus Schmidke Newbie


          I removed the things I do not understand (as mentioned, beginRequest and endRequest). With this, I was able to remove BypassInterceptors, and without BypassInterceptors I can have injected my hibernate session.

          At the first sight, it works perfectly. Of course, I don't know if I am breaking something in the interns of seam or if I am creating memory leaks or whatever.

          public class Dateidownload extends AbstractResource {
           Session session;
           public void getResource(HttpServletRequest request,
           HttpServletResponse response) throws ServletException, IOException {
           // ServletLifecycle.beginRequest(request);
           try {
           String id = request.getQueryString();
           Anhang_Dokument ad = (Anhang_Dokument) session.get(
           Anhang_Dokument.class, Long.parseLong(id));
           if (ad == null)
           throw new ObjectNotFoundException(id);
           response.setHeader("Cache-Control", "no-store");
           response.setHeader("Pragma", "no-cache");
           response.setDateHeader("Expires", 0);
           } catch (Exception e) {
           } finally {
           // ServletLifecycle.endRequest(request);
           public String getResourcePath() {
           return "/download";

          There are other things in CaptchaImage I don't understand, for example the meaning of @Startup and @Install together. But as told before, I simply deleted things I did not understand, and for the moment, it works ...