|
21 | 21 | import javax.servlet.http.HttpServletResponse; |
22 | 22 |
|
23 | 23 | import org.ocpsoft.rewrite.context.EvaluationContext; |
24 | | -import org.ocpsoft.rewrite.servlet.config.response.ResponseInterceptor; |
| 24 | +import org.ocpsoft.rewrite.servlet.config.response.ResponseContentInterceptor; |
| 25 | +import org.ocpsoft.rewrite.servlet.config.response.ResponseStreamWrapper; |
25 | 26 | import org.ocpsoft.rewrite.servlet.http.event.HttpServletRewrite; |
26 | 27 | import org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse; |
27 | 28 |
|
|
33 | 34 | public abstract class Response extends HttpOperation |
34 | 35 | { |
35 | 36 | /** |
36 | | - * Add the given {@link ResponseInterceptor} instances to the current {@link ServletResponse}. This will activate response |
37 | | - * buffering on the current {@link ServletRequest} - meaning that generated output will not be sent to the client |
38 | | - * until the entire request has completed and all registered {@link ResponseInterceptor} instances have been executed. |
| 37 | + * Add the given {@link ResponseContentInterceptor} instances to the current {@link ServletResponse}. This will |
| 38 | + * activate response buffering on the current {@link ServletRequest} - meaning that generated output will not be sent |
| 39 | + * to the client until the entire request has completed and all registered {@link ResponseContentInterceptor} |
| 40 | + * instances have been executed. |
39 | 41 | * |
40 | | - * @param bufferedResponseToLowercase2 |
| 42 | + * <p> |
| 43 | + * <b>WARNING:</b> This will cause the ENTIRE response to be buffered in memory, which may cause performance issues |
| 44 | + * on larger responses. Make sure you know what you are doing! If it is possible to do the necessary operations using |
| 45 | + * a {@link ResponseStreamWrapper} instead, you should probably consider doing so to avoid memory overhead. |
41 | 46 | * |
42 | 47 | * @throws IllegalStateException When output has already been written to the client. |
43 | 48 | */ |
44 | | - public static Response withOutputInterceptedBy(final ResponseInterceptor... buffers) throws IllegalStateException |
| 49 | + public static Response withOutputInterceptedBy(final ResponseContentInterceptor... buffers) |
| 50 | + throws IllegalStateException |
45 | 51 | { |
46 | 52 | return new Response() { |
47 | 53 | @Override |
48 | 54 | public void performHttp(HttpServletRewrite event, EvaluationContext context) |
49 | 55 | { |
50 | | - for (ResponseInterceptor buffer : buffers) { |
51 | | - HttpRewriteWrappedResponse.getInstance(event.getRequest()).addBufferStage(buffer); |
| 56 | + for (ResponseContentInterceptor buffer : buffers) { |
| 57 | + HttpRewriteWrappedResponse.getInstance(event.getRequest()).addContentInterceptor(buffer); |
| 58 | + } |
| 59 | + } |
| 60 | + }; |
| 61 | + } |
| 62 | + |
| 63 | + public static Response withOutputStreamWrappedBy(final ResponseStreamWrapper... wrappers) |
| 64 | + throws IllegalStateException |
| 65 | + { |
| 66 | + return new Response() { |
| 67 | + @Override |
| 68 | + public void performHttp(HttpServletRewrite event, EvaluationContext context) |
| 69 | + { |
| 70 | + for (ResponseStreamWrapper wrapper : wrappers) { |
| 71 | + HttpRewriteWrappedResponse.getInstance(event.getRequest()).addStreamWrapper(wrapper); |
52 | 72 | } |
53 | 73 | } |
54 | 74 | }; |
|
0 commit comments