Recieving getoutputstream() error with Tomcat

clients are recieving a general message when working in the adhoc utility “An internal error has occured. Please save adhoc.log and send to Business Objects Technical Support.”

We are running a BO XIR2 SP3 deployment with two front end web servers and two backend CMS servers.

The tomcat logs show the following:

2009-02-10 12:12:48 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:599)
at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:163)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.InfoView.plugin.crystalenterprise.report.viewDHTMLReport_jsp._jspService(viewDHTMLReport_jsp.java:510)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

If anyone can please provide some input it would be apprecieated. BO support has not come up with any reason as to why this is happening.


aheeter (BOB member since 2008-04-30)

Hi -

We are getting the same errors in our BOXI R2 SP2.
Sounds like we have a similar setup with two front end servers and two back end servers.

Did you ever find out what was causing these error msgs from Tomcat?

Thanks,

Deb


dfranke :us: (BOB member since 2002-08-28)

I recently solved one of these “getOutputStream()” errors…

My error stack was different, but maybe my solution may give you an idea on what to search for.

The errors I was receiving:

I started digging through these lines one at a time, trying to find the offending code…a general rule of thumb that I came up with is to start at the top and ignore anything with “jasper” in it…that usually gets you into the actual BOBJ code (which is almost always where the problem is :roll_eyes: ).

So the offending area that I looked into was “org.apache.jsp.viewers.cdz_005fadv.viewAsPDF_jsp._jspService(viewAsPDF_jsp.java:158)”. I found the file “viewAsPDF_jsp.java” in the directory “%TOMCAT_HOME%\work\Catalina\localhost\businessobjects_enterprise115_desktoplaunch\org\apache\jsp\viewers\cdz_005fadv” and the source file that it is built on is viewAsPDF.jsp located in “%TOMCAT_HOME%\webapps\businessobjects#enterprise115#desktoplaunch\viewers\cdz_adv”.

The line number provided (158), was misleading and didn’t show me where the actual problem was. Once I found both of these files, that’s where I could really start finding the issue.

In my particular case it was a simple carriage return at the end of the source file, which I figured out after doing an hour of research on Google… :blue:

In other words, the last few lines of the .jsp file below (note the additional return AFTER the “%>”):

	//Output writer
	ServletOutputStream Output = response.getOutputStream();
	objBinaryView.getContent(Output);
	Output.close();
	//Garbage collection
	objBinaryView = null;
	doc = null;
%>

If you look at the “.java” file it comes out as:

	//Output writer
	ServletOutputStream Output = response.getOutputStream();
	objBinaryView.getContent(Output);
	Output.close();
	//Garbage collection
	objBinaryView = null;
	doc = null;

      out.write('\r');
      out.write('\n');

The error occurs during the “out.write” commands because the output has been closed…so as simple as it seems, any extra space, character, or return after the “%>”, creates those out.write statements and throws an error…

So if you’re ever editing ANY of the jsp files that have multiple sections that are parsed into java classes make sure there’s never anything between the “%>” and “<%”.

Like this:

<%@ page language="java"
%><%
@ page language="java"%>

But NOT like this:

<%@ page language="java"%>
<%@ page language="java"%>

So anyhow, this is how I solved my issue…for your issue, I would suggest you start looking at the “viewDHTMLReport_jsp.java” file, which you’ll find in your Tomcat “work” folder (if I had to gander a guess I’d say you’ll find it in “%TOMCAT_HOME%\work\Catalina\localhost\businessobjects_enterprise115_desktoplaunch\org\apache\jsp\InfoView\plugin\crystalenterprise\report”). And, also look at the source jsp page (which again, if I had to guess would be in “%TOMCAT_HOME%\businessobjects_enterprise115_desktoplaunch\Infoview\plugin\crystalenterprises\report”).

Hope that helps you out!

= EK


euphonEK (BOB member since 2009-03-27)

For those of you who have not fixed this issue with your BOE XI R2 installations, the actual issue that causes this error message to appear in the Tomcat log is the carriage return AFTER the “%>” in the ‘downloadPDForEXCEL.jsp’ and ‘viewAsPDF.jsp’ files. This thread was a great help in figuring this out. With a little experimenting it turned out to be the carriage return AFTER the “%>”, not the carriage return before the “%>”.

I hope this is helpful to anyone who may still need to work out this issue.


mgrackin :us: (BOB member since 2002-08-29)

Hi,
I modify viewAsPDF.jsp in this way:

<!--
=============================================================
WebIntelligence(r) Report Panel
Copyright(c) 2001-2005 Business Objects S.A.
All rights reserved

Use and support of this software is governed by the terms
and conditions of the software license agreement and support
policy of Business Objects S.A. and/or its subsidiaries. 
The Business Objects products and technology are protected
by the US patent number 5,555,403 and 6,247,008

=============================================================
--><%@ page language="java" contentType="text/html;charset=UTF-8"
%><%
@ page import="com.businessobjects.adv_ivcdzview.*,
 java.util.*,java.net.URLEncoder"%>
<jsp:useBean id="objUtils" class="com.businessobjects.adv_ivcdzview.Utils" scope="application" />
<jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page">
<%
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
%>
</jsp:useBean>
<%
try
{
String strEntry = requestWrapper.getQueryParameter("sEntry", true);
String strName = requestWrapper.getQueryParameter("name", true);
if (strName.startsWith("/") &amp;&amp; strName.endsWith(".pdf"))
{
int len = strName.length();
strName = strName.substring(1, len-4);
}
String notEncodedStrName = strName;
strName = ViewerTools.encodeDocName4Download(strName);
String strQueryString = requestWrapper.getQueryString();
session.setAttribute(ViewerTools.getSessionVariableKey("VIEWASPDF_QUERYSTRING"), strQueryString);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var p = parent.parent;
var url = p._root;
p.getHttpServerObject(url+"/html/empty.html", viewPDF)
function viewPDF(xmlhttp)
{
var iPos = url.indexOf('/viewers/cdz_adv');
var pattern=/IIS/gi
var httpServerName = xmlhttp.getResponseHeader("Server");
if(httpServerName.match(pattern))
url = url.substring(0, iPos) + '/ViewAsPDF/<%=URLEncoder.encode(strEntry, "UTF-8")%>/<%=ViewerTools.escapeQuotes(ViewerTools.replace(notEncodedStrName,"%","_",false))%>.pdf';
else
url = url.substring(0, iPos) + '/ViewAsPDF/<%=URLEncoder.encode(strEntry, "UTF-8")%>/<%=ViewerTools.escapeQuotes(strName)%>.pdf';
self.location.replace(url);
}
</script>
</head>
<body></body>
</html>
<%
}
catch(Exception e)
{
objUtils.displayErrorMsg(e, "_ERR_VIEWER_PDFMODE", true, out, session);
}
%>

and this file downloadPDForXLS.jsp in this way

<%@ page language="java" contentType="application/pdf" errorPage="errorPage4Download.jsp" import="com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*"%><jsp:useBean id="objUtils" class="com.businessobjects.adv_ivcdzview.Utils" scope="application" /><jsp:useBean id="objUserSettings" class="com.businessobjects.adv_ivcdzview.UserSettings" scope="session" /><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
response.reset();
response.setDateHeader("expires", 0);
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
String strEntry = requestWrapper.getQueryParameter("sEntry", true);
String strViewType = requestWrapper.getQueryParameter("viewType", true);
String strSaveReport = requestWrapper.getQueryParameter("saveReport", false, "N");
DHTMLLogger _logger = Utils.getLogger("com.businessobjects.dhtml." + requestWrapper.getCurrentPageName());
_logger.info("viewType=" + strViewType);
if (strViewType.equals("P"))
{
String theAgent = request.getHeader("user-agent");
if (null == theAgent) theAgent = "";
if (theAgent.equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", "application/pdf");
response.setStatus(HttpServletResponse.SC_OK);
return;
}
}
ReportEngines reportEngines = (ReportEngines)session.getAttribute(ViewerTools.SessionReportEngines);
DocumentInstance doc = reportEngines.getDocumentFromStorageToken(strEntry);
BinaryView objBinaryView = null;
String strContentType = "";
String strDocExt = "";
Reports arrReports = null;
Report objReport = null;
if(strSaveReport.equalsIgnoreCase("Y"))
{
String iReport = requestWrapper.getQueryParameter("iReport", true);
int nReportIndex = Integer.parseInt(iReport);
arrReports = doc.getReports();
objReport = arrReports.getItem(nReportIndex);
objReport.setPaginationMode(PaginationMode.Listing);
}
if (strViewType.equalsIgnoreCase("P"))
{
strDocExt = ".pdf";
strContentType = "application/pdf";
if (request.getHeader("User-Agent").equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", strContentType);
return;
}
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.PDF);
_logger.info(" download report as PDF");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.PDF);
_logger.info(" download document as PDF");
}
}
else if (strViewType.equalsIgnoreCase("X"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLS);
_logger.info(" download report as Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLS);
_logger.info(" download document as Excel");
}
}
else if (strViewType.equalsIgnoreCase("T"))
{
strDocExt = ".txt";
strContentType = "application/txt";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.TEXT);
_logger.info(" download report as Text");
}
}
else if (strViewType.equalsIgnoreCase("O"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download report as Optimized Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download document as Optimized Excel");
}
}
else
{
String strMsg = "Unknown document view type: " + strViewType;
throw new Exception(strMsg);
}
String strDocName = doc.getProperties().getProperty(PropertiesType.NAME, "");
int iLength = objBinaryView.getContentLength();
response.setContentLength(iLength);
response.setContentType(strContentType);
response.setHeader("Content-Disposition", "attachment;filename=\"" + ViewerTools.encodeDocName4Download(strDocName) + strDocExt + "\"");
ServletOutputStream Output = response.getOutputStream();
objBinaryView.getContent(Output);
Output.close();
objBinaryView = null;
doc = null;
arrReports = null;
objReport = null;
%>

I continue to receive exception on tomcat 6, when open a new report to visualize it.
Are there more files to be modified?

Tomcat6 exception:

15-mar-2013 0.11.07 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
	at org.apache.catalina.connector.Response.getWriter(Response.java:611)
	at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
	at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
	at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
	at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
	at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
	at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
	at org.apache.jsp.viewers.cdz_005fadv.getImage_jsp._jspService(getImage_jsp.java:104)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.businessobjects.webutil.websessiontimeout.WebSessionTimeoutFilter.doFilter(WebSessionTimeoutFilter.java:161)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.businessobjects.adv_ivcdzview.SetCharacterEncodingFilter.doFilter(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)

Thommino79 (BOB member since 2013-03-14)

Thommino -

It looks like the issue with viewAsPDF.jsp and downloadPDForXLS.jsp is the same thing as the previous files. The very last ending character has a carriage return after it.

Open the file again go all the way to the bottom of the file and remove the new line after the “%>”.

I’m betting there are still a lot more of these in other JSP files…

= EK


euphonEK (BOB member since 2009-03-27)

As you can see from previous code there are no more “return char” after %>
Where do you see it?


Thommino79 (BOB member since 2013-03-14)

Sorry, I didn’t necessarily see it in your code, but I figured that might have just been how you cut and pasted it…

I just know that was the only edit I needed to make to that file to get rid of the errors.

As an aside, all the files I edited (removed extra returns and spaces from) were:
[list]downloadPDFForXLS.jsp
getImage.jsp
getKindIcon.jsp
viewAsPDF.jsp[/list]
You might also take a look at “getPDFView.jsp”? I can’t say for sure because I’m not seeing the errors anymore after making the aforementioned modifications.

Also, I’m testing this with Tomcat 7 now, so that might also be a factor…


euphonEK (BOB member since 2009-03-27)

Which version of BO are you using?
We have BO XI 3,1 SP 5.3
I modified in this way:

downloadPDForXLS.jsp

<%@ page language="java" contentType="application/pdf" errorPage="errorPage4Download.jsp" import="com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*"%><jsp:useBean id="objUtils" class="com.businessobjects.adv_ivcdzview.Utils" scope="application" /><jsp:useBean id="objUserSettings" class="com.businessobjects.adv_ivcdzview.UserSettings" scope="session" /><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
response.reset();
response.setDateHeader("expires", 0);
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
String strEntry = requestWrapper.getQueryParameter("sEntry", true);
String strViewType = requestWrapper.getQueryParameter("viewType", true);
String strSaveReport = requestWrapper.getQueryParameter("saveReport", false, "N");
DHTMLLogger _logger = Utils.getLogger("com.businessobjects.dhtml." + requestWrapper.getCurrentPageName());
_logger.info("viewType=" + strViewType);
if (strViewType.equals("P"))
{
String theAgent = request.getHeader("user-agent");
if (null == theAgent) theAgent = "";
if (theAgent.equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", "application/pdf");
response.setStatus(HttpServletResponse.SC_OK);
return;
}
}
ReportEngines reportEngines = (ReportEngines)session.getAttribute(ViewerTools.SessionReportEngines);
DocumentInstance doc = reportEngines.getDocumentFromStorageToken(strEntry);
BinaryView objBinaryView = null;
String strContentType = "";
String strDocExt = "";
Reports arrReports = null;
Report objReport = null;
if(strSaveReport.equalsIgnoreCase("Y"))
{
String iReport = requestWrapper.getQueryParameter("iReport", true);
int nReportIndex = Integer.parseInt(iReport);
arrReports = doc.getReports();
objReport = arrReports.getItem(nReportIndex);
objReport.setPaginationMode(PaginationMode.Listing);
}
if (strViewType.equalsIgnoreCase("P"))
{
strDocExt = ".pdf";
strContentType = "application/pdf";
if (request.getHeader("User-Agent").equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", strContentType);
return;
}
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.PDF);
_logger.info(" download report as PDF");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.PDF);
_logger.info(" download document as PDF");
}
}
else if (strViewType.equalsIgnoreCase("X"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLS);
_logger.info(" download report as Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLS);
_logger.info(" download document as Excel");
}
}
else if (strViewType.equalsIgnoreCase("T"))
{
strDocExt = ".txt";
strContentType = "application/txt";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.TEXT);
_logger.info(" download report as Text");
}
}
else if (strViewType.equalsIgnoreCase("O"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download report as Optimized Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download document as Optimized Excel");
}
}
else
{
String strMsg = "Unknown document view type: " + strViewType;
throw new Exception(strMsg);
}
String strDocName = doc.getProperties().getProperty(PropertiesType.NAME, "");
int iLength = objBinaryView.getContentLength();
response.setContentLength(iLength);
response.setContentType(strContentType);
response.setHeader("Content-Disposition", "attachment;filename=\"" + ViewerTools.encodeDocName4Download(strDocName) + strDocExt + "\"");
ServletOutputStream Output = response.getOutputStream();
objBinaryView.getContent(Output);
Output.close();
objBinaryView = null;
doc = null;
arrReports = null;
objReport = null;
%>

getImage.jsp

<%@ page language="java" import="com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*"%><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
try
{
response.reset();
long now = System.currentTimeMillis();
response.setDateHeader("Expires", now + 120000);
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
String strEntry = requestWrapper.getQueryParameter("sEntry");
if (strEntry == null)
throw new Exception("Internal Error: Missing sEntry parameter.");
String strImageName = requestWrapper.getQueryParameter("name");
if ( strImageName == null )
throw new Exception("Internal Error: Missing name parameter.");
ReportEngines reportEngines = (ReportEngines)session.getAttribute(ViewerTools.SessionReportEngines);
DocumentInstance doc = reportEngines.getDocumentFromStorageToken(strEntry);
Image objImage = doc.getImage(strImageName);
ServletOutputStream Output = response.getOutputStream();
response.setContentType( objImage.getContentType() );
response.setContentLength(objImage.getContentLength());
objImage.getContent(Output);
Output.close();
objImage = null;
doc = null;
}
catch(Exception e)
{
e.printStackTrace();
}
%>

getKindIcon.jsp

<%@ page language="java" import="java.io.*,com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*,com.crystaldecisions.sdk.framework.IEnterpriseSession,com.crystaldecisions.sdk.occa.pluginmgr.IPluginInfo"%><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
requestWrapper.onStart(request);
DHTMLLogger _logger = Utils.getLogger("com.businessobjects.dhtml." + requestWrapper.getCurrentPageName());
try
{
response.reset();
requestWrapper.setCharacterEncoding("UTF-8");
boolean isAlive = (session.getAttribute(ViewerTools.SessionAlive) == null)?false:true;
if (!isAlive) return;
String strSession = (String)session.getAttribute(ViewerTools.SessionEntSessionName);
if (strSession == null)
{
strSession = "CE_ENTERPRISESESSION";
session.setAttribute(ViewerTools.SessionEntSessionName, strSession);
}
IEnterpriseSession entSession = (IEnterpriseSession) session.getAttribute(strSession);
String progID = requestWrapper.getQueryParameter("progID");
if (progID == null)
throw new Exception("Internal Error: Missing progID parameter.");
IPluginInfo info = entSession.getPluginManager().getPluginInfo(progID);
InputStream stream = info.getPicture();
if (stream == null) {
_logger.error("IPluginInfo=" + info);
_logger.error("stream == null");
        return;
}
ServletOutputStream os = response.getOutputStream();
byte[] buffer = new byte[512];
while (-1 != stream.read(buffer)) {
    os.write(buffer);
}
os.close();
}
catch(Exception e)
{
_logger.error(e.getMessage());
}
%>

viewAsPDF.jsp

<!--
=============================================================
WebIntelligence(r) Report Panel
Copyright(c) 2001-2005 Business Objects S.A.
All rights reserved

Use and support of this software is governed by the terms
and conditions of the software license agreement and support
policy of Business Objects S.A. and/or its subsidiaries. 
The Business Objects products and technology are protected
by the US patent number 5,555,403 and 6,247,008

=============================================================
--><%@ page language="java" contentType="text/html;charset=UTF-8"
%><%@ page import="com.businessobjects.adv_ivcdzview.*,
 java.util.*,java.net.URLEncoder"%>
<jsp:useBean id="objUtils" class="com.businessobjects.adv_ivcdzview.Utils" scope="application" />
<jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page"><%
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
%></jsp:useBean><%
try
{
String strEntry = requestWrapper.getQueryParameter("sEntry", true);
String strName = requestWrapper.getQueryParameter("name", true);
if (strName.startsWith("/") &amp;&amp; strName.endsWith(".pdf"))
{
int len = strName.length();
strName = strName.substring(1, len-4);
}
String notEncodedStrName = strName;
strName = ViewerTools.encodeDocName4Download(strName);
String strQueryString = requestWrapper.getQueryString();
session.setAttribute(ViewerTools.getSessionVariableKey("VIEWASPDF_QUERYSTRING"), strQueryString);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var p = parent.parent;
var url = p._root;
p.getHttpServerObject(url+"/html/empty.html", viewPDF)
function viewPDF(xmlhttp)
{
var iPos = url.indexOf('/viewers/cdz_adv');
var pattern=/IIS/gi
var httpServerName = xmlhttp.getResponseHeader("Server");
if(httpServerName.match(pattern))
url = url.substring(0, iPos) + '/ViewAsPDF/<%=URLEncoder.encode(strEntry, "UTF-8")%>/<%=ViewerTools.escapeQuotes(ViewerTools.replace(notEncodedStrName,"%","_",false))%>.pdf';
else
url = url.substring(0, iPos) + '/ViewAsPDF/<%=URLEncoder.encode(strEntry, "UTF-8")%>/<%=ViewerTools.escapeQuotes(strName)%>.pdf';
self.location.replace(url);
}
</script>
</head>
<body></body>
</html>
<%
}
catch(Exception e)
{
objUtils.displayErrorMsg(e, "_ERR_VIEWER_PDFMODE", true, out, session);
}
%>

I’m having yet this exception:

java.lang.NullPointerException
	at org.apache.jsp.viewers.cdz_005fadv.getImage_jsp._jspService(getImage_jsp.java:79)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.businessobjects.webutil.websessiontimeout.WebSessionTimeoutFilter.doFilter(WebSessionTimeoutFilter.java:161)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.businessobjects.adv_ivcdzview.SetCharacterEncodingFilter.doFilter(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)

Have you got other ideas?


Thommino79 (BOB member since 2013-03-14)

Just upgraded to XI3.1 SP6, but we were having the same issues all the way back to XI R2…

This is a completely different error…the original error in this discussion was:

java.lang.IllegalStateException: getOutputStream() has already been called for this response

I’m guessing something that you changed in the getImage.jps file is now causing a new error…?

For comparison purposes, here are my files:
downloadPDForXLS.jsp (Note: ONLY change made was removing the superfluous carriage return at the very end of the file.)

<%@ page language="java" contentType="application/pdf" errorPage="errorPage4Download.jsp" import="com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*"%><jsp:useBean id="objUtils" class="com.businessobjects.adv_ivcdzview.Utils" scope="application" /><jsp:useBean id="objUserSettings" class="com.businessobjects.adv_ivcdzview.UserSettings" scope="session" /><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
response.reset();
response.setDateHeader("expires", 0);
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
String strEntry = requestWrapper.getQueryParameter("sEntry", true);
String strViewType = requestWrapper.getQueryParameter("viewType", true);
String strSaveReport = requestWrapper.getQueryParameter("saveReport", false, "N");
DHTMLLogger _logger = Utils.getLogger("com.businessobjects.dhtml." + requestWrapper.getCurrentPageName());
_logger.info("viewType=" + strViewType);
if (strViewType.equals("P"))
{
String theAgent = request.getHeader("user-agent");
if (null == theAgent) theAgent = "";
if (theAgent.equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", "application/pdf");
response.setStatus(HttpServletResponse.SC_OK);
return;
}
}
ReportEngines reportEngines = (ReportEngines)session.getAttribute(ViewerTools.SessionReportEngines);
DocumentInstance doc = reportEngines.getDocumentFromStorageToken(strEntry);
BinaryView objBinaryView = null;
String strContentType = "";
String strDocExt = "";
Reports arrReports = null;
Report objReport = null;
if(strSaveReport.equalsIgnoreCase("Y"))
{
String iReport = requestWrapper.getQueryParameter("iReport", true);
int nReportIndex = Integer.parseInt(iReport);
arrReports = doc.getReports();
objReport = arrReports.getItem(nReportIndex);
objReport.setPaginationMode(PaginationMode.Listing);
}
if (strViewType.equalsIgnoreCase("P"))
{
strDocExt = ".pdf";
strContentType = "application/pdf";
if (request.getHeader("User-Agent").equalsIgnoreCase("contype"))
{
response.setHeader("Content-Type", strContentType);
return;
}
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.PDF);
_logger.info(" download report as PDF");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.PDF);
_logger.info(" download document as PDF");
}
}
else if (strViewType.equalsIgnoreCase("X"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLS);
_logger.info(" download report as Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLS);
_logger.info(" download document as Excel");
}
}
else if (strViewType.equalsIgnoreCase("XX")) 
{
strDocExt = ".xlsx";
strContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLSX);
_logger.info(" download report as Optimized Excel 2007");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLSX);
_logger.info(" download document as Optimized Excel 2007");
}
}
else if (strViewType.equalsIgnoreCase("T"))
{
strDocExt = ".txt";
strContentType = "application/txt";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.TEXT);
_logger.info(" download report as Text");
}
}
else if (strViewType.equalsIgnoreCase("O"))
{
strDocExt = ".xls";
strContentType = "application/vnd.ms-excel";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download report as Optimized Excel");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLSDataCentric);
_logger.info(" download document as Optimized Excel");
}
}
else if (strViewType.equalsIgnoreCase("OX")) 
{
strDocExt = ".xlsx";
strContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if(strSaveReport.equalsIgnoreCase("Y"))
{
objBinaryView = (BinaryView)objReport.getView(OutputFormatType.XLSXDataCentric);
_logger.info(" download report as Optimized Excel 2007");
}
else
{
objBinaryView = (BinaryView)doc.getView(OutputFormatType.XLSXDataCentric);
_logger.info(" download document as Optimized Excel 2007");
}
}
else
{
String strMsg = "Unknown document view type: " + strViewType;
throw new Exception(strMsg);
}
String strDocName = doc.getProperties().getProperty(PropertiesType.NAME, "");
int iLength = objBinaryView.getContentLength();
response.setContentLength(iLength);
response.setContentType(strContentType);
response.setHeader("Content-Disposition", "attachment;filename=\"" + ViewerTools.encodeDocName4Download(strDocName) + strDocExt + "\"");
ServletOutputStream Output = response.getOutputStream();
objBinaryView.getContent(Output);
Output.close();
objBinaryView = null;
doc = null;
arrReports = null;
objReport = null;
%>

getImage.jsp (Note: changes are removing the carriage return at end of file and removing carriage return between the blocks on the first and second line.)

<%@ page language="java" import="com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*"%><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
try
{
response.reset();
long now = System.currentTimeMillis();
response.setDateHeader("Expires", now + 120000);
requestWrapper.onStart(request);
requestWrapper.setCharacterEncoding("UTF-8");
String strEntry = requestWrapper.getQueryParameter("sEntry");
if (strEntry == null)
throw new Exception("Internal Error: Missing sEntry parameter.");
String strImageName = requestWrapper.getQueryParameter("name");
if ( strImageName == null )
throw new Exception("Internal Error: Missing name parameter.");
ReportEngines reportEngines = (ReportEngines)session.getAttribute(ViewerTools.SessionReportEngines);
DocumentInstance doc = reportEngines.getDocumentFromStorageToken(strEntry);
Image objImage = doc.getImage(strImageName);
ServletOutputStream Output = response.getOutputStream();
response.setContentType( objImage.getContentType() );
response.setContentLength(objImage.getContentLength());
objImage.getContent(Output);
Output.close();
objImage = null;
doc = null;
}
catch(Exception e)
{
e.printStackTrace();
}
%>

getKindIcon.jsp (Note: ONLY change made was removing the superfluous carriage return at the very end of the file.)

<%@ page language="java" import="java.io.*,com.businessobjects.rebean.wi.*,com.businessobjects.adv_ivcdzview.*,java.util.*,com.crystaldecisions.sdk.framework.IEnterpriseSession,com.crystaldecisions.sdk.occa.pluginmgr.IPluginInfo"%><jsp:useBean id="requestWrapper" class="com.businessobjects.adv_ivcdzview.RequestWrapper" scope="page" /><%
requestWrapper.onStart(request);
DHTMLLogger _logger = Utils.getLogger("com.businessobjects.dhtml." + requestWrapper.getCurrentPageName());
try
{
response.reset();
requestWrapper.setCharacterEncoding("UTF-8");
boolean isAlive = (session.getAttribute(ViewerTools.SessionAlive) == null)?false:true;
if (!isAlive) return;
String strSession = (String)session.getAttribute(ViewerTools.SessionEntSessionName);
if (strSession == null)
{
strSession = "CE_ENTERPRISESESSION";
session.setAttribute(ViewerTools.SessionEntSessionName, strSession);
}
IEnterpriseSession entSession = (IEnterpriseSession) session.getAttribute(strSession);
String progID = requestWrapper.getQueryParameter("progID");
if (progID == null)
throw new Exception("Internal Error: Missing progID parameter.");
IPluginInfo info = entSession.getPluginManager().getPluginInfo(progID);
InputStream stream = info.getPicture();
if (stream == null) {
_logger.error("IPluginInfo=" + info);
_logger.error("stream == null");
        return;
}
ServletOutputStream os = response.getOutputStream();
byte[] buffer = new byte[512];
while (-1 != stream.read(buffer)) {
    os.write(buffer);
}
os.close();
}
catch(Exception e)
{
_logger.error(e.getMessage());
}
%>

viewAsPDF.jsp
After I looked at my SVN logs I realized that we’ve never had to modify this file, although it does appear to have the additional carriage return at the end, so that could be removed if desired (but it doesn’t seem to cause errors for me).

Also, after you make any changes it might be a good idea to shutdown Tomcat, delete everything in the Tomcat “work” directory, then restart it (note: you’ll need to wait a bit for Tomcat to recompile all the webapps).

Hopefully that helps…

= EK


euphonEK (BOB member since 2009-03-27)

your downloadPDForXLS.jsp has more id code, but for the other part is the same.

getImage.jsp is the same of yours.
getKindIcon.jsp is the same of yours.
Insiede my viewAsPDF.jsp there are some return code. Why don’t you have?
I cannot understand why you didn’t receive error.
Thanks


Thommino79 (BOB member since 2013-03-14)