/** * Lets InspectIT optionally instrument the given response by wrapping it. * * @param httpRequestObj * the request (an instance of javax.servlet.ServletRequest) * @param httpResponseObj * the response object (an instance of javax.servlet.ServletResponse) * @return the new response object to use, or the original one if it was not instrumented. */ public Object instrumentResponse(Object httpRequestObj, Object httpResponseObj) { try { if (configurationValid && WHttpServletResponse.isInstance(httpResponseObj)) { if (!linker.isProxyInstance(httpResponseObj, TagInjectionResponseWrapper.class)) { ClassLoader cl = httpResponseObj.getClass().getClassLoader(); TagInjectionResponseWrapper wrap = new TagInjectionResponseWrapper(httpRequestObj, httpResponseObj, tracer, scriptTags); Object proxy = linker.createProxy(TagInjectionResponseWrapper.class, wrap, cl); if (proxy == null) { return httpResponseObj; } else { return proxy; } } } } catch (Throwable e) { // NOPMD LOG.error("Error instrumenting response object.", e); } return httpResponseObj; // No instrumentation }
@BeforeMethod public void init() { printerResult.getBuffer().setLength(0); respWrapper = new TagInjectionResponseWrapper(dummyRequest, dummyResponse, tracer, tagPrinter); respWrapper.proxyLinked(dummyProxy, linker); }
@SuppressWarnings("unchecked") @BeforeMethod public void init() { when(linker.isProxyInstance(any(Object.class), any(Class.class))).thenReturn(false); when(linker.createProxy(any(Class.class), any(TagInjectionOutputStream.class), any(ClassLoader.class))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { TagInjectionOutputStream injectedStream = (TagInjectionOutputStream) invocation.getArguments()[1]; injectedStream.proxyLinked(dummyStreamProxy, linker); return dummyStreamProxy; } }); streamResult.reset(); respWrapper = new TagInjectionResponseWrapper(dummyRequest, dummyResponse, tracer, tagPrinter); respWrapper.proxyLinked(dummyProxy, linker); }