How to download a file via Portlet Bridge in JBoss EPP 5?

Solution Unverified - Updated -

Issue

  • How to stream a file out from portlet in JBoss EPP 5.
  • The code works well in seam application but doesn't in portlet using Portlet Bridge.

    public void dumpToClient(StringWriter stream, String fileName)
      throws Exception {
    
       HttpServletResponse response = this.getResponse();
    
       HttpServletRequest request = this.getRequest();
    
       String charset = ProtoConst.CSV_CHARSET;
    
       String browserType = request.getHeader("user-agent");
       if ((null != browserType) && (-1 != browserType.indexOf("MSIE"))) {
         fileName = URLEncoder.encode(fileName, "UTF-8");
       } else if ((null != browserType)
           && (-1 != browserType.indexOf("Mozilla"))) {
         fileName = new String(fileName.getBytes("UTF-8"), "UTF-8");
    
       }
    
       response.reset();
       response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
       response.setContentType("application/octet-stream;charset="
         + charset.trim());
       PrintWriter out = response.getWriter();
       out.print(stream.toString());
       out.flush();
    
       FacesContext.getCurrentInstance().responseComplete();
    }
    

Environment

  • JBoss Enterprise Portal Platform (EPP) 5
  • Portlet Bridge
  • Seam

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.