mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 19:16:53 +00:00
Merge pull request #1541 from oldbig/develop
feature/dynamic_endpoint_path_variable_and_error_message
This commit is contained in:
commit
e70032ebc4
@ -2946,9 +2946,14 @@ trait APIMethods400 {
|
||||
(box, _) <- NewStyle.function.dynamicEndpointProcess(url, json, method, params, pathParams, callContext)
|
||||
} yield {
|
||||
box match {
|
||||
case Full(v) => (v, HttpCode.`200`(Some(cc)))
|
||||
case e: Failure => (e.messageChain, HttpCode.`200`(Some(cc))) // TODO code need change
|
||||
case _ => ("fail", HttpCode.`200`(Some(cc)))
|
||||
case Full(v) =>
|
||||
val code = (v \ "code").asInstanceOf[JInt].num.toInt
|
||||
(v \ "value", callContext.map(_.copy(httpCode = Some(code))))
|
||||
|
||||
case e: Failure =>
|
||||
val changedMsgFailure = e.copy(msg = s"$InternalServerError ${e.msg}")
|
||||
fullBoxOrException[JValue](changedMsgFailure)
|
||||
??? // will not execute to here, Because the failure message is thrown by upper line.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
private val ExpressionRegx = """\{(.+?)\}""".r
|
||||
/**
|
||||
* unapply Request to (request url, json, http method, request parameters, path parameters, role)
|
||||
* request url is current request url
|
||||
* request url is current request target url to remote server
|
||||
* json is request body
|
||||
* http method is request http method
|
||||
* request parameters is http request parameters
|
||||
@ -220,7 +220,6 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
ApiRole.getOrCreateDynamicApiRole(roleName)
|
||||
))
|
||||
}
|
||||
val connectorMethods = Some(List("dynamicEndpointProcess"))
|
||||
val doc = ResourceDoc(
|
||||
partialFunction,
|
||||
implementedInApiVersion,
|
||||
@ -234,8 +233,7 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
errorResponseBodies,
|
||||
catalogs,
|
||||
tags,
|
||||
roles,
|
||||
connectorMethods = connectorMethods
|
||||
roles
|
||||
)
|
||||
(doc, path)
|
||||
}
|
||||
|
||||
@ -104,10 +104,16 @@ package object bankconnectors extends MdcLoggable {
|
||||
NewStyle.function.getMethodRoutings(Some(methodName))
|
||||
.find(routing => {
|
||||
routing.parameters.exists(it => it.key == "http_method" && it.value.equalsIgnoreCase(method.value)) &&
|
||||
routing.parameters.exists(it => it.key == "url")&&
|
||||
routing.parameters.exists(it => it.key == "url") &&
|
||||
routing.parameters.exists(
|
||||
it => it.key == "url_pattern" &&
|
||||
(it.value == url || Pattern.compile(it.value).matcher(url).matches())
|
||||
it => {
|
||||
val value = it.value
|
||||
it.key == "url_pattern" && // url_pattern is equals with current target url to remote server or as regex match
|
||||
(value == url || {
|
||||
val regexStr = value.replaceAll("""\{[^/]+?\}""", "[^/]+?")
|
||||
Pattern.compile(regexStr).matcher(url).matches()
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,12 +58,14 @@ import code.api.util.APIUtil._
|
||||
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
|
||||
import code.customer.internalMapping.MappedCustomerIdMappingProvider
|
||||
import code.model.dataAccess.internalMapping.MappedAccountIdMappingProvider
|
||||
import code.util.{Helper, JsonUtils}
|
||||
import code.util.JsonUtils
|
||||
import com.openbankproject.commons.model.enums.{AccountAttributeType, CardAttributeType, DynamicEntityOperation, ProductAttributeType}
|
||||
import com.openbankproject.commons.util.{ReflectUtils, RequiredFieldValidation}
|
||||
import com.openbankproject.commons.util.ReflectUtils
|
||||
import net.liftweb.json
|
||||
import net.liftweb.json.{JValue, _}
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import net.liftweb.json.Extraction.decompose
|
||||
import net.liftweb.json.JsonParser.ParseException
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable {
|
||||
@ -9382,21 +9384,34 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
|
||||
case (status, entity) if status.isSuccess() =>
|
||||
this.extractBody(entity)
|
||||
.map{
|
||||
case v if StringUtils.isBlank(v) => (Empty, callContext)
|
||||
case v => (Full(json.parse(v)), callContext)
|
||||
case v if StringUtils.isBlank(v) =>
|
||||
(Full{
|
||||
("code", status.intValue()) ~ ("value", JString(""))
|
||||
}, callContext)
|
||||
case v =>
|
||||
(Full{
|
||||
("code", status.intValue()) ~ ("value", json.parse(v))
|
||||
}, callContext)
|
||||
}
|
||||
case (status, entity) => {
|
||||
val future: Future[Box[Box[JValue]]] = extractBody(entity) map { msg =>
|
||||
tryo {
|
||||
val failure: Box[JValue] = ParamFailure(msg, APIFailureNewStyle(msg, status.intValue()))
|
||||
failure
|
||||
} ~> APIFailureNewStyle(msg, status.intValue())
|
||||
val future: Future[JObject] = extractBody(entity) map { msg =>
|
||||
try {
|
||||
("code", status.intValue()) ~ ("value", json.parse(msg))
|
||||
} catch {
|
||||
case _: ParseException => ("code", status.intValue()) ~ ("value", JString(msg))
|
||||
}
|
||||
}
|
||||
future.map{
|
||||
case Full(v) => (v, callContext)
|
||||
case e: EmptyBox => (e, callContext)
|
||||
future.map { jObject =>
|
||||
(Full(jObject), callContext)
|
||||
}
|
||||
}
|
||||
}.recoverWith {
|
||||
case e: Exception if e.getMessage.contains(s"$httpRequestTimeout seconds") =>
|
||||
Future.failed(
|
||||
new Exception(s"$AdapterTimeOurError Please Check Adapter Side, the response should be returned to OBP-Side in $httpRequestTimeout seconds. Details: ${e.getMessage}", e)
|
||||
)
|
||||
case e: Exception =>
|
||||
Future.failed(new Exception(s"$AdapterUnknownError Please Check Adapter Side! Details: ${e.getMessage}", e))
|
||||
}
|
||||
|
||||
result
|
||||
|
||||
Loading…
Reference in New Issue
Block a user