AppDynamics lets you split servlet custom match rules according to the request payload. For each of these examples, you must create a servlet custom match rule and enable the URI option on the Rule Configuration tab.

Split by POJO Method Call

Using a Java method to name a transaction is useful when:

  • You might not have a clear URI pattern, or
  • You are using an XML/JSON framework not otherwise supported

For example, consider the processOrder() method in the doPost() method of the servlet at the following URL: http://acmeonline.com/store.  

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
   //process the data from the sevlet request and get the orderType and the items
   processOrder(orderType,item)
   ...
}
public void processOrder(String orderType,String item) {
   //process order
}
CODE

You want to derive transaction naming from the first parameter to the processOrder() method, orderType

  1. On the Rule Configuration tab for the custom match rule, enable the Split Transactions using the XML/JSON payload or Java method invocation.
  2. Select POJO Method Call as the splitting mechanism. 
  3. For the method, choose the processOrder, and specify the parameter to use by numeric position in the parameter (0 index). The following screenshot displays the configuration of a custom match rule which will name all the qualifying requests into a Store.order.creditcard transaction:
    Split Transactions Using Payload

In addition to the parameter, you can also specify either the return type or a recursive getter chain on the object to name the transaction. For example, if the method parameter points to a complex object like PurchaseOrder, you can use something like getOrderDetails().getType() to correctly name the transaction.

Split Transaction by JSP Name

You can identify transactions by JSP name, as follows: 

  1. On the Rule Configuration tab, enable the Split Transactions using the XML/JSON payload or Java method invocation.
  2. Select POJO Method Call as the splitting mechanism. 
  3. Set the name of the class to com.sun.faces.application.ViewHandlerImpl.
  4. Set the name of the method to renderView().
  5. Set the argument index to 1.
  6. Define the Method Call Chain or getter as getViewId(). The agent appends the value to the name of the transaction as follows: <Name of the Custom Rule>.<path to jsp>.

You can later rename these business transactions to a more user-friendly name if you like.

Split Transactions on XPath Expression

You can access values in an XML payload for business transaction naming or splitting using an XPath expression. Consider the following example from an Ecommerce order transaction where the XML represents an order for three items. The order uses credit card processing, which is the distinguishing element for this body:

<acme>
   <order>
      <type>creditcard</type>
      <item>Item1</item> 
      <item>Item2</item>
      <item>Item3</item>
   </order>
</acme>
CODE

The URL is:

http://acmeonline.com/store


The doPost() method of the Servlet is:

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
   DocumentBuilderFactory docFactory =
   DocumentBuilderFactory.newInstance();
   DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
   Document doc = docBuilder.parse(req.getInputStream());
   Element  element = doc.getDocumentElement();
   //read the type of order
   //read all the items
   processOrder(orderType,items)
   ...
}
CODE


Imagine you want to differentiate "Order" transactions based upon the type of order. You can use the XPath expression //order/type on this XML payload, which in this example evaluates to creditcard.

  1. On the Rule Configuration tab, click Split transactions using XML/JSON Payload or a Java method invocation.
  2. Choose  XPath Expressions for the Split Mechanism.
  3. Enter the XPath expression that points to the value of the XML element to use for naming. In this example, //order/type

The agent appends the value of the XPath expression to the name of the business transaction, for example, Store.order.creditcard. Even though the agent doesn't name the transaction until after XML parsing, AppDynamics measures the duration of the business transaction to include the execution of the doPost() method. 

You can use one or more XPath expressions to chain the names generated for the Business Transaction.

You can specify whether the request results in transaction splitting when the expression does not evaluate to a value.

Split Transactions on Java XML Binding

You can identify transactions for Java XML data binding frameworks for these types of frameworks:

  • Castor
  • JAXB
  • JibX
  • XMLBeans
  • XStream

In the following example, the posted XML is unmarshalled to the PurchaseOrderDocument object, and the getOrderType() method should be used to identify the type of the order:

<acme>   
   <order>     
     <type>creditcard</type>         
      <item>Item1</item>
      <item>Item2</item>        
      <item>Item3</item>  
   </order>
</acme>
CODE

The following snippet shows the doPost() method for the Servlet:

 

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
   PurchaseOrderDocument poDoc = PurchaseOrderDocument.Factory.parse(po);
   PurchaseOrder po = poDoc.getPurchaseOrder();
   String orderType = po.getOrderType();

   //read all the items
   processOrder(orderType,items)
   ...
}
CODE

To split the transaction based upon the XML Binding:

  1. On the Rule Configuration tab, check Split transactions using XML/JSON Payload or a Java method invocation
  2. Select Java XML Binding as the split mechanism.
  3. Enter these values for the match criteria:  
    • Unmarshaled Class Name: PurchaseOrderDocument
    • Method name: getOrderType()

The agent identifies the business transaction for this example as Store.order.creditcard:

This custom rule ensures that the Java agent intercepts the method in XMLBeans (which unmarshalls XML to Java objects). If the name of the transaction is not on a first level getter on the unmarshalled object, you can also use a recursive getter chain such as getOrderType().getOrder() to get the name.

Although the transaction name is not obtained until the XML is unmarshalled, the response time for the transaction is calculated from the doGet() method invocation.

Split Transactions on JSON Payload

You can access JSON payload for transaction identification purposes using the method where the Servlet unmarshalls the payload.

For example, the following JSON payload posts an order for an item car and uses creditcard for processing the order. The URL is http://acmeonline.com/store:

order :{
  type:creditcard,
  id:123,
  name:Car,
  price:23
}}
CODE

The following code snippet shows the doPost method of the Servlet:

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
   //create JSONObject from servlet input stream
   String orderType = jsonObject.get("type");
   //read the item for the order 
   processOrder(orderType,item)
   ...
}
CODE

After the application unmarshalls the posted JSON payload to the JSON object, the type key is available to identify the type of the order. In this case, this key uniquely identifies the business transaction.

To use the JSON payload for transaction identification you must set the enable-json-bci-rules node property to true on each node to enable this rule. To configure the rule:

  1. On the Rule Configuration tab, check Split transactions using XML/JSON Payload or a Java method invocation
  2. For the JSON object key, enter the name of the JSON object. For example, type.

The agent automatically intercepts the JSONObject.get("$JSON_Object_Key") method to name the transaction. Although the agent doesn't obtain the transaction name until the JSON object is unmarshalled, the response time for the transaction will be calculated from the doGet() method.