Announcement Announcement Module
Collapse
No announcement yet.
Servlet.service() for servlet spring threw exception java.lang.IllegalStateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Servlet.service() for servlet spring threw exception java.lang.IllegalStateException

    Hi all,

    I wrote a web-application with Spring MVC/Web Flow. The application has a link "get document". If one click this link, an PDF file will be created in run time and will be opened in Adorbe Acrobat. The pdf file can be opened successfully. But I get exception on the server side as follow:
    Code:
    ...
    [ERROR] 13:07:57 [localhost].[/test-dsl-client].[spring] - Servlet.service() for servlet spring threw exception
    java.lang.IllegalStateException
    	at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:433)
    	at org.springframework.web.servlet.view.RedirectView.sendRedirect(RedirectView.java:304)
    	at org.springframework.web.servlet.view.RedirectView.renderMergedOutputModel(RedirectView.java:196)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:252)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1173)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
    	at java.lang.Thread.run(Thread.java:595)
    And my code to open the pdf file looks as follow:
    Code:
    ...
            try{
                // Drucke PDF
        		String downloadFileName = "Antrag.pdf";
        		HttpServletResponse httpResponse = externalContext.getResponse();
        		httpResponse.setContentType("application/pdf");
        		httpResponse.setHeader("Content-Disposition", "filename=\"" + downloadFileName + "\"");
        		OutputStream out = httpResponse.getOutputStream();
        		out.write(base64Decode(result));
        		out.flush();
        		out.close();
            }catch (IllegalStateException e) {
    			// TODO: handle exception
    		}
    ...
    One can see I try to catch the exception but it seems the exception comes from else where.

  • #2
    Is the code you have supplied part of a controller? Looks to me like the exception is being thrown further along the processing. e.g. you return the pdf to the client from a controller and then return a modelandview that trys to do a redirect. Because the response has already been written (i.e. the pdf) then you will get an IllegalStateException as per the javadoc on the sendRedirect method for the HttpServletResponse.

    Comment

    Working...
    X