...
Code Block |
---|
|
CABR.registerHandler('SUBMIT', 'PAYMENTS_CONTAINER', function (config)
{
var fm = new cbx.form.FormManager(
{
formId : "PAYMENT_FORM"
});
var mData = fm.model.getModelData();
var paymenttxnData =
{
'ACC_NO' : mData.TXT_DBIT_AC_NO,
'ACC_NAME' : mData.TXT_DBIT_AC_NAME,
'BENE_ACC_NO' : mData.TXT_BEN_AC_NO,
'BENE_NAME' : mData.TXT_BEN_AC_NAME,
'TRANS_DATE' : mData.TRANS_DATE,
'TRANS_AMNT' : mData.TXT_TRANS_AMNT,
"INPUT_PRODUCT": "PAYMNT",
"INPUT_SUB_PRODUCT": "BKSIFT",
"INPUT_FUNCTION_CODE" : "PAYXFER",
"INPUT_ACTION" : "GET_TXN",
};
cbx.ajax(
{
params : params,
success : function (result, request)
{
alert("Record added successfully");
},
},
failure : function (result, request)
{
alert("Error, something went wrong");
}
});
}); |
2. Create a forward mapping in the forward mapping file to an action class that forwards the Ajax request to the server.
...
Code Block |
---|
|
try
{
ActionMapRegistry.setCustomInstanceIndexer(ClassicalActionMapIndexer.class);
ActionMapRegistry actionMapRegistry = ActionMapRegistry.getCustomInstance();
actionMapRegistry.register("coresvs-forward.mapping");
//Adding the mapping file in the startup servlet
actionMapRegistry.register("payment-forward.mapping");
}
catch (BaseException e)
{
LOGGER.error("Unable to start ActionMapRegistry", e);
} |
3. The given mapping file expects the PymtTxnAction action class to read the client request. Create the action class extending the Canvas's PortletAction class that validates the user entitlement and formats the request data as JSON request to the server:
Code Block |
---|
|
package com.intellectdesign.modelhouse;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.intellectdesign.canvas.action.PortletAction;
import com.intellectdesign.canvas.common.ReplyObject;
import com.intellectdesign.canvas.exceptions.action.OrbiActionException;
import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException;
import com.intellectdesign.canvas.login.sessions.SessionInfo;
import com.intellectdesign.canvas.web.config.ActionMap;
public class PymtTxnAction extends PortletAction
{
@Override
public ReplyObject executePortletActionUsing(String action, SessionInfo sessionInfo, ActionMap actionMap, Map requestParams, HttpServletRequest request) throws OrbiActionException
{
ReplyObject reply = null;
try
{
reply = executeHostRequest(sessionInfo, actionMap.getHostCode(), requestParams, request);
}
catch (ProcessingErrorException procExp)
{
throw new OrbiActionException("System Error:"+ procExp);
}
return reply;
}
} |
4. In the handler properties file (which is defined for the HANDLER_PROPERTIES_FILE key in System Preference Configurator), Map the handler class to the Host Code to handle all the requests from the host (defined in the forward mapping file).
...
Code Block |
---|
|
package com.intellectdesign.modelhouse;
import java.util.HashMap;
import java.util.Vector;
import com.intellectdesign.canvas.common.ExtReplyObject;
import com.intellectdesign.canvas.common.ReplyObject;
import com.intellectdesign.canvas.constants.util.TIConstants;
import com.intellectdesign.canvas.database.DatabaseException;
import com.intellectdesign.canvas.event.handler.IData;
import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException;
import com.intellectdesign.canvas.handler.SimpleRequestHandler;
import com.intellectdesign.modelhouse.txn.PaymentInstruction;
import com.intellectdesign.modelhouse.txn.TxnData;
public class PymtTxnRequestHandler extends SimpleRequestHandler
{
public ReplyObject processRequest(Vector obj) throws ProcessingErrorException
{
ReplyObject reply = new ExtReplyObject();
if (obj instanceof Vector)
{
Vector inputVector = (Vector) obj;
String userNo = (String) inputVector.get(TIConstants.USER_NO_INDEX_IN_VECTOR);
HashMap map = (HashMap) inputVector.get(inputVector.size() - 1);
map.put("USER_NO", userNo);
TxnData txnData = (TxnData) formatTxnData(map);
try
{
//Pass the transaction data to the instruction class
PaymentInstruction paymentInstruction = new PaymentInstruction();
paymentInstruction.insertTxnData(txnData);
HashMap successMap = new HashMap();
reply = constructSuccessReply(successMap);
}
catch (DatabaseException dbException)
{
throw new ProcessingErrorException("TXN0001", userNo);
}
return reply;
}
return reply;
}
private ExtReplyObject constructSuccessReply(HashMap respMap)
{
ExtReplyObject reply = new ExtReplyObject();
reply.headerMap = new HashMap();
reply.headerMap.put("REPLY_TYPE", "SUCCESS");
if (respMap != null)
{
reply.headerMap.put("JSON_MAP", respMap);
}
return reply;
}
protected IData formatTxnData(HashMap mapData)
{
TxnData txnData = new TxnData();
txnData.setAccNo((String) mapData.get("ACC_NO"));
txnData.setAccName((String) mapData.get("ACC_NAME"));
txnData.setAccCcy((String) mapData.get("BENE_ACC_NO"));
txnData.setAccName((String) mapData.get("BENE_NAME"));
txnData.setAccBranch((String) mapData.get("TRANS_DATE"));
txnData.setAccBranch((String) mapData.get("TRANS_AMNT"));
return txnData;
}
} |
...