Skip to content

Commit 809c03d

Browse files
authored
Merge pull request #2731 from hongwei1/develop
bugfix/fixed the ClassScanUtils scanning issue
2 parents 1eb6aea + 5fc8028 commit 809c03d

5 files changed

Lines changed: 115 additions & 14 deletions

File tree

obp-api/src/main/scala/bootstrap/liftweb/Boot.scala

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ import code.api.ResourceDocs1_4_0.ResourceDocs300.{ResourceDocs310, ResourceDocs
4141
import code.api.ResourceDocs1_4_0._
4242
import code.api._
4343
import code.api.attributedefinition.AttributeDefinition
44+
import code.api.berlin.group.v1_3.{OBP_BERLIN_GROUP_1_3, OBP_BERLIN_GROUP_1_3_Alias}
4445
import code.api.berlin.group.ConstantsBG
46+
import code.api.STET.v1_4.OBP_STET_1_4
47+
import code.api.Polish.v2_1_1_1.OBP_PAPI_2_1_1_1
48+
import code.api.MxOF.{OBP_MXOF_1_0_0, CNBV9_1_0_0}
49+
import code.api.BahrainOBF.v1_0_0.{ApiCollector => BahrainApiCollector}
50+
import code.api.AUOpenBanking.v1_0_0.{ApiCollector => AUApiCollector}
51+
import code.api.UKOpenBanking.v2_0_0.OBP_UKOpenBanking_200
52+
import code.api.UKOpenBanking.v3_1_0.OBP_UKOpenBanking_310
4553
import code.api.cache.Redis
46-
import code.api.util.APIUtil.{enableVersionIfAllowed, errorJsonResponse, getPropsValue}
54+
import code.api.util.APIUtil.{enableVersionIfAllowed, versionIsAllowed,errorJsonResponse, getPropsValue}
4755
import code.api.util.ApiRole._
4856
import code.api.util.ErrorMessages.MandatoryPropertyIsNotSet
4957
import code.api.util._
@@ -463,7 +471,95 @@ class Boot extends MdcLoggable {
463471
ApiVersion.setUrlPrefix(ApiPathZero)
464472

465473
// Add the various API versions
474+
val scannedApisCount = ScannedApis.versionMapScannedApis.size
475+
logger.info(s"ClassScanUtils found $scannedApisCount ScannedApis implementations")
476+
466477
ScannedApis.versionMapScannedApis.keys.foreach(enableVersionIfAllowed) // process all scanned apis versions
478+
479+
480+
// Manual registration for ScannedApis if not already registered by ClassScanUtils
481+
// This ensures all APIs work in Fat JAR environment where class scanning fails
482+
483+
if (!ScannedApis.versionMapScannedApis.contains(ConstantsBG.berlinGroupVersion1)) {
484+
logger.warn("BGv1.3 was NOT found by ClassScanUtils, registering manually")
485+
if (versionIsAllowed(ConstantsBG.berlinGroupVersion1)) {
486+
LiftRules.statelessDispatch.append(OBP_BERLIN_GROUP_1_3)
487+
logger.info(s"${ConstantsBG.berlinGroupVersion1.fullyQualifiedVersion} was ENABLED (manual registration)")
488+
}
489+
}
490+
491+
if (!ScannedApis.versionMapScannedApis.contains(OBP_BERLIN_GROUP_1_3_Alias.apiVersion)) {
492+
logger.warn("BGv1.3 Alias was NOT found by ClassScanUtils, registering manually")
493+
if (versionIsAllowed(OBP_BERLIN_GROUP_1_3_Alias.apiVersion)) {
494+
LiftRules.statelessDispatch.append(OBP_BERLIN_GROUP_1_3_Alias)
495+
logger.info(s"${OBP_BERLIN_GROUP_1_3_Alias.apiVersion.fullyQualifiedVersion} was ENABLED (manual registration)")
496+
}
497+
}
498+
499+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.stetV14)) {
500+
logger.warn("STET v1.4 was NOT found by ClassScanUtils, registering manually")
501+
if (versionIsAllowed(ApiVersion.stetV14)) {
502+
LiftRules.statelessDispatch.append(OBP_STET_1_4)
503+
logger.info(s"${ApiVersion.stetV14.fullyQualifiedVersion} was ENABLED (manual registration)")
504+
}
505+
}
506+
507+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.polishApiV2111)) {
508+
logger.warn("Polish API v2.1.1.1 was NOT found by ClassScanUtils, registering manually")
509+
if (versionIsAllowed(ApiVersion.polishApiV2111)) {
510+
LiftRules.statelessDispatch.append(OBP_PAPI_2_1_1_1)
511+
logger.info(s"${ApiVersion.polishApiV2111.fullyQualifiedVersion} was ENABLED (manual registration)")
512+
}
513+
}
514+
515+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.mxofV100)) {
516+
logger.warn("Mexico Open Finance v1.0.0 was NOT found by ClassScanUtils, registering manually")
517+
if (versionIsAllowed(ApiVersion.mxofV100)) {
518+
LiftRules.statelessDispatch.append(OBP_MXOF_1_0_0)
519+
logger.info(s"${ApiVersion.mxofV100.fullyQualifiedVersion} was ENABLED (manual registration)")
520+
}
521+
}
522+
523+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.cnbv9)) {
524+
logger.warn("Mexico CNBV9 v1.0.0 was NOT found by ClassScanUtils, registering manually")
525+
if (versionIsAllowed(ApiVersion.cnbv9)) {
526+
LiftRules.statelessDispatch.append(CNBV9_1_0_0)
527+
logger.info(s"${ApiVersion.cnbv9.fullyQualifiedVersion} was ENABLED (manual registration)")
528+
}
529+
}
530+
531+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.bahrainObfV100)) {
532+
logger.warn("Bahrain OBF v1.0.0 was NOT found by ClassScanUtils, registering manually")
533+
if (versionIsAllowed(ApiVersion.bahrainObfV100)) {
534+
LiftRules.statelessDispatch.append(BahrainApiCollector)
535+
logger.info(s"${ApiVersion.bahrainObfV100.fullyQualifiedVersion} was ENABLED (manual registration)")
536+
}
537+
}
538+
539+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.cdsAuV100)) {
540+
logger.warn("Australia CDS v1.0.0 was NOT found by ClassScanUtils, registering manually")
541+
if (versionIsAllowed(ApiVersion.cdsAuV100)) {
542+
LiftRules.statelessDispatch.append(AUApiCollector)
543+
logger.info(s"${ApiVersion.cdsAuV100.fullyQualifiedVersion} was ENABLED (manual registration)")
544+
}
545+
}
546+
547+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.ukOpenBankingV20)) {
548+
logger.warn("UK Open Banking v2.0.0 was NOT found by ClassScanUtils, registering manually")
549+
if (versionIsAllowed(ApiVersion.ukOpenBankingV20)) {
550+
LiftRules.statelessDispatch.append(OBP_UKOpenBanking_200)
551+
logger.info(s"${ApiVersion.ukOpenBankingV20.fullyQualifiedVersion} was ENABLED (manual registration)")
552+
}
553+
}
554+
555+
if (!ScannedApis.versionMapScannedApis.contains(ApiVersion.ukOpenBankingV31)) {
556+
logger.warn("UK Open Banking v3.1.0 was NOT found by ClassScanUtils, registering manually")
557+
if (versionIsAllowed(ApiVersion.ukOpenBankingV31)) {
558+
LiftRules.statelessDispatch.append(OBP_UKOpenBanking_310)
559+
logger.info(s"${ApiVersion.ukOpenBankingV31.fullyQualifiedVersion} was ENABLED (manual registration)")
560+
}
561+
}
562+
467563
enableVersionIfAllowed(ApiVersion.v1_2_1)
468564
enableVersionIfAllowed(ApiVersion.v1_3_0)
469565
enableVersionIfAllowed(ApiVersion.v1_4_0)

obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
138138
case ApiVersion.v1_2_1 => Implementations1_2_1.resourceDocs
139139
case ApiVersion.`dynamic-endpoint` => OBPAPIDynamicEndpoint.allResourceDocs
140140
case ApiVersion.`dynamic-entity` => OBPAPIDynamicEntity.allResourceDocs
141-
case version: ScannedApiVersion => ScannedApis.versionMapScannedApis(version).allResourceDocs
141+
case version: ScannedApiVersion => ScannedApis.versionMapScannedApis.get(version).map(_.allResourceDocs).getOrElse(ArrayBuffer.empty[ResourceDoc])
142142
case _ => ArrayBuffer.empty[ResourceDoc]
143143
}
144144

@@ -161,7 +161,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
161161
case ApiVersion.v1_2_1 => OBPAPI1_2_1.routes
162162
case ApiVersion.`dynamic-endpoint` => OBPAPIDynamicEndpoint.routes
163163
case ApiVersion.`dynamic-entity` => OBPAPIDynamicEntity.routes
164-
case version: ScannedApiVersion => ScannedApis.versionMapScannedApis(version).routes
164+
case version: ScannedApiVersion => ScannedApis.versionMapScannedApis.get(version).map(_.routes).getOrElse(Nil)
165165
case _ => Nil
166166
}
167167

obp-api/src/main/scala/code/api/util/APIUtil.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
28232823
case ApiVersion.v6_0_0 => LiftRules.statelessDispatch.append(v6_0_0.OBPAPI6_0_0)
28242824
case ApiVersion.`dynamic-endpoint` => LiftRules.statelessDispatch.append(OBPAPIDynamicEndpoint)
28252825
case ApiVersion.`dynamic-entity` => LiftRules.statelessDispatch.append(OBPAPIDynamicEntity)
2826-
case version: ScannedApiVersion => LiftRules.statelessDispatch.append(ScannedApis.versionMapScannedApis(version))
2826+
case version: ScannedApiVersion =>
2827+
ScannedApis.versionMapScannedApis.get(version).foreach(api => LiftRules.statelessDispatch.append(api))
28272828
case _ => logger.info(s"There is no ${version.toString}")
28282829
}
28292830

obp-api/src/main/scala/code/util/ClassScanUtils.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package code.util
33
import java.io.File
44

55
import com.openbankproject.commons.model.Bank
6+
import code.util.Helper.MdcLoggable
67
import org.apache.commons.lang3.StringUtils
78
import org.clapper.classutil.{ClassFinder, ClassInfo}
89
import com.openbankproject.commons.util.ReflectUtils
@@ -13,7 +14,7 @@ import scala.reflect.runtime.universe.TypeTag
1314
* this is some util method to scan any class according some rules
1415
* @author shuang
1516
*/
16-
object ClassScanUtils {
17+
object ClassScanUtils extends MdcLoggable {
1718

1819
lazy val finder = ClassFinder(getClassPath(this.getClass, classOf[Bank], classOf[String]))
1920

@@ -36,14 +37,23 @@ object ClassScanUtils {
3637
def getSubTypeObjects[T:TypeTag]: List[T] = {
3738
val clazz = ReflectUtils.typeTagToClass[T]
3839
val classes = try {
39-
finder.getClasses().toList
40+
val allClasses = finder.getClasses().toList
41+
logger.info(s"ClassScanUtils successfully scanned ${allClasses.size} classes from classpath")
42+
allClasses
4043
} catch {
41-
case _: UnsupportedOperationException =>
44+
case e: UnsupportedOperationException =>
4245
// ASM version is too old for some class files (e.g. requires ASM7). In that case,
4346
// skip scanned APIs instead of failing the whole application.
47+
logger.warn(s"Class scanning failed with UnsupportedOperationException: ${e.getMessage}")
48+
logger.warn("This is expected when running from a Fat JAR. Scanned APIs will not be auto-registered.")
49+
Seq.empty
50+
case e: Exception =>
51+
logger.warn(s"Class scanning failed with ${e.getClass.getSimpleName}: ${e.getMessage}")
4452
Seq.empty
4553
}
46-
classes.filter(_.implements(clazz.getName)).map(_.name).map(companion[T](_)).toList
54+
val filtered = classes.filter(_.implements(clazz.getName))
55+
logger.info(s"Found ${filtered.size} classes implementing ${clazz.getName}")
56+
filtered.map(_.name).map(companion[T](_)).toList
4757
}
4858

4959
/**

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<avro.version>1.8.2</avro.version>
1717
<lift.version>3.5.0</lift.version>
1818
<http4s.version>0.23.30</http4s.version>
19-
<obp-ri.version>2016.11-RC6-SNAPSHOT</obp-ri.version>
2019
<!-- Common plugin settings -->
2120
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2221
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
@@ -43,11 +42,6 @@
4342
<name>Scala-Tools Dependencies Repository for Releases</name>
4443
<url>https://oss.sonatype.org/content/repositories/releases/</url>
4544
</repository>
46-
<repository>
47-
<id>scala-tools.snapshots</id>
48-
<name>Scala-Tools Dependencies Repository for Snapshots</name>
49-
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
50-
</repository>
5145
<repository>
5246
<id>git-OpenBankProject</id>
5347
<name>OpenBankProject Git based repo</name>

0 commit comments

Comments
 (0)