From e3e32458c47b41c2b4a9ca393342169fdf3d77cb Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 10 Dec 2025 15:36:23 +0100 Subject: [PATCH] Refactor/Disable Lift-specific schedulers and actor systems in Boot.scala; update pom.xml to upgrade classutil to 1.5.1 and configure maven-war-plugin with attachClasses; replace scala.jdk.CollectionConverters with scala.collection.JavaConverters for compatibility; add obp-http4s-runner module with fat JAR assembly configuration; update ClassScanUtils to handle UnsupportedOperationException from old ASM versions --- obp-api/pom.xml | 17 ++++- .../main/scala/bootstrap/liftweb/Boot.scala | 36 +++++----- obp-api/src/main/scala/code/api/OAuth2.scala | 2 +- .../code/api/util/CertificateVerifier.scala | 6 +- .../main/scala/code/api/util/JwsUtil.scala | 2 +- .../scala/code/api/v4_0_0/APIMethods400.scala | 2 +- .../generator/ConnectorBuilderUtil.scala | 2 +- .../scala/code/snippet/ConsentScreen.scala | 2 +- .../code/snippet/ConsumerRegistration.scala | 2 +- .../main/scala/code/util/ClassScanUtils.scala | 42 ++++++++--- .../src/main/scala/code/util/HydraUtil.scala | 2 +- .../v4_0_0/GetScannedApiVersionsTest.scala | 2 +- obp-http4s-runner/pom.xml | 71 +++++++++++++++++++ pom.xml | 1 + 14 files changed, 149 insertions(+), 40 deletions(-) create mode 100644 obp-http4s-runner/pom.xml diff --git a/obp-api/pom.xml b/obp-api/pom.xml index 36e14374a..c11d23533 100644 --- a/obp-api/pom.xml +++ b/obp-api/pom.xml @@ -42,6 +42,19 @@ jar-with-dependencies + + + / + true + runtime + + + + + ${project.build.outputDirectory} + / + + @@ -388,7 +401,7 @@ org.clapper classutil_${scala.version} - 1.4.0 + 1.5.1 com.github.grumlimited @@ -666,6 +679,8 @@ 3.4.0 ${webXmlPath} + true + classes diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index ce46e6922..74ecc1d72 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -33,7 +33,7 @@ import code.UserRefreshes.MappedUserRefreshes import code.accountapplication.MappedAccountApplication import code.accountattribute.MappedAccountAttribute import code.accountholders.MapperAccountHolders -import code.actorsystem.ObpActorSystem +//import code.actorsystem.ObpActorSystem import code.api.Constant._ import code.api.ResourceDocs1_4_0.ResourceDocs300.{ResourceDocs310, ResourceDocs400, ResourceDocs500, ResourceDocs510, ResourceDocs600} import code.api.ResourceDocs1_4_0._ @@ -328,7 +328,7 @@ class Boot extends MdcLoggable { createBootstrapSuperUser() //launch the scheduler to clean the database from the expired tokens and nonces, 1 hour - DataBaseCleanerScheduler.start(intervalInSeconds = 60*60) +// DataBaseCleanerScheduler.start(intervalInSeconds = 60*60) // if (Props.devMode || Props.testMode) { // StoredProceduresMockedData.createOrDropMockedPostgresStoredProcedures() @@ -428,15 +428,15 @@ class Boot extends MdcLoggable { logger.debug(s"If you can read this, logging level is debug") - val actorSystem = ObpActorSystem.startLocalActorSystem() - connector match { - case "akka_vDec2018" => - // Start Actor system of Akka connector - ObpActorSystem.startNorthSideAkkaConnectorActorSystem() - case "star" if (APIUtil.getPropsValue("starConnector_supported_types","").split(",").contains("akka")) => - ObpActorSystem.startNorthSideAkkaConnectorActorSystem() - case _ => // Do nothing - } +// val actorSystem = ObpActorSystem.startLocalActorSystem() +// connector match { +// case "akka_vDec2018" => +// // Start Actor system of Akka connector +// ObpActorSystem.startNorthSideAkkaConnectorActorSystem() +// case "star" if (APIUtil.getPropsValue("starConnector_supported_types","").split(",").contains("akka")) => +// ObpActorSystem.startNorthSideAkkaConnectorActorSystem() +// case _ => // Do nothing +// } // where to search snippets LiftRules.addToPackages("code") @@ -751,13 +751,13 @@ class Boot extends MdcLoggable { TransactionScheduler.startAll() - APIUtil.getPropsAsBoolValue("enable_metrics_scheduler", true) match { - case true => - val interval = - APIUtil.getPropsAsIntValue("retain_metrics_scheduler_interval_in_seconds", 3600) - MetricsArchiveScheduler.start(intervalInSeconds = interval) - case false => // Do not start it - } +// APIUtil.getPropsAsBoolValue("enable_metrics_scheduler", true) match { +// case true => +// val interval = +// APIUtil.getPropsAsIntValue("retain_metrics_scheduler_interval_in_seconds", 3600) +// MetricsArchiveScheduler.start(intervalInSeconds = interval) +// case false => // Do not start it +// } object UsernameLockedChecker { def onBeginServicing(session: LiftSession, req: Req): Unit = { diff --git a/obp-api/src/main/scala/code/api/OAuth2.scala b/obp-api/src/main/scala/code/api/OAuth2.scala index d12934d8a..00800f99f 100644 --- a/obp-api/src/main/scala/code/api/OAuth2.scala +++ b/obp-api/src/main/scala/code/api/OAuth2.scala @@ -50,7 +50,7 @@ import sh.ory.hydra.model.OAuth2TokenIntrospection import java.net.URI import scala.concurrent.Future -import scala.jdk.CollectionConverters.mapAsJavaMapConverter +import scala.collection.JavaConverters._ /** * This object provides the API calls necessary to third party applications diff --git a/obp-api/src/main/scala/code/api/util/CertificateVerifier.scala b/obp-api/src/main/scala/code/api/util/CertificateVerifier.scala index 4cc0a408f..66743d483 100644 --- a/obp-api/src/main/scala/code/api/util/CertificateVerifier.scala +++ b/obp-api/src/main/scala/code/api/util/CertificateVerifier.scala @@ -8,7 +8,7 @@ import java.security.cert._ import java.util.{Base64, Collections} import javax.net.ssl.TrustManagerFactory import scala.io.Source -import scala.jdk.CollectionConverters._ +import scala.collection.JavaConverters._ import scala.util.{Failure, Success, Try} object CertificateVerifier extends MdcLoggable { @@ -69,8 +69,8 @@ object CertificateVerifier extends MdcLoggable { trustManagerFactory.init(trustStore) // Get trusted CAs from the trust store - val trustAnchors = trustStore.aliases().asScala - .filter(trustStore.isCertificateEntry) + val trustAnchors = enumerationAsScalaIterator(trustStore.aliases()) + .filter(trustStore.isCertificateEntry(_)) .map(alias => trustStore.getCertificate(alias).asInstanceOf[X509Certificate]) .map(cert => new TrustAnchor(cert, null)) .toSet diff --git a/obp-api/src/main/scala/code/api/util/JwsUtil.scala b/obp-api/src/main/scala/code/api/util/JwsUtil.scala index fb49658cc..57df7733c 100644 --- a/obp-api/src/main/scala/code/api/util/JwsUtil.scala +++ b/obp-api/src/main/scala/code/api/util/JwsUtil.scala @@ -17,7 +17,7 @@ import java.time.format.DateTimeFormatter import java.time.{Duration, ZoneOffset, ZonedDateTime} import java.util import scala.collection.immutable.{HashMap, List} -import scala.jdk.CollectionConverters.seqAsJavaListConverter +import scala.collection.JavaConverters._ object JwsUtil extends MdcLoggable { diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index d85f3d265..367a32f3f 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -113,7 +113,7 @@ import java.util.{Calendar, Date} import scala.collection.immutable.{List, Nil} import scala.collection.mutable.ArrayBuffer import scala.concurrent.Future -import scala.jdk.CollectionConverters.collectionAsScalaIterableConverter +import scala.collection.JavaConverters._ trait APIMethods400 extends MdcLoggable { self: RestHelper => diff --git a/obp-api/src/main/scala/code/bankconnectors/generator/ConnectorBuilderUtil.scala b/obp-api/src/main/scala/code/bankconnectors/generator/ConnectorBuilderUtil.scala index 95d94df17..5a1438be1 100644 --- a/obp-api/src/main/scala/code/bankconnectors/generator/ConnectorBuilderUtil.scala +++ b/obp-api/src/main/scala/code/bankconnectors/generator/ConnectorBuilderUtil.scala @@ -10,7 +10,7 @@ import org.apache.commons.lang3.StringUtils.uncapitalize import java.io.File import java.net.URL import java.util.Date -import scala.jdk.CollectionConverters.enumerationAsScalaIteratorConverter +import scala.collection.JavaConverters._ import scala.language.postfixOps import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} diff --git a/obp-api/src/main/scala/code/snippet/ConsentScreen.scala b/obp-api/src/main/scala/code/snippet/ConsentScreen.scala index 1871517b4..b4be08fec 100644 --- a/obp-api/src/main/scala/code/snippet/ConsentScreen.scala +++ b/obp-api/src/main/scala/code/snippet/ConsentScreen.scala @@ -45,7 +45,7 @@ import net.liftweb.util.Helpers._ import sh.ory.hydra.api.AdminApi import sh.ory.hydra.model.{AcceptConsentRequest, RejectRequest} -import scala.jdk.CollectionConverters.seqAsJavaListConverter +import scala.collection.JavaConverters._ import scala.xml.NodeSeq diff --git a/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala b/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala index b79da7d55..daddd1a29 100644 --- a/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala +++ b/obp-api/src/main/scala/code/snippet/ConsumerRegistration.scala @@ -43,7 +43,7 @@ import org.apache.commons.lang3.StringUtils import org.codehaus.jackson.map.ObjectMapper import scala.collection.immutable.{List, ListMap} -import scala.jdk.CollectionConverters.seqAsJavaListConverter +import scala.collection.JavaConverters._ import scala.xml.{Text, Unparsed} class ConsumerRegistration extends MdcLoggable { diff --git a/obp-api/src/main/scala/code/util/ClassScanUtils.scala b/obp-api/src/main/scala/code/util/ClassScanUtils.scala index 22c070656..a57f10f06 100644 --- a/obp-api/src/main/scala/code/util/ClassScanUtils.scala +++ b/obp-api/src/main/scala/code/util/ClassScanUtils.scala @@ -35,7 +35,15 @@ object ClassScanUtils { */ def getSubTypeObjects[T:TypeTag]: List[T] = { val clazz = ReflectUtils.typeTagToClass[T] - finder.getClasses().filter(_.implements(clazz.getName)).map(_.name).map(companion[T](_)).toList + val classes = try { + finder.getClasses().toList + } catch { + case _: UnsupportedOperationException => + // ASM version is too old for some class files (e.g. requires ASM7). In that case, + // skip scanned APIs instead of failing the whole application. + Seq.empty + } + classes.filter(_.implements(clazz.getName)).map(_.name).map(companion[T](_)).toList } /** @@ -43,14 +51,22 @@ object ClassScanUtils { * @param predict check whether include this type in the result * @return all fit type names */ - def findTypes(predict: ClassInfo => Boolean): List[String] = finder.getClasses() - .filter(predict) - .map(it => { - val name = it.name - if(name.endsWith("$")) name.substring(0, name.length - 1) - else name - }) //some companion type name ends with $, it added by scalac, should remove from class name - .toList + def findTypes(predict: ClassInfo => Boolean): List[String] = { + val classes = try { + finder.getClasses().toList + } catch { + case _: UnsupportedOperationException => + Seq.empty + } + classes + .filter(predict) + .map(it => { + val name = it.name + if(name.endsWith("$")) name.substring(0, name.length - 1) + else name + }) //some companion type name ends with $, it added by scalac, should remove from class name + .toList + } /** * get given class exists jar Files @@ -71,7 +87,13 @@ object ClassScanUtils { */ def getMappers(packageName:String = ""): Seq[ClassInfo] = { val mapperInterface = "net.liftweb.mapper.LongKeyedMapper" - val infos = finder.getClasses().filter(it => it.interfaces.contains(mapperInterface)) + val classes = try { + finder.getClasses().toList + } catch { + case _: UnsupportedOperationException => + Seq.empty + } + val infos = classes.filter(it => it.interfaces.contains(mapperInterface)) if(StringUtils.isNoneBlank()) { infos.filter(classInfo => classInfo.name.startsWith(packageName)) } else { diff --git a/obp-api/src/main/scala/code/util/HydraUtil.scala b/obp-api/src/main/scala/code/util/HydraUtil.scala index 1fdf5f6fb..a6b1627ed 100644 --- a/obp-api/src/main/scala/code/util/HydraUtil.scala +++ b/obp-api/src/main/scala/code/util/HydraUtil.scala @@ -15,7 +15,7 @@ import sh.ory.hydra.model.OAuth2Client import sh.ory.hydra.{ApiClient, Configuration} import scala.collection.immutable.List -import scala.jdk.CollectionConverters.{mapAsJavaMapConverter, seqAsJavaListConverter} +import scala.collection.JavaConverters._ object HydraUtil extends MdcLoggable{ diff --git a/obp-api/src/test/scala/code/api/v4_0_0/GetScannedApiVersionsTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/GetScannedApiVersionsTest.scala index dadf79cdd..14d90ec75 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/GetScannedApiVersionsTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/GetScannedApiVersionsTest.scala @@ -33,7 +33,7 @@ import com.openbankproject.commons.model.ListResult import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion} import org.scalatest.Tag -import scala.jdk.CollectionConverters.collectionAsScalaIterableConverter +import scala.collection.JavaConverters._ class GetScannedApiVersionsTest extends V400ServerSetup { /** diff --git a/obp-http4s-runner/pom.xml b/obp-http4s-runner/pom.xml new file mode 100644 index 000000000..c1bf11535 --- /dev/null +++ b/obp-http4s-runner/pom.xml @@ -0,0 +1,71 @@ + + 4.0.0 + + + com.tesobe + obp-parent + 1.10.1 + ../pom.xml + + + obp-http4s-runner + jar + OBP Http4s Runner + + + + + com.tesobe + obp-api + ${project.version} + classes + jar + + + + org.clapper + classutil_${scala.version} + + + + + + org.clapper + classutil_${scala.version} + 1.5.1 + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.6.0 + + + + bootstrap.http4s.Http4sServer + + + + jar-with-dependencies + + false + obp-http4s-runner + + + + make-fat-jar + package + + single + + + + + + + + diff --git a/pom.xml b/pom.xml index 52827eb8a..da476faed 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ obp-commons obp-api + obp-http4s-runner