/** * Proxy for {@link javax.servlet.ServletResponse#getWriter()}. * * @return the instrumented writer * @throws IOException * if an exception getting the original writer occurs. */ @ProxyMethod public PrintWriter getWriter() throws IOException { commitHeaderData(); if (wrappedWriter == null) { PrintWriter originalWriter = wrappedResponse.getWriter(); // avoid rewrapping or unnecessary wrapping if (isNonHtmlContentTypeSet() || (originalWriter instanceof TagInjectionPrintWriter)) { wrappedWriter = originalWriter; } else { wrappedWriter = new TagInjectionPrintWriter(originalWriter, tagToInject.printTags()); } } return wrappedWriter; }
/** * Proxy for {@link javax.servlet.ServletResponse#getOutputStream()}. * * @return the instrumented stream * @throws IOException * if an exception getting the original stream occurs. */ @ProxyMethod(returnType = "javax.servlet.ServletOutputStream") public OutputStream getOutputStream() throws IOException { commitHeaderData(); if (wrappedStream == null) { OutputStream originalStream = wrappedResponse.getOutputStream(); // avoid rewrapping or unnecessary wrapping if (isNonHtmlContentTypeSet() || linker.isProxyInstance(originalStream, TagInjectionOutputStream.class)) { wrappedStream = originalStream; } else { TagInjectionOutputStream resultStr = new TagInjectionOutputStream(originalStream, tagToInject.printTags()); resultStr.setEncoding(wrappedResponse.getCharacterEncoding()); ClassLoader cl = wrappedResponse.getWrappedElement().getClass().getClassLoader(); wrappedStream = (OutputStream) linker.createProxy(TagInjectionOutputStream.class, resultStr, cl); if (wrappedStream == null) { // fallback to the normal stream if it can not be linked wrappedStream = originalStream; } } } return wrappedStream; }