changed the errorMsg to return the whole response body in case of any unknown json message from server in TransactionExecutor.kt

This commit is contained in:
Md Asif 2024-09-25 14:33:17 +05:30
parent 66dde20601
commit 8046dd0e62
7 changed files with 54 additions and 39 deletions

View File

@ -28,9 +28,9 @@ dependencies {
implementation("io.ktor:ktor-server-netty-jvm") implementation("io.ktor:ktor-server-netty-jvm")
implementation("ch.qos.logback:logback-classic:$logback_version") implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0") implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0")
implementation("org.json:json:20240303")
implementation("com.squareup.okhttp3:okhttp:4.12.0") implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("redis.clients:jedis:5.1.2")
implementation("org.slf4j:slf4j-api:2.0.16") implementation("org.slf4j:slf4j-api:2.0.16")
testImplementation("io.ktor:ktor-server-test-host-jvm") testImplementation("io.ktor:ktor-server-test-host-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")

View File

@ -6,7 +6,7 @@ import io.ktor.server.netty.*
import net.ipksindia.plugins.* import net.ipksindia.plugins.*
fun main() { fun main() {
embeddedServer(Netty, port = 8082, host = "0.0.0.0", module = Application::module) embeddedServer(Netty, port = 8083, host = "0.0.0.0", module = Application::module)
.start(wait = true) .start(wait = true)
} }

View File

@ -11,11 +11,11 @@ class NeftRequestProcessor {
companion object { companion object {
private val logger: Logger = LoggerFactory.getLogger(NeftRequestProcessor::class.java) private val logger: Logger = LoggerFactory.getLogger(NeftRequestProcessor::class.java)
private val migratedDCCBCodes = listOf("0003","0015", "0016") private val migratedDCCBCodes = listOf("0003","0015")
val bankDccbToSftpMap = mutableMapOf<String, String>( val bankDccbToSftpMap = mutableMapOf<String, String>(
"0015" to "0005", //Tamluk "0015" to "0005", //Tamluk
"0003" to "0021", //Balageria "0003" to "0021", //Balageria
"0016" to "0001", //WBSCB // "0016" to "0001", //WBSCB
) )
fun process(transactionNumber: String): Pair<String, String>? { fun process(transactionNumber: String): Pair<String, String>? {
@ -39,7 +39,9 @@ class NeftRequestProcessor {
logger.error("TXN: #{} FAILED REASON: Teller not found", transactionNumber) logger.error("TXN: #{} FAILED REASON: Teller not found", transactionNumber)
return null return null
} }
val transactionPair = TransactionFactory(outwardTransaction, makerTeller).createTransactionPair() val transactionPair = TransactionFactory(outwardTransaction, makerTeller).createTransactionPair()
logger.info("TXN: #{} TRANSFER RRN: {} NEFT RRN: {}", transactionNumber, transactionPair.first.rrn, transactionPair.second.rrn)
val (transferResponse, neftResponse) = try { val (transferResponse, neftResponse) = try {
TransactionExecutor().executePair(transactionPair) TransactionExecutor().executePair(transactionPair)
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -19,7 +19,7 @@ import javax.net.ssl.HostnameVerifier
class TransactionExecutor() { class TransactionExecutor() {
private val protocol = "https" private val protocol = "https"
private val host = "180.179.119.227" private val host = "180.179.110.185"
private val port = "443" private val port = "443"
private val rootRoute = "IPKS_Queue_Generation" private val rootRoute = "IPKS_Queue_Generation"
private val remoteUrl = "$protocol://$host:$port/$rootRoute" private val remoteUrl = "$protocol://$host:$port/$rootRoute"
@ -28,14 +28,15 @@ class TransactionExecutor() {
val transferTransaction = transactionPair.first val transferTransaction = transactionPair.first
val neftTransaction = transactionPair.second val neftTransaction = transactionPair.second
val transferResponse = execute(Json.encodeToString(transferTransaction)) val transferResponse = execute(Json.encodeToString(transferTransaction))
val neftResponse = execute(Json.encodeToString(neftTransaction)) val neftResponse = execute(Json.encodeToString(neftTransaction))
return Pair(transferResponse, neftResponse) return Pair(transferResponse, neftResponse)
} }
private fun execute(postBody: String): TransactionResponse { private fun execute(postBody: String): TransactionResponse {
// println(postBody)
val transferRoute = "Ipks" val transferRoute = "IpksApi"
val transferURL = "$remoteUrl/$transferRoute" val transferURL = "$remoteUrl/$transferRoute"
val jsonMediaType = "application/json; charset=utf-8".toMediaType() val jsonMediaType = "application/json; charset=utf-8".toMediaType()
@ -52,9 +53,9 @@ class TransactionExecutor() {
val responseBody = httpClient.newCall(request).execute().use { response -> val responseBody = httpClient.newCall(request).execute().use { response ->
if (!response.isSuccessful) { if (!response.isSuccessful) {
throw IOException("Unexpected code $response") throw IOException("Unexpected response: ${response.body}")
} }
response.body!!.string() response.body?.string() ?: throw IOException("no response body")
} }
val responseObj = JSONObject(responseBody) val responseObj = JSONObject(responseBody)
@ -66,7 +67,7 @@ class TransactionExecutor() {
val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" } val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" }
return TransactionSuccessResponse(status, message, queueNo, error) return TransactionSuccessResponse(status, message, queueNo, error)
} else { } else {
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { "no error message provided" } val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { responseBody }
return TransactionFailureResponse(status, message, errorMsg, error) return TransactionFailureResponse(status, message, errorMsg, error)
} }
return response return response

View File

@ -17,6 +17,7 @@ class TransactionFactory(private val transactionRequest: TransactionRequest, pri
return TransferTransaction( return TransferTransaction(
bankCode = bankDccbToSftpMap[transactionRequest.dccbCode.padStart(4, '0')]!!, bankCode = bankDccbToSftpMap[transactionRequest.dccbCode.padStart(4, '0')]!!,
branchCode = transactionRequest.branchCode.padStart(3,'0'), branchCode = transactionRequest.branchCode.padStart(3,'0'),
// branchCode = "99999", for UAT
cbsTellerId = teller.tellerId, cbsTellerId = teller.tellerId,
cbsTellerUserType = teller.userType, cbsTellerUserType = teller.userType,
queIdType = "5", queIdType = "5",
@ -44,6 +45,7 @@ class TransactionFactory(private val transactionRequest: TransactionRequest, pri
return NeftTransaction( return NeftTransaction(
bankCode = bankDccbToSftpMap[transactionRequest.dccbCode.padStart(4, '0')]!!, bankCode = bankDccbToSftpMap[transactionRequest.dccbCode.padStart(4, '0')]!!,
branchCode = transactionRequest.branchCode.padStart(3,'0'), branchCode = transactionRequest.branchCode.padStart(3,'0'),
// branchCode = "99999", for UAT
cbsTellerId = teller.tellerId, cbsTellerId = teller.tellerId,
cbsTellerUserType = teller.userType, cbsTellerUserType = teller.userType,
queIdType = "5", queIdType = "5",

View File

@ -7,39 +7,48 @@ class TellerDao {
private val tellerMap = mapOf( private val tellerMap = mapOf(
"0003" to mapOf( "0003" to mapOf(
"00008" to "8", "00012" to "312",
"00022" to "22", "00017" to "317",
"00012" to "12", "00013" to "313",
"00014" to "14", "00014" to "314",
"00003" to "1003", "00015" to "315",
"00015" to "15", "00016" to "316",
"00013" to "13", "00019" to "319",
"00018" to "18", "00020" to "320",
"00001" to "1001", "00026" to "11126",
"00004" to "4", "00010" to "310"
"00017" to "1234",
"00005" to "5",
"00011" to "11",
"00020" to "1234",
"00021" to "1234",
"00016" to "016",
"00009" to "9",
"00010" to "10",
"00007" to "7",
"00006" to "6",
), ),
"0015" to mapOf( "0015" to mapOf(
"00008" to "118", "00006" to "11106",
"00002" to "249", "00005" to "11105",
"00002" to "11102",
"00004" to "11104",
"00023" to "1234",
"00008" to "11108",
"00017" to "11117",
"00011" to "10111",
"00021" to "1234",
"00001" to "1234",
"00018" to "11118",
"00012" to "11112",
"00019" to "11119",
"00003" to "11103",
"00009" to "11109",
"00015" to "11115",
"00020" to "11120",
"00013" to "11113",
"00014" to "1234",
"00016" to "11116",
"00010" to "11110",
"00007" to "11107",
"00022" to "1234",
"00026" to "11126"
), ),
"0016" to mapOf(
"00001" to "249",
"00002" to "249"
)
) )
fun getTeller(dccbCode: String, branchCode: String): Teller? { fun getTeller(dccbCode: String, branchCode: String): Teller? {
val branchList = tellerMap[dccbCode] ?: return null val branchList = tellerMap[dccbCode] ?: return null
val tellerId = branchList[branchCode] ?: "249" val tellerId = branchList[branchCode] ?: return null
val teller = Teller( val teller = Teller(
tellerId, tellerId,
dccbCode, dccbCode,

View File

@ -1,6 +1,7 @@
DB_NAME=IPKSDB DB_NAME=IPKS
DB_HOST=testipksdb.c7q7defafeea.ap-south-1.rds.amazonaws.com #DB_HOST=testipksdb.c7q7defafeea.ap-south-1.rds.amazonaws.com
#DB_HOST=localhost #DB_HOST=localhost
DB_HOST=ipksprod3.c7q7defafeea.ap-south-1.rds.amazonaws.com
DB_PORT=1521 DB_PORT=1521
DB_USER=pacs_db DB_USER=pacs_db
DB_PASSWORD=pacs_db DB_PASSWORD=pacs_db