Configure the Java agent
Supported for: Windows only
This task describes how to configure the Service Virtualization Java agent to virtualize a Java application.
There are two components required for Java virtualization:
- Java agent. The Service Virtualization Java agent listens for requests from your application under test.
-
Java instrumentator. Service Virtualization provides a Java instrumentator (HP.SV.JavaInstrumentator.jar). You download the instrumentator from inside the Service Virtualization application, and use an XML configuration file to define the classes and methods that you want to virtualize. The download includes the instrumentator, a sample XML configuration file, and a readme file.
Note: The Service Virtualization Java instrumentator supports OpenJDK and Oracle Java 5 or later. For the most up-to-date information on supported versions, refer to the Support Matrix.
How to configure the Java agent
-
Prerequisite:
If Java security is enabled for the application that is being virtualized, the Java Instrumentation Agent requires the following permissions:
permission java.io.FilePermission "<<ALL FILES>>", "read, write";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.org.apache.xerces.internal.jaxp";
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.org.apache.xerces.internal.dom";
permission java.io.SerializablePermission "enableSubclassImplementation";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.net.SocketPermission "*", "connect, resolve";
permission java.util.PropertyPermission "*", "read";
-
Configure the Service Virtualization Java agent settings:
From the main Service Virtualization menu, select Tools > Options. On the Agents Page, select Java Agent. For user interface details, see the Java agent settings.
-
Download and unzip the Service Virtualization Java instrumentator:
On the Agents page, select Download Java Application Instrumentator.
-
Create and configure an XML configuration file:
There is a sample file included with the Java instrumentator download.
You need to configure two parts of the XML configuration file:
- Managed Classes: Classes that the Java Instrumentation Agent takes care of. Managed classes can be virtualized, but do not need to be.
-
Service Virtualization Agent Endpoint: In the format http://<machine_name>:<listening_port>
where:
machine_name = the computer on which the Service Virtualization Java agent is located
listening_port = the port defined on the Java agent settings page.
Additional information on how to configure the file is included in the sample configuration file.
-
Configure virtualized classes in a new or existing virtual service:
When a class is being virtualized, it makes network calls to the Service Virtualization Server.
You can define virtualized classes in the following ways:
- When you create a new virtual service. For details, see Create a Virtual Service.
- Define or modify the classes for an existing virtual service. For details, see Service Properties Page.
-
Start your Java application with Service Virtualization instrumentation:
-
For the instrumentation of a generic Java application:
Run the Java application with parameter -javaagent:<path to HP.SV.JavaInstrumentator.jar>=<path to configuration xml file>.
For example:
java -javaagent:c:/sv/HP.SV.JavaInstrumentator.jar=c:/sv/config.xml -jar application.jar
-
For the instrumentation of a Java application deployed to an application server (AS):
Add the -javaagent parameter into the Java process that runs the AS. This can generally be done either by using settings in the Management Console of the AS, or by amending the start-up script that starts the AS. The start-up script typically includes variables such as JAVA_OPTION that define the Java parameters. Add the -javaagent parameter to the relevant variable.
The instrumentator processes everything in the AS (including the AS itself) and not only the application that you want to virtualize.
JBoss Application Server
If the HP.SV.JavaInstrumentator is used on JBoss Application Server 7.X or later (including WildFly versions), you must set the HP.SV.JavaInstrumentator as a global module. This is because HP.SV.JavaInstrumentator amends a bytecode of managed classes so that they call components within the HP.SV.JavaInstrumentator.
To set the HP.SV.JavaInstrumentator as a global module, specify the following command line arguments for the Java process that runs JBoss/Wildfly:
-javaagent:<path to instrumentator>=<path to configuration xml file>
-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Xbootclasspath/p:%JBOSS_HOME%\modules\system\layers\base\org\jboss\logmanager\main\jboss-logmanager-1.5.2.Final.jar
-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager,com.hp.sv.java,org.eclipse.persistence
The version of jboss-logmanager jar (in this case it was jboss-logmanager-1.5.2.Final.jar) can vary so make sure to use the correct version for your server.
For example, on a Windows machine you can add these parameters by amending the JBoss startup script located at
<JBoss Home Folder>/bin/standalone.cmd
.On a Linux system you can add these parameters by amending the
<JBoss Home Folder>/bin/standalone.sh
.These are only examples, and may be specified differently in your environment.
-
See also: