Knowledge Base > Automation Engine and Target Systems > Java EE/JMX > Send a SOAP Message using an MBean

Sending an SOAP Message with an MBean

Below is an example for an SOAP message which polls stock prices.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getQuote soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="urn:xmethods-delayed-quotes">
<symbol xsi:type="xsd:string">IBM</symbol>
</ns1:getQuote></soapenv:Body>
</soapenv:Envelope>

The following SOAP action should be used to send the SOAP message: "urn:xmethods-delayed-quotes#getQuote".  

URL of the webservice: http://services.xmethods.net/soap

An MBean can be used to send this SOAP message. This MBean requires at least Java version 5. Add  the MBean to the agent's classpath:

  1. Copy the file soapmbean.jar into the folder of the JMX agent.
  2. Start the JMX agent with the file soapmbean.jar in the classpath.
    java -cp soapmbean.jar;ucxjjmx.jar com/uc4/ex/jmx/UCXJMX

Create a JMX job and insert the following line in the Process tab:

JMX_CREATE_MBEAN EXISTS="IGNORE",CLASSNAME="com.uc4.ex.jmx.soap.SOAP",NAME="uc4.com:name=SOAP"

Start the job. The MBean "SOAP" is now listed in the MBean Browser.

In the next step, determine the JCL for using the SOAP MBean:

JMX_CREATE_MBEAN EXISTS="IGNORE",CLASSNAME="com.uc4.ex.jmx.soap.SOAP",NAME="uc4.com:name=SOAP"
JMX_COMPOSITE_ADD KEY="1",VALUE='<?xml version="1.0" encoding="UTF-8"?>',NAME="s"
JMX_COMPOSITE_ADD KEY="2",VALUE='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="3",VALUE='xmlns:xsd="http://www.w3.org/2001/XMLSchema" ',NAME="s"
JMX_COMPOSITE_ADD KEY="4",VALUE='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',NAME="s"
JMX_COMPOSITE_ADD KEY="5",VALUE="<soapenv:Body><ns1:getQuote ",NAME="s"
JMX_COMPOSITE_ADD KEY="6",VALUE='soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="7",VALUE='xmlns:ns1="urn:xmethods-delayed-quotes">',NAME="s"
JMX_COMPOSITE_ADD KEY="8",VALUE='<symbol xsi:type="xsd:string">IBM</symbol>',NAME="s"
JMX_COMPOSITE_ADD KEY="9",VALUE="</ns1:getQuote></soapenv:Body></soapenv:Envelope>",NAME="s"
JMX_INVOKE OPERATIONNAME="sendSOAP",MBEAN="uc4.com:name=SOAP",PARAMS='s,"urn:xmethods-delayed-quotes#getQuote",http://services.xmethods.net/soap'

The first line ensures that the MBean exists or loads it if necessary. The statements JMX_COMPOSITE_ADD insert the SOAP message line by line with the parameter KEY= containing the line number. After the SOAP message has been composed, it is assigned to the operation "sendSOAP" (JMX_INVOKE) as its first parameter. The second parameter contains the SOAP action, and the third one  the URL to which the SOAP request should be sent.

Execute the job. The job report shows the response message.

An XPath expression can be used to read an individual value. Do so by inserting a new script line using the script element JMX_COMPOSITE_ADD with the statement "XPATH" for KEY= and the searched value for VALUE= (see second script line). The script now looks as shown below:

JMX_CREATE_MBEAN EXISTS="IGNORE",CLASSNAME="com.uc4.ex.jmx.soap.SOAP",NAME="uc4.com:name=SOAP"
JMX_COMPOSITE_ADD KEY="XPATH",VALUE="//Result",NAME="s"
JMX_COMPOSITE_ADD KEY="1",VALUE='<?xml version="1.0" encoding="UTF-8"?>',NAME="s"
JMX_COMPOSITE_ADD KEY="2",VALUE='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="3",VALUE='xmlns:xsd="http://www.w3.org/2001/XMLSchema" ',NAME="s"
JMX_COMPOSITE_ADD KEY="4",VALUE='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',NAME="s"
JMX_COMPOSITE_ADD KEY="5",VALUE="<soapenv:Body><ns1:getQuote ",NAME="s"
JMX_COMPOSITE_ADD KEY="6",VALUE='soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="7",VALUE='xmlns:ns1="urn:xmethods-delayed-quotes">',NAME="s"
JMX_COMPOSITE_ADD KEY="8",VALUE='<symbol xsi:type="xsd:string">IBM</symbol>',NAME="s"
JMX_COMPOSITE_ADD KEY="9",VALUE="</ns1:getQuote></soapenv:Body></soapenv:Envelope>",NAME="s"
JMX_INVOKE OPERATIONNAME="sendSOAP",MBEAN="uc4.com:name=SOAP",PARAMS='s,"urn:xmethods-delayed-quotes#getQuote",http://services.xmethods.net/soap'

Based on the sample script, the job report now shows a value.

Parts of the SOAP message can also be supplied with values via script variables. The following example reads a value via a :READ mask:

Pre-Process tab:

:READ &SYMBOL#,"IBM,SAP,ORCL","Please choose one","IBM"

Process tab:

The script variable &SYMBOL# is used in the 10th line:

JMX_CREATE_MBEAN EXISTS="IGNORE",CLASSNAME="com.uc4.ex.jmx.soap.SOAP",NAME="uc4.com:name=SOAP"
JMX_COMPOSITE_ADD KEY="XPATH",VALUE="//Result",NAME="s"
JMX_COMPOSITE_ADD KEY="1",VALUE='<?xml version="1.0" encoding="UTF-8"?>',NAME="s"
JMX_COMPOSITE_ADD KEY="2",VALUE='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="3",VALUE='xmlns:xsd="http://www.w3.org/2001/XMLSchema" ',NAME="s"
JMX_COMPOSITE_ADD KEY="4",VALUE='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',NAME="s"
JMX_COMPOSITE_ADD KEY="5",VALUE="<soapenv:Body><ns1:getQuote ",NAME="s"
JMX_COMPOSITE_ADD KEY="6",VALUE='soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ',NAME="s"
JMX_COMPOSITE_ADD KEY="7",VALUE='xmlns:ns1="urn:xmethods-delayed-quotes">',NAME="s"
JMX_COMPOSITE_ADD KEY="8",VALUE='<symbol xsi:type="xsd:string">&SYMBOL#</symbol>',NAME="s"
JMX_COMPOSITE_ADD KEY="9",VALUE="</ns1:getQuote></soapenv:Body></soapenv:Envelope>",NAME="s"
JMX_INVOKE OPERATIONNAME="sendSOAP",MBEAN="uc4.com:name=SOAP",PARAMS='s,"urn:xmethods-delayed-quotes#getQuote",http://services.xmethods.net/soap'