Exception on sending zip file

Splash Forums Rewrite Users Exception on sending zip file

This topic contains 6 replies, has 2 voices, and was last updated by  Christian Kaltepoth 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #27336

    joe
    Participant

    ` ConfigurationBuilder builder = ConfigurationBuilder.begin();
    …….
    builder.addRule().when(Direction.isInbound().and(Path.matches(“/{fileName}.zip”))).perform(zipOperation);

    private static final HttpOperation zipOperation = new HttpOperation() {
    @Override
    public void performHttp(HttpServletRewrite event, EvaluationContext context) {
    String fileName = (String) Evaluation.property(“fileName”).retrieve(event, context);

    byte[] zipData = SiteContext.getContext().getZipFile(fileName);

    HttpServletResponse response = event.getResponse();
    response.setContentType(“application/zip”);
    response.addHeader(“Content-Disposition”, “attachment;filename=\”” + fileName + “.zip\””);
    response.addHeader(“Content-Length”, String.valueOf(zipData.length));
    try {
    response.getOutputStream().write(zipData);
    BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream());
    output.write(zipData);
    output.close();
    response.getOutputStream().close();

    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    };
    —————————–
    java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)
    at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120)
    at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.sendError(HttpRewriteWrappedResponse.java:450)
    at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:781)
    at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:411)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:191)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

    ———————————————-
    <prettyFaces.version>2.0.0.Final</prettyFaces.version>

    <dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-servlet</artifactId>
    <version>${prettyFaces.version}</version>
    </dependency>
    <dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-config-prettyfaces</artifactId>
    <version>${prettyFaces.version}</version>
    </dependency>

    • This topic was modified 6 months ago by  joe.
    • This topic was modified 6 months ago by  joe.
    #27339

    joe
    Participant

    Every time, Zip file is downloaded successfully though.

    #27340

    You are using a very old version of Rewrite. Could you update to 2.0.12.Final (or even better 3.0.0.Alpha10) and test again?

    Don’t can confused by the “Alpha”. 3.0.0.Alpha10 should actually be more stable than 2.0.12.Final.

    #27341

    joe
    Participant

    I changed the version to
    <prettyFaces.version>3.0.0.Alpha10</prettyFaces.version>
    I had build time error:
    ————————————————————————

    Failed to read artifact descriptor for org.ocpsoft.rewrite:rewrite-config
    -prettyfaces:jar:3.0.0.Alpha10: Could not find artifact org.ocpsoft.rewrite:rewrite-parent:pom:3.0.0-SNAPSHOT –

    —————————————-

    I tried last version 3.0.0.Alpha6, build is fine but still having the same runtime exception:
    java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)
    at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120)
    at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.sendError(HttpRewriteWrappedResponse.jav
    a:467)
    at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:781)
    at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:411)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

    #27342

    Try adding this as the last line in your custom HttpOperation:

    Lifecycle.abort().perform(event, context);
    

    This basically tells Rewrite to abort processing and do NOT pass the request further down the filter chain.

    #27343

    joe
    Participant

    That works. Thanks Christian. That was important for our project as we want to reduce noise in logs.

    #27344

    Great! 🙂

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.