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, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content