Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Rahul Saraswat
Exception in getting OutputStream from response object
March 13, 2013 8:58 AM
Answer

Rahul Saraswat

Rank: Junior Member

Posts: 42

Join Date: February 26, 2013

Recent Posts

HI Everyone,

I am getting an error in getting the OutputStream from the renderRequest object. The error is as follows :

org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
at com.liferay.portlet.MimeResponseImpl.getWriter(MimeResponseImpl.java:82)



The code snippet is as follows :

HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(renderResponse);
httpResponse.flushBuffer();
try{
this.outputStream = renderResponse.getPortletOutputStream();
}catch(IOException ioException){
System.out.println(" ");
this.outputStream.close();
this.outputStream.flush();
}


Thanks in advance.

Thanks & Regards
Abhimanyu Saraswat
David H Nebinger
RE: Exception in getting OutputStream from response object
March 13, 2013 9:30 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6133

Join Date: September 1, 2006

Recent Posts

You cannot manually take over the output stream. You are not in a servlet anymore.
Rahul Saraswat
RE: Exception in getting OutputStream from response object
March 13, 2013 11:34 AM
Answer

Rahul Saraswat

Rank: Junior Member

Posts: 42

Join Date: February 26, 2013

Recent Posts

Thanks for your reply David. Can you please suggest some way to get the OutputStream.

Thanks & Regards
Rahul Saraswat
David H Nebinger
RE: Exception in getting OutputStream from response object
March 13, 2013 12:02 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6133

Join Date: September 1, 2006

Recent Posts

You cannot.

I'm guessing you're trying to pass back an image or some other binary file, but the render response is not the place to do it.
Rahul Saraswat
RE: Exception in getting OutputStream from response object
March 14, 2013 2:19 AM
Answer

Rahul Saraswat

Rank: Junior Member

Posts: 42

Join Date: February 26, 2013

Recent Posts

Thanks for the reply David.
I am trying to create pdf so need to get the OutputStream from the RenderResponse. I 'll use this binary stream in processAction() of the portlet. Kindly suggest.

Thanks & Regards
Abhimanyu Saraswat
David H Nebinger
RE: Exception in getting OutputStream from response object
March 14, 2013 5:40 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6133

Join Date: September 1, 2006

Recent Posts

Nope, you cannot do this.

You're not in a servlet world anymore, Abihimanyu. This is not how you accomplish this in the portlet world.

In a portlet world, you use a resource request. Your resource request handler would generate the pdf content and can return it in the portlet's stream.
Rahul Saraswat
RE: Exception in getting OutputStream from response object
March 15, 2013 1:13 AM
Answer

Rahul Saraswat

Rank: Junior Member

Posts: 42

Join Date: February 26, 2013

Recent Posts

Thanks a lot David. It is working fine now after using resourceURL.
Thanks for your time.

Thanks & Regards
Rahul Saraswat