ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Servlet receives unexpected IllegalStateException: Writer already obtained

oshqair
22 Jun 2011 06:18:08 GMT
22 Jun 2011 06:18:08 GMT

Dear All,
I have to view a jasper report inside zul page.
I am using jasper reports applet version 4.0.0.I have included the applet tag <n:applet> inside zul page to view a jasper report using embedded viewer class, this applet calls a servlet that gets the jasperPrint object from the Http Session and writes back the result as application/octet-stream.

The report appears with no exceptions. But when I make any action after report preview like select or save etc…, the exception are thrown:
1. java.lang.IllegalStateException: Cannot reset buffer after response has been committed
2. Servlet receives unexpected IllegalStateException: Writer already obtained

Note that it’s working successfully with tomcat application server, and no exceptions happen, the exception only appears when deploying in websphere application server ver. 6.1 or 7.0.

On the other hand, when deploying the same servlet outside the ZK project, it works fine with all servers types mentioned above.

sample of servlet code...

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		JasperPrint jasperPrint = (JasperPrint) request.getSession().getAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE);
		
		if (jasperPrint != null) {
			ServletOutputStream ouputStream = null;
			ObjectOutputStream oos = null;
			
			try {
				response.setContentType("application/octet-stream");
				ouputStream = response.getOutputStream();
				oos = new ObjectOutputStream(ouputStream);
				oos.writeObject(jasperPrint);
				oos.flush();
				ouputStream.flush();
				
			} catch(Exception e) {
				e.printStackTrace();
			} finally {
				oos.close();
				ouputStream.close();
			}
		}
	}

Any help will be appreciated.

Thank You

RyanWu
10 Jul 2011 23:06:07 GMT
10 Jul 2011 23:06:07 GMT

i guess these exceptions are caused by the buffer size, in other words, the default buffer were fulled and has been submitted to client.

you can try extend ServletOutputStream and enlarge the buffer.