Question
Streaming back binary content
This topic has come up in many forms, mainly for methods to download PDFs or Excel files from PDMLink. This post does not deal with the mechanics of generating or retrieving the data to be returned but rather the methods to properly structure the action in PDMLink. The customizer's guide has good instructions for creating a JSP page and hooking that into an action. I have that down pretty good. Problem is, JSP from what I've read is not suited for streaming back binary content. Its setup for text/HTML. Yes, it can be changed and I think I have it working pretty well but I consider it a stroke of luck that it works.
There are some cases where I've see the exception "java.lang.IllegalStateException: OutputStream already obtained" returned. I believe this is where the JSP response started writing stuff back as text and I tried to re-grab the stream as xls and write to it.
Now, I mentioned that I think I've worked around it and am still using a JSP page...
<%@ page import="wt.fc...%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page contentType="application/xls" %>
...
excelUtil.createExcelFile(response.getOutputStream(),sheet1,sheet2);
response.reset();
response.setHeader("Pragma","cache");
response.setHeader("Cache-Control","private");
response.setHeader("Content-disposition","attachment; filename="+filename+".XLS");//should prompt for download
excelUtil.writeFile();
...
catch(Exception e)
{
response.setContentType("text/html");
out.println(e.getMessage());
}
But, if I still see this error, I will be forced to rewrite as servlet. Does anyone have an example how the action configuration changes to use a servlet as opposed to JSP page? Would I use a pure servlet or some extension of a API class like DefaultObjectFormProcessorDelegate? I fear I am straying back into template processor land which is not supported anymore.
Antonio Villanueva - Sr. Software Engineer - ISR Systems
UTC AEROSPACE SYSTEMS
100 Wooster Heights Road, Danbury, CT 06804
Tel: +1 203 797 5682
antonio.villanueva@utas.utc.com<">mailto:antonio.villanueva@utas.utc.com> www.utcaerospacesystems.com
CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.
There are some cases where I've see the exception "java.lang.IllegalStateException: OutputStream already obtained" returned. I believe this is where the JSP response started writing stuff back as text and I tried to re-grab the stream as xls and write to it.
Now, I mentioned that I think I've worked around it and am still using a JSP page...
<%@ page import="wt.fc...%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page contentType="application/xls" %>
...
excelUtil.createExcelFile(response.getOutputStream(),sheet1,sheet2);
response.reset();
response.setHeader("Pragma","cache");
response.setHeader("Cache-Control","private");
response.setHeader("Content-disposition","attachment; filename="+filename+".XLS");//should prompt for download
excelUtil.writeFile();
...
catch(Exception e)
{
response.setContentType("text/html");
out.println(e.getMessage());
}
But, if I still see this error, I will be forced to rewrite as servlet. Does anyone have an example how the action configuration changes to use a servlet as opposed to JSP page? Would I use a pure servlet or some extension of a API class like DefaultObjectFormProcessorDelegate? I fear I am straying back into template processor land which is not supported anymore.
Antonio Villanueva - Sr. Software Engineer - ISR Systems
UTC AEROSPACE SYSTEMS
100 Wooster Heights Road, Danbury, CT 06804
Tel: +1 203 797 5682
antonio.villanueva@utas.utc.com<">mailto:antonio.villanueva@utas.utc.com> www.utcaerospacesystems.com
CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

