We have a default naming rule in BTT to define the data formatter and response formatter. If you do not specify them in the request, BTT uses csRequestFormat as data format and csReplyFormat as response format.
Following is an example of how to send a request to the server without specified formatter in XML Channel and JOSN Channel:
The client sends a 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> <stockCtxData> <code>IBM</code> </stockCtxData> </data> </xml_request>
The implementation of this operation is as the same as the one in the specified formatter request:
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="csRequestFormat" refId="stockFmt" /> <refFormat name="csReplyFormat" 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>
The response XML is as the same as the one in the specified formatter request:
<?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 JOSN request to invoke the stock query BTT operation. The code of the request JOSN is as follows:
{"xml_request":{"data":{"stockCtxData":{"code":"IBM"}},"action":"QueryStockOp"}}
The implementation of this operation is as the same as the one in the specified formatter request:
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="csRequestFormat" refId="stockFmt" /> <refFormat name="csReplyFormat" 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"}}