This page describes how to instrument a browser application through assisted injection of the JavaScript Agent. Assisted injection is when your server-side application injects the JavaScript Agent into your browser application. You can configure your business applications to inject the JavaScript Agent into your browser applications.

Types of Assisted Injection

You can perform assisted injection with rules or through attributes. This table summarizes the platforms supported for each type of assisted injection and the process for performing the assisted injection.

Type of Assisted Injection

Supported Platforms

Description

Injection RulesJava

Type of assisted injection uses rules to configure which Java classes should be intercepted.

You create the injection rules in the User Experience App Integration Panel of the Controller UI for the business application that will inject the JavaScript Agent.

Attribute InjectionJava, ASP.NET

Type of assisted injection relies on templates that tell the app agent where to inject information.

You enable attribute injection in the User Experience App Integration Panel of the Controller UI for the business application that will inject the JavaScript Agent.

Additionally, you add code snippets in the page templates that determine where the JavaScript Agent is injected.

Injection Rules (Java Only)

To have your server-side application use assisted injection of the JavaScript Agent using injection rules, you define rules to configure: 

  • The Java classes and methods that should be intercepted 
  • The Java writer object and method to use to add the agent to the response object 

Assisted injection using rules is available for Java frameworks only.  

Access the User Experience App Integration Panel

  1. From the Applications page, open the business application that you want to automatically inject the JavaScript Agent into your browser application.
  2. From the left navigation bar, select Configuration.
  3. Click User Experience App Integration.

Create JavaScript Injection Rules

  1. In the JavaScript Agent Injection tab, select a browser application from the Inject the JavaScript Agent configured for this Browser App dropdown.
  2. From the Configure JavaScript Injection tab, expand Create Injection Rules.
  3. Click the + icon to open the Create Manual Injection Rule dialog.
  4. From the Where to Inject JavaScript tab:
    1.  In the Name field, enter a name for the rule. 
    2. Check Enable.
    3. In the Class and Method to intercept section, define match conditions for the class and method that write to the output stream in your application. This is the class that server-side agent intercepts for injection.
    4. If the write method is overloaded:
      1. Check the Is this Method Overloaded? checkbox.

      2. Click Add Parameter.
      3. Add the parameters that define the method.
    1. In the Pointer to the writer section: 
      1. Select how to obtain a reference to the writer object using either the selected method with a configured number of parameters, return value, or invoked object.
      2. Specify a getter chain.
    2. In the Injection options section, specify:
      • the output stream write method the server-side agent should use to inject the JavaScript Agent
      • when the injection should occur: when the method begins or when the method ends
      • which part of the script should be injected: the header or the footer
      • optional prefix to output before writing the header or footer, such as <DOCTYPE. . . >
  5. Click Create Injection Rule.

Attribute Injection

To have your server-side application use assisted injection of the JavaScript Agent using attribute injection, you: 

  • Enable attribute injection
  • Copy code snippets into your page template 

Only Servlet containers supported assisted injection.

Access the User Experience App Integration Panel

  1. From the Applications page, open the business application that you want to automatically inject the JavaScript Agent into your browser application.
  2. From the left navigation bar, select Configuration.
  3. Click User Experience App Integration.

Access the JavaScript Injection Configuration Panel

  1. From the User Experience App Integration page, click the JavaScript Agent Injection tab.
  2. In the JavaScript Agent Injection tab, select a browser application from the Inject the JavaScript Agent configured for this Browser App dropdown.

Copy Code Snippets into Your Page Template

These examples show code snippets that you can copy directly into your page templates or into other pages. These code snippets direct the app agent where to inject information. The header value must be injected at the very top of the <head> section and the footer value must be added at the very end of the code creating the page.  

If you have already injected the header portion of the agent using manual injection, you can use these code snippets to automatically inject the footer data portion only. In this case, add only the JS_FOOTER values shown in the sections below.

JSF

<h:outputText rendered="#{AppDynamics_JS_HEADER != null}" value='#{request.getAttribute("AppDynamics_JS_HEADER")}' escape="false"/>
<h:outputText rendered="#{AppDynamics_JS_FOOTER != null}" value='#{request.getAttribute("AppDynamics_JS_FOOTER")}' escape="false"/>
CODE

JSP

<% if (request.getAttribute("AppDynamics_JS_HEADER") != null) { %> <%=request.getAttribute("AppDynamics_JS_HEADER")%> <% } %>
<% if (request.getAttribute("AppDynamics_JS_FOOTER") != null) { %> <%=request.getAttribute("AppDynamics_JS_FOOTER")%> <% } %>
CODE

Servlet

if (request.getAttribute("AppDynamics_JS_HEADER") != null)
{
    out.write(request.getAttribute("AppDynamics_JS_HEADER".toString());
}
if (request.getAttribute("AppDynamics_JS_FOOTER") != null)
{
    out.write(request.getAttribute("AppDynamics_JS_FOOTER").toString());
}
CODE

Groovy

<g:if test="${AppDynamics_JS_HEADER}">
    ${AppDynamics_JS_HEADER}
</g:if>

<g:if test="${AppDynamics_JS_FOOTER}">
    ${AppDynamics_JS_FOOTER}
</g:if>
CODE

Velocity Template

#if ($AppDynamics_JS_HEADER)
    $AppDynamics_JS_HEADER
#end
#if ($AppDynamics_JS_FOOTER)
    $AppDynamics_JS_FOOTER
#end
CODE

ASP.NET C#

<% if (Context.Items.Contains("AppDynamics_JS_HEADER"))
    Response.Write(Context.Items["AppDynamics_JS_HEADER"]); %>
<% if (Context.Items.Contains("AppDynamics_JS_FOOTER"))
    Response.Write(Context.Items["AppDynamics_JS_FOOTER"]); %>
CODE

MVC Razor

@if(HttpContext.Current.Items.Contains("AppDynamics_JS_HEADER")) 
{ @Html.Raw((string)HttpContext.Current.Items["AppDynamics_JS_HEADER"]) }
@if(HttpContext.Current.Items.Contains("AppDynamics_JS_FOOTER") )
{ @Html.Raw(HttpContext.Current.Items["AppDynamics_JS_FOOTER"].ToString()) }
CODE