1.1 Setup using ANT
Installing ANT
Download and install ANT by following the installation guide for your particular operating system.
Once it is done, please ensure the ant command is added in the system path by checking with the command itself.
Example - Using ant command on a Linux OS to check if ANT is installed properly.
$ ant -version Apache Ant version 1.7.0 compiled on December 13 2006
Creating a Java project
With the ANT tool installed, the next step will be to create a Java project for the Java agent. This is done using the jcreate mzsh command. For more information regarding the jcreate command, see 2.2.10 jcreate.
Container deployments
If you are deploying on containers, please read the instructions here for AWS deployments /wiki/spaces/MD83/pages/5967616 and for private container deployments /wiki/spaces/MD83/pages/5967000
Creating a project on the platform server
Using the jcreate command, create a new Java project.
Example - Using jcreate to create a new Java project
$ mzsh mzadmin/dr jcreate /home/mzadmin/agent1 helloWorld
The jcreate command will create a java project named helloWorld in the agent1 directory.
If the development is to be done on a separate server from the platform server, the following additional steps are required to be performed.
The next step will be to compress the helloWorld directory into a compressed archive.
Example - Compressing the Java project directory using Zip.
$ cd /home/mzadmin/agent1 $ zip -r helloWorld.zip helloWorld/
After compressing the directory, copy and extract the zip file to a directory in server or machine that the development will be performed.
Example - Decompressing the Java project at the destination server.
$ mkdir agent1 $ cd agent1 $ mv /tmp/helloWorld.zip . $ unzip helloWorld.zip
Building a Java project
The following are steps to build the Java project successfully for the Java agent.
Go to the Java project directory and edit the ant.settings file.
Modify the file to include valid entries for host, port, username and password for the platform.
Example - ant.settings file.
ant.settings//----- Platform host settings ----- host=platformhost port=9000 username=mzadmin password=dr //----- Runtime settings ----- syncHttpAddress=http://${host}:${port}/javaagent/sync postHttpAddress=http://${host}:${port}/javaagent/post
The next step will be to update the project's libraries with the latest UDRs available with the following commands:
Example - Command to refresh the UDRs in the project library.
$ ant pull $ ant clean
This command will download all the necessary java jars to the project directory. This includes any changes done to it before hand.
Implementing a Java project
Once the Java project is set up and all libraries present, the implementation of the business logic can begin. Below will be an example of an implementation, where the java file HelloworldAgent.java will have env.debug("Hello World");
under the consume function block.
Example - Debugging a "Hello World" statement
package com.mediationzone.java_agent; import com.digitalroute.mz.java.agents.RealtimeAgent; import com.digitalroute.mz.java.agents.api.AgentEnv; import com.digitalroute.mz.java.agents.api.ConfigDefinition; import com.digitalroute.mz.java.agents.UDRInterface; import java.util.Map; public class HelloworldAgent implements RealtimeAgent { @Override public void configure(ConfigDefinition cfg) { cfg.defineOutput(byte[].class, UDRInterface.class); //cfg.defineOutput(Your_UDR.class); //cfg.defineOutput("routename", Your_UDR.class); } @Override public void deinitialize(AgentEnv env) throws Exception { } @Override public void init(AgentEnv env, Map<String,String> userdata) throws Exception { } @Override public void consume(UDRInterface input, AgentEnv env) throws Exception { // try { // env.debug(input); // // Your_UDR newUdr = env.createUDR(Your_UDR.class); // // Your_UDR udr = (Your_UDR) input; // } catch (Exception e) { // throw new RuntimeException(e); // } // env.debug("Hello World"); env.route(input); } @Override public void consume(byte[] input, AgentEnv env) throws Exception { env.debug(input); env.route(input); } @Override public Object getMIM(String mimName) { return null; } }
The code will generate a debug statement with the string "Hello World" and output it to the Workflow Monitor with the Debug option enabled.
For the example workflow and java code, refer to 9.47.5 Java Agent Example
For more information about the environment functions utilized by the Java agent, refer to 3. Java General Functions
External third party Java libraries could also be added and used by the Java configuration code. For the detailed steps, refer to 1.3 Adding External Third Party Java Libraries
Example of the Hello World debug statement for Workflow with Java agent.
Deploy a Java project
Once all changes to the codes are performed in the project directory, the changes are committed with the following command:
Example - Command to commit the changes to the java codes.
$ ant commit
With this command, the changes made in the java files will be committed and saved. The Java agent will now be able to select and execute the business logic contained within from the workflow. For more information on how to configure the Java agent, see 9.47.2 Java Agent Configuration.