Skip to content

Commit

Permalink
Merge pull request #2326 from hongwei1/develop
Browse files Browse the repository at this point in the history
refactor/added the show.dependent.connectors props
  • Loading branch information
simonredfern committed Nov 16, 2023
2 parents 31819ee + 6d6264e commit 2759550
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
7 changes: 6 additions & 1 deletion obp-api/src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -1273,4 +1273,9 @@ expectedOpenFuturesPerService=100
# Enable /Disable IBAN validation
validate_iban=false

set_response_header_Set-Cookie = "Path=/; HttpOnly; Secure"
set_response_header_Set-Cookie = "Path=/; HttpOnly; Secure"


# Show all dependent connector methods for each endpoint. The default value is false.
# If set to true, it may consume a significant amount of heap memory.
#show_used_connector_methods=false
7 changes: 4 additions & 3 deletions obp-api/src/main/scala/code/api/constant/constant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ object Constant extends MdcLoggable {
final val STATIC_RESOURCE_DOC_CACHE_KEY_PREFIX = "rd_static_"
final val ALL_RESOURCE_DOC_CACHE_KEY_PREFIX = "rd_all_"
final val STATIC_SWAGGER_DOC_CACHE_KEY_PREFIX = "swagger_static_"
val CREATE_LOCALISED_RESOURCE_DOC_JSON_TTL: Int = APIUtil.getPropsValue(s"createLocalisedResourceDocJson.cache.ttl.seconds", "3600").toInt
val GET_DYNAMIC_RESOURCE_DOCS_TTL: Int = APIUtil.getPropsValue(s"dynamicResourceDocsObp.cache.ttl.seconds", "3600").toInt
val GET_STATIC_RESOURCE_DOCS_TTL: Int = APIUtil.getPropsValue(s"staticResourceDocsObp.cache.ttl.seconds", "3600").toInt
final val CREATE_LOCALISED_RESOURCE_DOC_JSON_TTL: Int = APIUtil.getPropsValue(s"createLocalisedResourceDocJson.cache.ttl.seconds", "3600").toInt
final val GET_DYNAMIC_RESOURCE_DOCS_TTL: Int = APIUtil.getPropsValue(s"dynamicResourceDocsObp.cache.ttl.seconds", "3600").toInt
final val GET_STATIC_RESOURCE_DOCS_TTL: Int = APIUtil.getPropsValue(s"staticResourceDocsObp.cache.ttl.seconds", "3600").toInt
final val SHOW_USED_CONNECTOR_METHODS: Boolean = APIUtil.getPropsAsBoolValue(s"show_used_connector_methods", false)

}

Expand Down
19 changes: 16 additions & 3 deletions obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
if (isNeedCheckView) {
checkerFunctions += checkViewFun
}
val addedMethods: List[String] = checkerFunctions.toList.flatMap(getDependentConnectorMethods(_)).map("obp." +)
val addedMethods: List[String] = checkerFunctions.toList.flatMap(getDependentConnectorMethods(_))
.map(value =>("obp." +value).intern())

// add connector method to endpoint info
addEndpointInfos(addedMethods, partialFunctionName, implementedInApiVersion)
Expand Down Expand Up @@ -4194,7 +4195,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
* NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap.
* according class name, method name and method's signature to get all dependent methods
*/
def getDependentMethods(className: String, methodName:String, signature: String): List[(String, String, String)] = {
def getDependentMethods(className: String, methodName:String, signature: String): List[(String, String, String)] =
if(SHOW_USED_CONNECTOR_METHODS){
val methods = ListBuffer[(String, String, String)]()
//NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap.
val ctClass = cp.get(className)
Expand All @@ -4207,6 +4209,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
}
})
methods.toList
} else {
Nil
}

/**
Expand All @@ -4215,7 +4219,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
* @param endpoint can be OBPEndpoint or other PartialFunction
* @return a list of connector method name
*/
def getDependentConnectorMethods(endpoint: PartialFunction[_, _]): List[String] = {
def getDependentConnectorMethods(endpoint: PartialFunction[_, _]): List[String] =
if (SHOW_USED_CONNECTOR_METHODS){
val connectorTypeName = classOf[Connector].getName
val endpointClassName = endpoint.getClass.getName
// not analyze dynamic code
Expand Down Expand Up @@ -4249,6 +4254,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{

connectorMethods.toList.distinct
}
else{
Nil
}

case class EndpointInfo(name: String, version: String)

Expand Down Expand Up @@ -4762,3 +4770,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{


}


object createDependentConnectorMethod extends App{

}
8 changes: 6 additions & 2 deletions obp-api/src/main/scala/code/api/util/DynamicUtil.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package code.api.util

import code.api.Constant.SHOW_USED_CONNECTOR_METHODS
import code.api.{APIFailureNewStyle, JsonResponseException}
import code.api.util.ErrorMessages.DynamicResourceDocMethodDependency
import code.util.Helper.MdcLoggable
Expand All @@ -9,10 +10,10 @@ import com.openbankproject.commons.util.{JsonUtils, ReflectUtils}
import javassist.{ClassPool, LoaderClassPath}
import net.liftweb.common.{Box, Empty, Failure, Full, ParamFailure}
import net.liftweb.http.JsonResponse

import net.liftweb.json.{Extraction, JValue, prettyRender}
import org.apache.commons.lang3.StringUtils
import org.graalvm.polyglot.{Context, Engine, HostAccess, PolyglotAccess}

import java.security.{AccessControlContext, AccessController, CodeSource, Permission, PermissionCollection, Permissions, Policy, PrivilegedAction, ProtectionDomain}
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -151,7 +152,8 @@ object DynamicUtil extends MdcLoggable{
* @param predicate
* @return
*/
def getDynamicCodeDependentMethods(clazz: Class[_], predicate: String => Boolean = _ => true): List[(String, String, String)] = {
def getDynamicCodeDependentMethods(clazz: Class[_], predicate: String => Boolean = _ => true): List[(String, String, String)] =
if (SHOW_USED_CONNECTOR_METHODS) {
val className = clazz.getTypeName
val listBuffer = new ListBuffer[(String, String, String)]()
val classPool = getClassPool(clazz.getClassLoader)
Expand All @@ -171,6 +173,8 @@ object DynamicUtil extends MdcLoggable{
}

listBuffer.distinct.toList
} else {
Nil
}

trait Sandbox {
Expand Down
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Most recent changes at top of file
```
Date Commit Action
16/11/2023 2b8811dc Added show_used_connector_methods, default is false.
30/10/2023 4e82c66c Added createLocalisedResourceDocJson.cache.ttl.seconds, default is 3600
13/10/2023 d87c99d8 Added props hikari.connectionTimeout, default is from hikari.
Added props hikari.maximumPoolSize, default is from hikari.
Expand Down

0 comments on commit 2759550

Please sign in to comment.