Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in generating inline PDF

 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In one of my J2ee application i was trying generating PDF when user click on one particular link
for this i used itext pdf utility to generate byte array which then I'm writing to outstream

In IE 6.0 I'm not able to open it as inline content as expected but it's prompting me to save the pdf where as in firefox, i'm getting the below exception

java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:229)
at javax.servlet.ServletResponseWrapper.setBufferSize(ServletResponseWrapper.java:148)
at org.apache.cocoon.Engine.handle(Engine.java:488)
at org.apache.cocoon.Cocoon.service(Cocoon.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.servlet.SabaCharacterSetFilter.doFilter(SabaCharacterSetFilter.java:95)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.web.security.DataDecryptionFilter.doFilter(DataDecryptionFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.web.tools.MonitorHttpRequestFilter.doFilter(MonitorHttpRequestFilter.java:57)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.tools.loadtest.ParamCaptureRequestFilter.doFilter(ParamCaptureRequestFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.jboss.web.catalina.security.JBossServletAuthenticator.invoke(JBossServletAuthenticator.java:71)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)


Can any body help me out to solve this issue

Thanks in advance
 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to add on this below is the code that i'm using

response.reset();
response.resetBuffer();

response.setContentType( "application/pdf" );
//response.setHeader("Content-length",Integer.toString(TalentPDFUtil.getEmployeeProfilePDF(id).toByteArray().length()));

response.setHeader("Content-disposition","inline; filename=\"" +"Print.pdf" +"\"");


OutputStream outStream = response.getOutputStream();




outStream.write(TalentPDFUtil.getEmployeeProfilePDF(id).toByteArray());

 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why are you calling these methods, I think there is no need to call them.??



 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply

i tried by removing below two lines

response.reset();
response.resetBuffer();


but still in log, I'm getting that exception

Actually after response.reset(); i was able to open pdf inline in IE otherwise it's always asking me to save

 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you flush and close the outStream ??
 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not calling flush or close on outStream
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should call them:

outStream.flush();
outStream.close();
 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already tried by calling os. flush() and os.close()
but that exception persists irrespective of it
that's why i removed that from my code
 
Anuj Pathak
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any other thing that i can add/check in my code to solve this issue

Please suggest
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know it should work by setting the content-type and passing the bytes to the outputstream and then flush and close it. am sorry I can't help you. at least could you put the whole code of your servlet here. maybe there is something else.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic