congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
TagInjectionOutputStream
Code IndexAdd Tabnine to your IDE (free)

How to use
TagInjectionOutputStream
in
rocks.inspectit.agent.java.eum.instrumentation

Best Java code snippets using rocks.inspectit.agent.java.eum.instrumentation.TagInjectionOutputStream (Showing top 6 results out of 315)

origin: inspectIT/inspectIT

  @Override
  public Object answer(InvocationOnMock invocation) throws Throwable {
    TagInjectionOutputStream injectedStream = (TagInjectionOutputStream) invocation.getArguments()[1];
    injectedStream.proxyLinked(dummyStreamProxy, linker);
    return dummyStreamProxy;
  }
});
origin: inspectIT/inspectIT

/**
 * 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;
}
origin: inspectIT/inspectIT

@SuppressWarnings("unchecked")
@Test
public void testPlainTextNoInjection() throws IOException {
  ArgumentCaptor<TagInjectionOutputStream> streamCaptor = ArgumentCaptor.forClass(TagInjectionOutputStream.class);
  respWrapper.getOutputStream();
  verify(linker, times(1)).createProxy(any(Class.class), streamCaptor.capture(), any(ClassLoader.class));
  TagInjectionOutputStream stream = streamCaptor.getValue();
  byte[] bytes = NON_HTML_TEST_CASE_A.getBytes(CHARACTER_ENCODING);
  int pos = 0;
  while (pos < bytes.length) {
    stream.write(bytes, pos, Math.min(3, bytes.length - pos));
    pos += 3; // write 3 bytes at once
  }
  String result = new String(streamResult.toByteArray(), CHARACTER_ENCODING);
  assertThat(result, equalTo(NON_HTML_TEST_CASE_A));
}
origin: inspectIT/inspectIT

@SuppressWarnings("unchecked")
@Test
public void testInvalidMarkupNoInjection() throws IOException {
  ArgumentCaptor<TagInjectionOutputStream> streamCaptor = ArgumentCaptor.forClass(TagInjectionOutputStream.class);
  respWrapper.getOutputStream();
  verify(linker, times(1)).createProxy(any(Class.class), streamCaptor.capture(), any(ClassLoader.class));
  TagInjectionOutputStream stream = streamCaptor.getValue();
  byte[] bytes = NON_HTML_TEST_CASE_B.getBytes(CHARACTER_ENCODING);
  int pos = 0;
  while (pos < bytes.length) {
    stream.write(bytes, pos, Math.min(3, bytes.length - pos));
    pos += 3; // write 3 bytes at once
  }
  String result = new String(streamResult.toByteArray(), CHARACTER_ENCODING);
  assertThat(result, equalTo(NON_HTML_TEST_CASE_B));
}
origin: inspectIT/inspectIT

@SuppressWarnings("unchecked")
@Test
public void testBodyInjection() throws IOException {
  ArgumentCaptor<TagInjectionOutputStream> streamCaptor = ArgumentCaptor.forClass(TagInjectionOutputStream.class);
  respWrapper.getOutputStream();
  verify(linker, times(1)).createProxy(any(Class.class), streamCaptor.capture(), any(ClassLoader.class));
  TagInjectionOutputStream stream = streamCaptor.getValue();
  byte[] bytes = HTML_TEST_CASE_B.getBytes(CHARACTER_ENCODING);
  int pos = 0;
  while (pos < bytes.length) {
    stream.write(bytes, pos, Math.min(3, bytes.length - pos));
    pos += 3; // write 3 bytes at once
  }
  String result = new String(streamResult.toByteArray(), CHARACTER_ENCODING);
  assertThat(result, equalTo(HTML_TEST_CASE_B_REFERENCE));
}
origin: inspectIT/inspectIT

@SuppressWarnings("unchecked")
@Test
public void testHeadInjection() throws IOException {
  ArgumentCaptor<TagInjectionOutputStream> streamCaptor = ArgumentCaptor.forClass(TagInjectionOutputStream.class);
  respWrapper.getOutputStream();
  verify(linker, times(1)).createProxy(any(Class.class), streamCaptor.capture(), any(ClassLoader.class));
  TagInjectionOutputStream stream = streamCaptor.getValue();
  byte[] bytes = HTML_TEST_CASE_A.getBytes(CHARACTER_ENCODING);
  int pos = 0;
  while (pos < bytes.length) {
    stream.write(bytes, pos, Math.min(3, bytes.length - pos));
    pos += 3; // write 3 bytes at once
  }
  String result = new String(streamResult.toByteArray(), CHARACTER_ENCODING);
  assertThat(result, equalTo(HTML_TEST_CASE_A_REFERENCE));
}
rocks.inspectit.agent.java.eum.instrumentationTagInjectionOutputStream

Javadoc

A ServletOutputStream which injects the given tag on the fly into the head (or another appropriate) section of the document. Automatically detects non-html and then falls back to just piping the data through.

Most used methods

  • <init>
    Creates a tag injecting stream.
  • proxyLinked
  • setEncoding
    Sets the Character encoding used by the data. Only this way the stream is able to decode / encode bi
  • write

Popular in Java

  • Making http post requests using okhttp
  • findViewById (Activity)
  • getExternalFilesDir (Context)
  • getSystemService (Context)
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JTable (javax.swing)
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now