Java Notes and Examples

The following sections apply to getter chains used in Java Agent configurations.

Values Passed in a Getter Chain

The value passed in a getter chain is always a string unless cast to another type.

The following cast types are supported:

  • int
  • float
  • bool (the primitive Boolean value)
  • boolean (a boxed boolean value; i.e. an object type that wraps a boolean)
  • long
  • object

The following section shows examples of how to refer to the types in parameters to getter chain methods. Notice that letter case is not important for the names of the types. Type casting is performed in a case-insensitive manner.

Java Getter Chain Examples

  • Getter chain with integer parameters in the substring method using the forward slash as the type separator:

    getAddress(appdynamics, sf).substring(int/0, int/10)
  • Getter chain with various non-string parameter types:

    getAddress(appdynamics, sf).myMethod(float/0.2, boolean/true, boolean/false, int/5)
  • Getter chain with forward slash escaped; escape character needed here for the string parameter:

    getUrl().split(\/) # node slash is escaped by a backward slash
  • Getter chain with an array element:

    getUrl().split(\/).[4]
  • Getter chains that return Hashmap values:

    get(object/myvalue).substring(int/0,int/10) 
    get(object/ACTION)
  • Getter chain with multiple array elements separated by commas:

    getUrl().split(\/).[1,3]
  • Getter chain retrieves property values, such as the length of an array:

    getUrl().split(\.).length
  • Getter chain using backslash to escape the dot in the string parameter;the call is getParam (a.b.c).

    getAddress.getParam(a\.b\.c\.)
  • In the following getter chain, the first dot requires an escape character because it is in a string method parameter (inside the parentheses). The second dot does not require an escape character because it is not in a method parameter (it is outside the parentheses).

    getName(suze\.smith).getClass().getSimpleName()

The following getter chain is from a transaction splitting rule on URIs that use a semicolon as a delimiter.

getRequestURI().split(\/).[2].split(;).[0]

The call gets the URI using getRequestURI() and then splits it using the escaped forward slash. From the resulting array, it takes the third entry (as the split treats the first slash as a separator) and inserts what before the slash (in this case, nothing) into the first entry. Then it splits this result using the semicolon, getting the first entry of the resulting array, which in this case contains the API name. For example, given the following URI:

/my-webapp/xyz;jsessionid=BE7F31CC0235C796BF8C6DF3766A1D00?act=Add&uid=c42ab7ad-48a7-4353-bb11-0dfeabb798b5

The getter chain splits on the API name, so the resulting split transactions are "API.abc", "API.xyz" and so on.

Tip: When using string.split(), remember that it takes a regex and you have to escape any special regex characters.

For example, if you want to split on the left square bracket ([):

Java syntax: split("\\[") Getter chain syntax: split(\\\\[)
Note: A Vertical Bar or Pipe (|) is a reserved character in Getter strings. For methods with a regular expression parameter, use Unicode as an alternative.

For example:

split(string/\\u007C).[0] // return the first element of an string split by a Vertical Bar.

Blocklisted Classes or Packages and Methods of the Java Getter Chain

Certain packages and classes have been blocklisted from being accessed within getter chains.

The following methods and classes or packages have been blocklisted by the Java Agent for Getter Chains:

Methods:

  • getClassLoader
  • loadClass
  • invoke

Classes or packages:

  • reflect
  • nio.file
  • ClassLoader
  • io.File
  • io.Socket
  • net.Socket
  • ProcessBuilder
  • Runtime