The client sends an XML request to invoke the stock query BTT operation. The code of the request XML is as follows:
<?xml version="1.0"?> <xml_request> <action>QueryStockOp</action> <data_formatter>stockFmt</data_formatter> <response_formatter>stockFmt</response_formatter> <data> <stockCtxData> <code>IBM</code> </stockCtxData> </data> </xml_request>
This XML request data structure is described in Defining the request data format.
The implementation of this operation is as follows:
package com.ibm.btt.poc.opstep; import com.ibm.btt.base.BTTServerOperation; public class QueryStockOp extends BTTServerOperation { @Override public void execute() throws Exception { String code = (String) getValueAt("code"); if("IBM".equals(code)){ setValueAt("price","100$"); } } }
The operation configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?> <QueryStockOp.xml> <operation id="QueryStockOp" context="stockCtx" implClass="com.ibm.btt.poc.opstep.QueryStockOp"> <refFormat name="stockFmt" refId="stockFmt" /> </operation> <kColl id="stockCtxData"> <field id="code" /> <field id="price" /> </kColl> <context id="stockCtx" type="op"> <refKColl refId="stockCtxData" /> </context> <fmtDef id="stockFmt"> <fXML dataName="stockCtxData"> <fString dataName="code" /> <fString dataName="price" /> </fXML> </fmtDef> </QueryStockOp.xml>
After sending the request to the server, you receive the response XML:
<?xml version="1.0"?> <xml_reply> <status>OK</status> <result> <stockCtxData> <code>IBM</code> <price>100$</price> </stockCtxData> </result> <sessionId>wmlCPMh5pLx9ZjpKx6P5iJU</sessionId> </xml_reply>
The client sends a JSON request to invoke the stock query BTT operation. The request JSON is as follows:
{"xml_request":{"response_formatter":"stockFmt","data":{"stockCtxData":{"code":"IBM"}},"action":"QueryStockOp","data_formatter":"stockFmt"}}
This JSON request data structure is described in Defining the request data format.
The implementation of this operation is the same as the one in XML Channel:
package com.ibm.btt.poc.opstep; import com.ibm.btt.base.BTTServerOperation; public class QueryStockOp extends BTTServerOperation { @Override public void execute() throws Exception { String code = (String) getValueAt("code"); if("IBM".equals(code)){ setValueAt("price","100$"); } } }
The operation configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?> <QueryStockOp.xml> <operation id="QueryStockOp" context="stockCtx" implClass="com.ibm.btt.poc.opstep.QueryStockOp"> <refFormat name="stockFmt" refId="stockFmt" /> </operation> <kColl id="stockCtxData"> <field id="code" /> <field id="price" /> </kColl> <context id="stockCtx" type="op"> <refKColl refId="stockCtxData" /> </context> <fJSON id="stockFmt"> <record dataName="stockCtxData"> <fString dataName="code" /> <fString dataName="price" /> </record> </fJSON> </QueryStockOp.xml>
After sending the request to the server, you receive the response JSON:
{"xml_reply":{"result":{"stockCtxData":{"code":"IBM","price":"100$"}},"status":"OK","sessionId":"wmlCPMh5pLx9ZjpKx6P5iJU"}}