Hi, my name is Leandro Takeda and I'm an Integration Developer at CGI, Portugal. I decided to create this document to share a simple Web Application which sends SOMA requests to do IBM DataPower via XML MGMT interface. I wasn’t sure about the title of this document, but I guess it fits the content.
The decision also to create this document comes from the needs to create this solution and to some difficult to find something similar on the internet. I follow the dilemma: If something is difficult or not found on the internet and you know it, please, share! Humans Knowledge Belongs to the World, right?
Those are the tools I used to create this solution:
- Eclipse Oxygen
- Java 1.8
- datapowerxmlmgmt-1.0.jar (This is a package containing all the DataPower actions from the DataPower Schema. This has been extracted using JAXB – You can find it in the GIT repo below).
- JSTL 1.2
- XBEAN0
- DOM4J 1.6.1
- Apache Tomcat v8.5
I will not enter the details on how to install or download each of them, however, if you have any questions, let me know.
- First, let´s create a Dynamic Web Project on Eclipse, you can go to File > New > Dynamic Web Project
- Let´s call it as DataPowerWebTool (Sorry, I´m not so creative).

- Now, click with the right button in the project and let´s create a new Servlet Java Class, let´s call it as GetCPUUsage. Go to New > Servlet. We will use the CPUUsage SOMA operation in this tutorial to use an example. You can put it in the package you want, I used the package “util”
- You will see a Java Servlet Class with the default methods included, GET and POST. Let´s only use POST method
- In the servlet, let´s add this line to get the value coming from the Web Page and also add, for now, a sysout, so we can print it and make sure it´s working:
String device = request.getParameter("device");
System.out.println(device);
Your method should be like this:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String device = request.getParameter("device");
System.out.println(device);
}
- Let's create a JSP file page now. Right click in the project with the right button and select: JSP. Go to File > New > JSP File. Let's call it as jsp
- This is the JSP used as example, it´s a pretty simple JSP with a form:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>DataPower Web Tool</title>
</head>
<body>
<form action="/DataPowerWebTool/GetCPUUsage" method="POST">
<input type="text" name="device"> <input type="submit"
name="submit" value="submit">
</form>
</body>
</html>
ATTENTION: See the the action URL, you should specify your project before, if you choose a different name.
- At this moment, if you inject any value in the web page and send, you should see something in the logs like below:


- Now, let´s put the 3 classes in your project, on the same Java package, “util”. The classes are java, CertificateManager.java, DPManagement.java, and HTTPSClient.java. Some of these classes I got from the internet and some I created, edited. I will not explain how these classes’ works, but you can check later in more time. There is no much secret about them and the names are auto-explained. The most import class here is the DPManagement.java because it´s specific for DataPower. The other ones are generic.
- We will modify our Servlet to adjust to our needs. Let´s add the 5 lines below:
DPManagement dp = new DPManagement();
ArrayList<String> listResult = new ArrayList<String>();
listResult = dp.getCPUUsage(device);
request.setAttribute("listResult", listResult);
request.getRequestDispatcher("/index.jsp").forward(request, response);
Explanation: In the first line, we are creating an instance for our DPManagement class. In the 2nd line, we are creating an ArrayList to save the results. In the 3rd we are calling the method from the DPManagement class. In the 4th we are setting the results as an attribute to send back to our JSP page. In the 5th line, we are sending the results back to our JSP page via getRequestDispatcher.
- You will see this in this line of the DPManagement.java:
getStatus.setClass1(StatusEnum.CPU_USAGE);
The operation used, in this case, CPU_USAGE. You will have a lot of ENUM TYPES here. You can choose the one you want from the list available. Those ENUMs comes from datapowerxmlmgmt-1.0.jar. You can find it in the GIT repository.
You will see also some auto explained method, like createSoapEnvelope, formatXML. I don't need to explain those, right?
- If you check in part of the code on DPManagement.java
try {
responseXml = invoke(soapEnvelope, false, listResult);
System.out.println(responseXml);
listResult.add(responseXml);
} catch (Exception e) {
e.printStackTrace();
listResult.add(e.getMessage());
}
You will see we are printing the response, so, you should see the results in the console.log
ATTENTION: In the same class we are hardcoding the username and password for the DataPower. You can change your code to store it in a file, or even pass as a parameter to the class. Do whatever you need:
private String invoke(String xml, boolean resp, ArrayList<String> listResult) {
HTTPSClient obj = null;
String responseXml = null;
try {
obj = new HTTPSClient(DATAPOWER_ADDRESS, 5550, "username","password");
obj.connect(true);
} catch (Exception e) {
listResult.add(e.getMessage());
}
responseXml = obj.sendMessage(xml);
obj.releaseConnection();
return formatXML(responseXml);
}
ATTENTION: Pay attention to the port, if you have a different port for your XML MGMT interface, you need to update the code here.
- See this working:
Console.log:

This is the web page:

- To have the result above. You can simply modify the index.jsp to show those results. Add JSTL to the .jsp.
- First add this time on the top of the JSP to include the JSTL:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
And print it to a simple textarea using JSTL:
<textarea rows="20" cols="80">
<c:out value="${listResult}"/>
</textarea>
- There are a lot of things you can do using this. You can get ObjectStatus. You can get details about your MPGW. You can get files from the DP You can get MEMORY DETAILS. Customized it to your needs. In some situations, you may need to manipulate the XML Response. You can do it using JAXB, read about it! Enjoy!
- Finally, you can find the code here: (https://github.com/letakeda/DataPowerWebTool) and leave a comment or drop me an email in case of any questions (letakeda@gmail.com). Thanks!