Guys,
I have use-case where a user can choose to preview a pdf, displayed inline
in the browser window (without being prompted for the save/open dialog). The
functionality is working all fine, its just that an IllegalStateException is
being generated ("Response has already been committed, be sure not to write
to the OutputStream......) which i would want to figure out why? and how to
avoid it. Below is very approach opted (using DynamicWebResource) to flush
out the contents of the dynamically generated PDF. Please note that i
initially was following another approach also listed below, which worked
fine on all browsers (with no such exception being raised) EXCEPT for
certain versions of IE, due to which i had to switch to this latter
approach..
/** Exception Stack Trace - START **/
ERROR - WebResponse - Unable to redirect to: ?wicket:interface=:0:1:::, HTTP
Response has already been committed.
ERROR - WicketFilter - closing the buffer error
java.lang.IllegalStateException: Response has already been committed, be
sure not to write to the OutputStream or to trigger a commit due to any
other action before calling this method.
at
com.evermind.server.http.EvermindHttpServletResponse.sendRedirect(EvermindHttpServletResponse.java:1359)
at
org.apache.wicket.protocol.http.WebResponse.redirect(WebResponse.java:232)
at
org.apache.wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:66)
at
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:403)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:199)
at
com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
at.....
oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at
com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
/* Exception Stack Trace - END */
---------------
/* Forms onSubmit CURRENT IMPLEMENTATION - resulting in the above exception
without breaking any flow*/
protected void onSubmit()
{
Resource cResource =
new
CertificatePDFResource(certificate.getCertificateId()); //
ResourceStreamRequestTarget cTarget =
new
ResourceStreamRequestTarget(cResource.getResourceStream());
cTarget.respond(getRequestCycle());
};
/* EARLIER IMPLEMENTATION of onSubmit() which didnt work on certain versions
of IE*/
protected void onSubmit()
{
Resource cResource =
new
CertificatePDFResource(certificate.getCertificateId()); //
cResource.onResourceRequested();
};
In the above snippet CertificatePDFResource is an implementation of
DynamicWebResource, the getResourceState() Implementation is as below..
------------------
/** getResourceState() implementation for DynamicWebResource */
protected ResourceState getResourceState() {
return new ResourceState() {
protected byte[] pdf;
public String getContentType() {
return "application/pdf";
}
public Time lastModifiedTime() {
// TODO to be re-visited
return Time.now();
}
public byte[] getData() {
return getResourceStream();
}
protected synchronized byte[] getResourceStream(){
if (pdf== null) {
pdf = Utils.getPdf.....
}
return pdf;
}
public int getLength() {
return getResourceStream().length;
}
};
Any suggestions/comments would be appreciated.
Thanks in advance,
Farhan.
--
View this message in context:
http://www.nabble.com/pdf-download---dynamically-generated-pdf-tp18349109p18349109.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]