IllegalStateException when using getOutputStream() Method in Custom JSP (Doc ID 1116576.1)

Last updated on MARCH 08, 2017

Applies to:

Oracle Business Process Management Suite - Version 10.3.1 and later
Information in this document applies to any platform.
***Checked for relevance on 26-Jul-2012***

Symptoms

If you try to use PdfWriter in a JSP page like in this example:

<f:invoke var="${bpmObject}" methodName="myMethod" retAttName="myAttribute" retAttScope="Page"/>
<% String myAttribute=(String)pageContext.getAttribute("myAttribute");
Document document = new Document(PageSize.A6.rotate(),10, 10, 10, 10);
PdfWriter writer = PdfWriter.getInstance(document,response.getOutputStream());
document.open();
document.newPage();
document.add(new Phrase(" "));
document.add(new Phrase(" PDF with iTEXT "));
document.add(new Phrase(myAttribute));
%>

you will get this exception using Oracle BPMStudio when you try to run the page:

The task could not be successfully executed.
Reason: 'java.lang.IllegalStateException: getOutputStream() has already been called for this response'.
Caused by: getOutputStream() has already been called for this response
fuego.lang.ComponentExecutionException: The task could not be successfully executed.
Reason: 'java.lang.IllegalStateException: getOutputStream() has already been called for this response'.
at fuego.web.execution.InteractiveExecution.setExecutionError(InteractiveExecution.java:307)
at fuego.web.execution.InteractiveExecution.process(InteractiveExecution.java:166)
at fuego.web.execution.impl.WebInteractiveExecution.process(WebInteractiveExecution.java:54)
at fuego.web.papi.TaskExecutor.processRedirect(TaskExecutor.java:239)
at fuego.web.papi.TaskExecutor.execute(TaskExecutor.java:104)
at fuego.workspace.servlet.ExecutorServlet.doAction(ExecutorServlet.java:117)
at fuego.workspace.servlet.BaseServlet.doPost(BaseServlet.java:229)
at fuego.workspace.servlet.BaseServlet.doGet(BaseServlet.java:220)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at fuego.workspace.servlet.AuthenticatedServlet.service(AuthenticatedServlet.java:83)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
...
Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:606)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
at org.apache.jasper.runtime.JspFactoryImpl.access$100(JspFactoryImpl.java:37)
at org.apache.jasper.runtime.JspFactoryImpl$PrivilegedReleasePageContext.run(JspFactoryImpl.java:173)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:73)
...

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms