From 0f713aaa4434460c1667559ea260df788573d24c Mon Sep 17 00:00:00 2001 From: Adel El-Beik <48713346+adelel1@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:40:42 +0100 Subject: [PATCH] ENT-11003: Upgraded Jetty and Jersey. (#7715) * ENT-11003: Upgraded jetty and jersey. Fixed up simm valuation demo. --- constants.properties | 6 ++--- core-tests/build.gradle | 2 +- core/build.gradle | 2 +- node/build.gradle | 5 ++-- .../registration/NodeRegistrationTest.kt | 11 +++++--- samples/bank-of-corda-demo/build.gradle | 1 + .../net/corda/bank/api/BankOfCordaWebApi.kt | 10 +++++--- samples/simm-valuation-demo/build.gradle | 1 + .../contracts-states/build.gradle | 3 ++- .../simm-valuation-demo/flows/build.gradle | 11 ++++++++ .../net/corda/vega/SimmValuationTest.kt | 2 -- .../kotlin/net/corda/vega/api/PortfolioApi.kt | 12 ++++++--- testing/node-driver/build.gradle | 5 ++-- .../testing/driver/internal/DriverInternal.kt | 2 +- .../node/internal/network/CrlServer.kt | 16 ++++++------ .../node/internal/network/NetworkMapServer.kt | 23 ++++++++++------- testing/testserver/build.gradle | 13 ++++------ .../net/corda/webserver/api/APIServer.kt | 10 ++++---- .../corda/webserver/converters/Converters.kt | 6 ++--- .../corda/webserver/internal/APIServerImpl.kt | 2 +- .../webserver/internal/AllExceptionMapper.kt | 6 ++--- .../corda/webserver/internal/NodeWebServer.kt | 25 +++++++++---------- .../servlets/AttachmentDownloadServlet.kt | 10 ++++---- .../webserver/servlets/CorDappInfoServlet.kt | 6 ++--- .../webserver/servlets/DataUploadServlet.kt | 14 +++++------ .../webserver/servlets/ObjectMapperConfig.kt | 4 +-- .../webserver/servlets/ResponseFilter.kt | 8 +++--- 27 files changed, 123 insertions(+), 93 deletions(-) diff --git a/constants.properties b/constants.properties index de99c0c42b..5274f73216 100644 --- a/constants.properties +++ b/constants.properties @@ -49,15 +49,15 @@ artemisVersion=2.32.0 # TODO Upgrade Jackson only when corda is using kotlin 1.3.10 jacksonVersion=2.17.0 jacksonKotlinVersion=2.17.0 -jettyVersion=9.4.54.v20240208 -jerseyVersion=2.25 +jettyVersion=12.0.7 +jerseyVersion=3.1.6 servletVersion=4.0.1 assertjVersion=3.12.2 slf4JVersion=2.0.12 log4JVersion=2.23.1 okhttpVersion=4.11.0 nettyVersion=4.1.77.Final -fileuploadVersion=1.4 +fileuploadVersion=2.0.0-M1 kryoVersion=5.5.0 kryoSerializerVersion=0.43 # Legacy JUnit 4 version diff --git a/core-tests/build.gradle b/core-tests/build.gradle index 9c5fbcfa41..08823f41ee 100644 --- a/core-tests/build.gradle +++ b/core-tests/build.gradle @@ -87,7 +87,7 @@ dependencies { } testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}" testImplementation "junit:junit:$junit_version" - testImplementation "commons-fileupload:commons-fileupload:$fileupload_version" + testImplementation "org.apache.commons:commons-fileupload2-jakarta:$fileupload_version" // Guava: Google test library (collections test suite) testImplementation "com.google.guava:guava-testlib:$guava_version" testImplementation "com.google.jimfs:jimfs:1.1" diff --git a/core/build.gradle b/core/build.gradle index ea7d76882d..6674d832ea 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -47,7 +47,7 @@ dependencies { testImplementation sourceSets.obfuscator.output testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version" testImplementation "junit:junit:$junit_version" - testImplementation "commons-fileupload:commons-fileupload:$fileupload_version" + testImplementation "org.apache.commons:commons-fileupload2-jakarta:$fileupload_version" // Guava: Google test library (collections test suite) testImplementation "com.google.guava:guava-testlib:$guava_version" testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version" diff --git a/node/build.gradle b/node/build.gradle index d5b193ee9b..881235caa9 100644 --- a/node/build.gradle +++ b/node/build.gradle @@ -200,8 +200,8 @@ dependencies { // Jetty dependencies for NetworkMapClient test. // Web stuff: for HTTP[S] servlets testImplementation "org.hamcrest:hamcrest-library:2.1" - testImplementation "org.eclipse.jetty:jetty-servlet:${jetty_version}" - testImplementation "org.eclipse.jetty:jetty-webapp:${jetty_version}" + testImplementation "org.eclipse.jetty.ee10:jetty-ee10-servlet:${jetty_version}" + testImplementation "org.eclipse.jetty.ee10:jetty-ee10-webapp:${jetty_version}" testImplementation "javax.servlet:javax.servlet-api:${servlet_version}" testImplementation "org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version" testImplementation "com.google.jimfs:jimfs:1.1" @@ -211,6 +211,7 @@ dependencies { testImplementation "org.glassfish.jersey.core:jersey-server:${jersey_version}" testImplementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}" testImplementation "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}" + testImplementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version" testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}" diff --git a/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt b/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt index f472870a5f..86f91e0918 100644 --- a/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt +++ b/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt @@ -1,5 +1,13 @@ package net.corda.node.utilities.registration +import jakarta.ws.rs.Consumes +import jakarta.ws.rs.GET +import jakarta.ws.rs.POST +import jakarta.ws.rs.Path +import jakarta.ws.rs.PathParam +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.core.Response import net.corda.core.identity.CordaX500Name import net.corda.core.internal.logElapsedTime import net.corda.core.internal.readFully @@ -40,9 +48,6 @@ import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentSkipListSet import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream -import javax.ws.rs.* -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response class NodeRegistrationTest { companion object { diff --git a/samples/bank-of-corda-demo/build.gradle b/samples/bank-of-corda-demo/build.gradle index 92da2420ef..41229b1ad1 100644 --- a/samples/bank-of-corda-demo/build.gradle +++ b/samples/bank-of-corda-demo/build.gradle @@ -43,6 +43,7 @@ dependencies { // Javax is required for webapis implementation "org.glassfish.jersey.core:jersey-server:${jersey_version}" + implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version" implementation "net.sf.jopt-simple:jopt-simple:$jopt_simple_version" implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version" diff --git a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt index 25daa53476..d20a3f2acc 100644 --- a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt +++ b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt @@ -1,5 +1,12 @@ package net.corda.bank.api +import jakarta.ws.rs.Consumes +import jakarta.ws.rs.GET +import jakarta.ws.rs.POST +import jakarta.ws.rs.Path +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.core.Response import net.corda.core.contracts.Amount import net.corda.core.identity.CordaX500Name import net.corda.core.messaging.CordaRPCOps @@ -10,9 +17,6 @@ import net.corda.core.utilities.getOrThrow import net.corda.finance.flows.CashIssueAndPaymentFlow import java.time.LocalDateTime import java.util.* -import javax.ws.rs.* -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response // API is accessible from /api/bank. All paths specified below are relative to it. @Path("bank") diff --git a/samples/simm-valuation-demo/build.gradle b/samples/simm-valuation-demo/build.gradle index 887c4de814..db7d765146 100644 --- a/samples/simm-valuation-demo/build.gradle +++ b/samples/simm-valuation-demo/build.gradle @@ -54,6 +54,7 @@ dependencies { // Javax is required for webapis implementation "org.glassfish.jersey.core:jersey-server:$jersey_version" + implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version" // Cordapp dependencies // Specify your cordapp's dependencies below, including dependent cordapps diff --git a/samples/simm-valuation-demo/contracts-states/build.gradle b/samples/simm-valuation-demo/contracts-states/build.gradle index 8601d61dc6..fe4c4485eb 100644 --- a/samples/simm-valuation-demo/contracts-states/build.gradle +++ b/samples/simm-valuation-demo/contracts-states/build.gradle @@ -80,7 +80,8 @@ tasks.register('generateDependencies') { processResources.finalizedBy generateDependencies jar { - archiveClassifier = 'fat' + // Test CorDapp filters out *-tests.jar. We only want the shrinked jar not this one. + archiveClassifier = 'tests' } tasks.register('shrink', ProGuardTask) { diff --git a/samples/simm-valuation-demo/flows/build.gradle b/samples/simm-valuation-demo/flows/build.gradle index 188b30ec45..5aab71f79f 100644 --- a/samples/simm-valuation-demo/flows/build.gradle +++ b/samples/simm-valuation-demo/flows/build.gradle @@ -1,3 +1,5 @@ +import net.corda.plugins.SignJar + apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'net.corda.plugins.quasar-utils' apply plugin: 'net.corda.plugins.cordapp' @@ -15,6 +17,9 @@ cordapp { vendor "R3" licence "Open Source (Apache 2)" } + signing { + enabled false + } } dependencies { @@ -43,3 +48,9 @@ dependencies { jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } + +tasks.register('sign', SignJar) { + inputJars jar +} + +jar.finalizedBy sign \ No newline at end of file diff --git a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt index 83395b772a..51e1b0249d 100644 --- a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt +++ b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt @@ -15,7 +15,6 @@ import net.corda.vega.api.PortfolioApiUtils import net.corda.vega.api.SwapDataModel import net.corda.vega.api.SwapDataView import org.assertj.core.api.Assertions.assertThat -import org.junit.Ignore import org.junit.Test import java.math.BigDecimal import java.time.LocalDate @@ -30,7 +29,6 @@ class SimmValuationTest { } @Test(timeout=300_000) - @Ignore("TODO JDK17: Fixme - Stage 2") fun `runs SIMM valuation demo`() { driver(DriverParameters(isDebug = true, startNodesInProcess = false, // starting nodes in separate processes to ensure system class path does not contain 3rd party libraries (masking serialization issues) diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApi.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApi.kt index fee3363a0a..e0f2f9a7b0 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApi.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApi.kt @@ -1,6 +1,15 @@ package net.corda.vega.api import com.opengamma.strata.basics.currency.MultiCurrencyAmount +import jakarta.ws.rs.Consumes +import jakarta.ws.rs.GET +import jakarta.ws.rs.POST +import jakarta.ws.rs.PUT +import jakarta.ws.rs.Path +import jakarta.ws.rs.PathParam +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.core.Response import net.corda.core.contracts.StateAndRef import net.corda.core.utilities.parsePublicKeyBase58 import net.corda.core.utilities.toBase58String @@ -24,9 +33,6 @@ import net.corda.vega.portfolio.toStateAndRef import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneId -import javax.ws.rs.* -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response //TODO: Change import namespaces vega -> .... diff --git a/testing/node-driver/build.gradle b/testing/node-driver/build.gradle index f7eb88c28b..4da5d479d5 100644 --- a/testing/node-driver/build.gradle +++ b/testing/node-driver/build.gradle @@ -58,8 +58,8 @@ dependencies { // Jetty dependencies for NetworkMapClient test. // Web stuff: for HTTP[S] servlets - implementation "org.eclipse.jetty:jetty-servlet:${jetty_version}" - implementation "org.eclipse.jetty:jetty-webapp:${jetty_version}" + implementation "org.eclipse.jetty.ee10:jetty-ee10-servlet:${jetty_version}" + implementation "org.eclipse.jetty.ee10:jetty-ee10-webapp:${jetty_version}" implementation "javax.servlet:javax.servlet-api:${servlet_version}" implementation "org.gradle:gradle-tooling-api:7.1" @@ -68,6 +68,7 @@ dependencies { implementation "org.glassfish.jersey.core:jersey-server:${jersey_version}" implementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}" implementation "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}" + implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version" implementation "io.reactivex:rxjava:$rxjava_version" implementation("org.apache.activemq:artemis-core-client:${artemis_version}") { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt index c761b96498..5f7f640028 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt @@ -1,5 +1,6 @@ package net.corda.testing.driver.internal +import jakarta.validation.constraints.NotNull import net.corda.core.flows.FlowLogic import net.corda.core.messaging.CordaRPCOps import net.corda.core.node.NodeInfo @@ -14,7 +15,6 @@ import net.corda.testing.driver.OutOfProcess import net.corda.testing.node.User import rx.Observable import java.nio.file.Path -import javax.validation.constraints.NotNull interface NodeHandleInternal : NodeHandle { val configuration: NodeConfiguration diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/CrlServer.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/CrlServer.kt index b6dee805fa..48cd6279ac 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/CrlServer.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/CrlServer.kt @@ -2,6 +2,10 @@ package net.corda.testing.node.internal.network +import jakarta.ws.rs.GET +import jakarta.ws.rs.Path +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.Response import net.corda.core.crypto.Crypto import net.corda.core.internal.CertRole import net.corda.core.internal.toX500Name @@ -24,11 +28,11 @@ import org.bouncycastle.asn1.x509.DistributionPointName import org.bouncycastle.asn1.x509.Extension import org.bouncycastle.asn1.x509.GeneralName import org.bouncycastle.asn1.x509.GeneralNames +import org.eclipse.jetty.ee10.servlet.ServletContextHandler +import org.eclipse.jetty.ee10.servlet.ServletHolder import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.ServerConnector -import org.eclipse.jetty.server.handler.HandlerCollection -import org.eclipse.jetty.servlet.ServletContextHandler -import org.eclipse.jetty.servlet.ServletHolder +import org.eclipse.jetty.server.handler.ContextHandlerCollection import org.glassfish.jersey.server.ResourceConfig import org.glassfish.jersey.servlet.ServletContainer import java.io.Closeable @@ -40,10 +44,6 @@ import java.security.cert.X509Certificate import java.time.Duration import java.util.* import javax.security.auth.x500.X500Principal -import javax.ws.rs.GET -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.Response import kotlin.collections.ArrayList class CrlServer(hostAndPort: NetworkHostAndPort) : Closeable { @@ -79,7 +79,7 @@ class CrlServer(hostAndPort: NetworkHostAndPort) : Closeable { } private val server: Server = Server(InetSocketAddress(hostAndPort.host, hostAndPort.port)).apply { - handler = HandlerCollection().apply { + handler = ContextHandlerCollection().apply { addHandler(buildServletContextHandler()) } } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt index 80023384cf..0c6986707b 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt @@ -1,5 +1,15 @@ package net.corda.testing.node.internal.network +import jakarta.ws.rs.Consumes +import jakarta.ws.rs.GET +import jakarta.ws.rs.POST +import jakarta.ws.rs.Path +import jakarta.ws.rs.PathParam +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.core.Response +import jakarta.ws.rs.core.Response.ok +import jakarta.ws.rs.core.Response.status import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SignedData import net.corda.core.identity.CordaX500Name @@ -14,11 +24,11 @@ import net.corda.nodeapi.internal.crypto.CertificateAndKeyPair import net.corda.nodeapi.internal.network.NetworkMap import net.corda.nodeapi.internal.network.ParametersUpdate import net.corda.testing.common.internal.testNetworkParameters +import org.eclipse.jetty.ee10.servlet.ServletContextHandler +import org.eclipse.jetty.ee10.servlet.ServletHolder import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.ServerConnector -import org.eclipse.jetty.server.handler.HandlerCollection -import org.eclipse.jetty.servlet.ServletContextHandler -import org.eclipse.jetty.servlet.ServletHolder +import org.eclipse.jetty.server.handler.ContextHandlerCollection import org.glassfish.jersey.server.ResourceConfig import org.glassfish.jersey.servlet.ServletContainer import java.io.Closeable @@ -29,11 +39,6 @@ import java.security.SignatureException import java.time.Duration import java.time.Instant import java.util.* -import javax.ws.rs.* -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response -import javax.ws.rs.core.Response.ok -import javax.ws.rs.core.Response.status class NetworkMapServer(private val pollInterval: Duration, hostAndPort: NetworkHostAndPort = NetworkHostAndPort("localhost", 0), @@ -54,7 +59,7 @@ class NetworkMapServer(private val pollInterval: Duration, init { server = Server(InetSocketAddress(hostAndPort.host, hostAndPort.port)).apply { - handler = HandlerCollection().apply { + handler = ContextHandlerCollection().apply { addHandler(ServletContextHandler().apply { contextPath = "/" val resourceConfig = ResourceConfig().apply { diff --git a/testing/testserver/build.gradle b/testing/testserver/build.gradle index f8957799a1..3cb142654b 100644 --- a/testing/testserver/build.gradle +++ b/testing/testserver/build.gradle @@ -31,10 +31,10 @@ dependencies { implementation project(":common-logging") // Web stuff: for HTTP[S] servlets - implementation "org.eclipse.jetty:jetty-servlet:$jetty_version" - implementation "org.eclipse.jetty:jetty-webapp:$jetty_version" - implementation "javax.servlet:javax.servlet-api:${servlet_version}" - implementation "commons-fileupload:commons-fileupload:$fileupload_version" + implementation "org.eclipse.jetty.ee10:jetty-ee10-servlet:$jetty_version" + implementation "org.eclipse.jetty.ee10:jetty-ee10-webapp:$jetty_version" + //implementation "javax.servlet:javax.servlet-api:${servlet_version}" + implementation "org.apache.commons:commons-fileupload2-jakarta:$fileupload_version" // Log4J: logging framework (with SLF4J bindings) implementation "org.apache.logging.log4j:log4j-slf4j2-impl:$log4j_version" @@ -43,14 +43,11 @@ dependencies { // JOpt: for command line flags. implementation "net.sf.jopt-simple:jopt-simple:$jopt_simple_version" - // Jersey for JAX-RS implementation for use in Jetty - // TODO: remove force upgrade when jersey catches up - implementation "org.eclipse.jetty:jetty-continuation:${jetty_version}" - implementation "org.glassfish.jersey.core:jersey-server:$jersey_version" implementation "org.glassfish.jersey.containers:jersey-container-servlet:$jersey_version" implementation "org.glassfish.jersey.containers:jersey-container-jetty-http:$jersey_version" implementation "org.glassfish.jersey.media:jersey-media-json-jackson:$jersey_version" + implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version" // For rendering the index page. implementation "org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.12" diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/api/APIServer.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/api/APIServer.kt index 1476cd6982..e217eece0b 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/api/APIServer.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/api/APIServer.kt @@ -1,15 +1,15 @@ package net.corda.webserver.api +import jakarta.ws.rs.GET +import jakarta.ws.rs.Path +import jakarta.ws.rs.Produces +import jakarta.ws.rs.core.MediaType +import jakarta.ws.rs.core.Response import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateAndRef import net.corda.core.identity.Party import net.corda.core.utilities.NetworkHostAndPort import java.time.LocalDateTime -import javax.ws.rs.GET -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response /** * Top level interface to external interaction with the distributed ledger. diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/converters/Converters.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/converters/Converters.kt index ec08dff4a6..a4e907e0a3 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/converters/Converters.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/converters/Converters.kt @@ -1,10 +1,10 @@ package net.corda.webserver.converters +import jakarta.ws.rs.ext.ParamConverter +import jakarta.ws.rs.ext.ParamConverterProvider +import jakarta.ws.rs.ext.Provider import net.corda.core.identity.CordaX500Name import java.lang.reflect.Type -import javax.ws.rs.ext.ParamConverter -import javax.ws.rs.ext.ParamConverterProvider -import javax.ws.rs.ext.Provider object CordaX500NameConverter : ParamConverter { override fun toString(value: CordaX500Name) = value.toString() diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/APIServerImpl.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/APIServerImpl.kt index b166a143ea..7e9cbe21c9 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/APIServerImpl.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/APIServerImpl.kt @@ -1,12 +1,12 @@ package net.corda.webserver.internal +import jakarta.ws.rs.core.Response import net.corda.core.contracts.ContractState import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.vaultQueryBy import net.corda.webserver.api.APIServer import java.time.LocalDateTime import java.time.ZoneId -import javax.ws.rs.core.Response class APIServerImpl(val rpcOps: CordaRPCOps) : APIServer { override fun serverTime(): LocalDateTime { diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/AllExceptionMapper.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/AllExceptionMapper.kt index 3530b74e56..3760c3e54c 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/AllExceptionMapper.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/AllExceptionMapper.kt @@ -1,9 +1,9 @@ package net.corda.webserver.internal +import jakarta.ws.rs.core.Response +import jakarta.ws.rs.ext.ExceptionMapper +import jakarta.ws.rs.ext.Provider import net.corda.core.utilities.loggerFor -import javax.ws.rs.core.Response -import javax.ws.rs.ext.ExceptionMapper -import javax.ws.rs.ext.Provider // Provides basic exception logging to all APIs @Provider diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt index 52dce3a5b7..076437e774 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt @@ -14,12 +14,12 @@ import net.corda.webserver.WebServerConfig import net.corda.webserver.converters.CordaConverterProvider import net.corda.webserver.services.WebServerPluginRegistry import net.corda.webserver.servlets.* +import org.eclipse.jetty.ee10.servlet.DefaultServlet +import org.eclipse.jetty.ee10.servlet.ServletContextHandler +import org.eclipse.jetty.ee10.servlet.ServletHolder import org.eclipse.jetty.server.* +import org.eclipse.jetty.server.handler.ContextHandlerCollection import org.eclipse.jetty.server.handler.ErrorHandler -import org.eclipse.jetty.server.handler.HandlerCollection -import org.eclipse.jetty.servlet.DefaultServlet -import org.eclipse.jetty.servlet.ServletContextHandler -import org.eclipse.jetty.servlet.ServletHolder import org.eclipse.jetty.util.ssl.SslContextFactory import org.glassfish.jersey.server.ResourceConfig import org.glassfish.jersey.server.ServerProperties @@ -30,7 +30,6 @@ import java.io.Writer import java.lang.reflect.InvocationTargetException import java.net.BindException import java.util.* -import javax.servlet.http.HttpServletRequest class NodeWebServer(val config: WebServerConfig) { private companion object { @@ -60,7 +59,7 @@ class NodeWebServer(val config: WebServerConfig) { private fun initWebServer(localRpc: CordaRPCOps): Server { // Note that the web server handlers will all run concurrently, and not on the node thread. - val handlerCollection = HandlerCollection() + val handlerCollection = ContextHandlerCollection() // API, data upload and download to services (attachments, rates oracles etc) handlerCollection.addHandler(buildServletContextHandler(localRpc)) @@ -72,7 +71,7 @@ class NodeWebServer(val config: WebServerConfig) { httpsConfiguration.outputBufferSize = 32768 httpsConfiguration.addCustomizer(SecureRequestCustomizer()) @Suppress("DEPRECATION") - val sslContextFactory = SslContextFactory() + val sslContextFactory = SslContextFactory.Server() sslContextFactory.keyStorePath = config.keyStorePath sslContextFactory.setKeyStorePassword(config.keyStorePassword) sslContextFactory.setKeyManagerPassword(config.keyStorePassword) @@ -118,15 +117,15 @@ class NodeWebServer(val config: WebServerConfig) { contextPath = "/" errorHandler = object : ErrorHandler() { @Throws(IOException::class) - override fun writeErrorPageHead(request: HttpServletRequest, writer: Writer, code: Int, message: String) { - writer.write("\n") - writer.write("Corda $safeLegalName : Error $code\n") + override fun writeErrorHtmlHead(request: Request?, writer: Writer?, code: Int, message: String?) { + writer?.write("\n") + writer?.write("Corda $safeLegalName : Error $code\n") } @Throws(IOException::class) - override fun writeErrorPageMessage(request: HttpServletRequest, writer: Writer, code: Int, message: String, uri: String) { - writer.write("

Corda $safeLegalName

\n") - super.writeErrorPageMessage(request, writer, code, message, uri) + override fun writeErrorHtmlMessage(request: Request?, writer: Writer?, code: Int, message: String?, cause: Throwable?, uri: String?) { + writer?.write("

Corda $safeLegalName

\n") + super.writeErrorHtmlMessage(request, writer, code, message, cause, uri) } } setAttribute("rpc", localRpc) diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/AttachmentDownloadServlet.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/AttachmentDownloadServlet.kt index b374d842b6..7622e2bfd1 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/AttachmentDownloadServlet.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/AttachmentDownloadServlet.kt @@ -1,5 +1,10 @@ package net.corda.webserver.servlets +import jakarta.servlet.http.HttpServlet +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import jakarta.ws.rs.core.HttpHeaders +import jakarta.ws.rs.core.MediaType import net.corda.core.internal.extractFile import net.corda.core.crypto.SecureHash import net.corda.core.messaging.CordaRPCOps @@ -8,11 +13,6 @@ import java.io.FileNotFoundException import java.io.IOException import java.util.Locale import java.util.jar.JarInputStream -import javax.servlet.http.HttpServlet -import javax.servlet.http.HttpServletRequest -import javax.servlet.http.HttpServletResponse -import javax.ws.rs.core.HttpHeaders -import javax.ws.rs.core.MediaType /** * Allows the node administrator to either download full attachment zips, or individual files within those zips. diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/CorDappInfoServlet.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/CorDappInfoServlet.kt index 4f51255e8b..46267cba24 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/CorDappInfoServlet.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/CorDappInfoServlet.kt @@ -1,5 +1,8 @@ package net.corda.webserver.servlets +import jakarta.servlet.http.HttpServlet +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse import kotlinx.html.* import kotlinx.html.stream.appendHTML import net.corda.core.messaging.CordaRPCOps @@ -7,9 +10,6 @@ import net.corda.webserver.services.WebServerPluginRegistry import org.glassfish.jersey.server.model.Resource import org.glassfish.jersey.server.model.ResourceMethod import java.io.IOException -import javax.servlet.http.HttpServlet -import javax.servlet.http.HttpServletRequest -import javax.servlet.http.HttpServletResponse /** * Dumps some data about the installed CorDapps. diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt index d860d5d5a5..0db503edb0 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt @@ -1,13 +1,13 @@ package net.corda.webserver.servlets +import jakarta.servlet.http.HttpServlet +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.contextLogger -import org.apache.commons.fileupload.servlet.ServletFileUpload +import org.apache.commons.fileupload2.jakarta.JakartaServletFileUpload import java.io.IOException import java.util.* -import javax.servlet.http.HttpServlet -import javax.servlet.http.HttpServletRequest -import javax.servlet.http.HttpServletResponse /** * Uploads to the node via the [CordaRPCOps] uploadFile interface. @@ -19,7 +19,7 @@ class DataUploadServlet : HttpServlet() { @Throws(IOException::class) override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) { - val isMultipart = ServletFileUpload.isMultipartContent(req) + val isMultipart = JakartaServletFileUpload.isMultipartContent(req) val rpc = servletContext.getAttribute("rpc") as CordaRPCOps if (!isMultipart) { @@ -27,7 +27,7 @@ class DataUploadServlet : HttpServlet() { return } - val upload = ServletFileUpload() + val upload = JakartaServletFileUpload() val iterator = upload.getItemIterator(req) val messages = ArrayList() @@ -48,7 +48,7 @@ class DataUploadServlet : HttpServlet() { continue } try { - messages += rpc.uploadAttachment(item.openStream()).toString() + messages += rpc.uploadAttachment(item.inputStream).toString() } catch (e: RuntimeException) { reportError(e.toString()) continue diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ObjectMapperConfig.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ObjectMapperConfig.kt index 8dc7635944..504b9e5d63 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ObjectMapperConfig.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ObjectMapperConfig.kt @@ -1,8 +1,8 @@ package net.corda.webserver.servlets import com.fasterxml.jackson.databind.ObjectMapper -import javax.ws.rs.ext.ContextResolver -import javax.ws.rs.ext.Provider +import jakarta.ws.rs.ext.ContextResolver +import jakarta.ws.rs.ext.Provider /** * Primary purpose is to install Kotlin extensions for Jackson ObjectMapper so data classes work diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ResponseFilter.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ResponseFilter.kt index ccb7c4d6e3..2b86d9b72e 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ResponseFilter.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/servlets/ResponseFilter.kt @@ -1,10 +1,10 @@ package net.corda.webserver.servlets +import jakarta.ws.rs.container.ContainerRequestContext +import jakarta.ws.rs.container.ContainerResponseContext +import jakarta.ws.rs.container.ContainerResponseFilter +import jakarta.ws.rs.ext.Provider import java.io.IOException -import javax.ws.rs.container.ContainerRequestContext -import javax.ws.rs.container.ContainerResponseContext -import javax.ws.rs.container.ContainerResponseFilter -import javax.ws.rs.ext.Provider /** * This adds headers needed for cross site scripting on API clients.