Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES-2299: Remove the old rest-client module #6208

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libs/corda-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dependencies {
implementation project(':libs:permissions:permission-endpoint')
implementation project(':libs:permissions:permission-password')
implementation project(':libs:rest:json-serialization')
implementation project(':libs:rest:rest-client')
implementation project(':libs:rest:generated-rest-client')
implementation project(':libs:virtual-node:cpi-upload-endpoints')
implementation project(':libs:virtual-node:virtual-node-endpoints')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
package net.corda.sdk.rest

import net.corda.libs.configuration.exception.WrongConfigVersionException
import net.corda.rest.RestResource
import net.corda.rest.annotations.RestApiVersion
import net.corda.rest.client.RestClient
import net.corda.rest.client.RestConnectionListener
import net.corda.rest.client.config.RestClientConfig
import net.corda.rest.client.exceptions.ClientSslHandshakeException
import net.corda.rest.exception.ResourceAlreadyExistsException
import net.corda.sdk.network.OnboardFailedException
import net.corda.utilities.debug
import net.corda.utilities.trace
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.MalformedURLException
import java.net.URL
import kotlin.reflect.KClass
import kotlin.system.exitProcess
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand All @@ -28,79 +18,6 @@ object RestClientUtils {
private val maxWait: Duration = 10.seconds
private val cooldownInterval: Duration = 2.seconds

/**
* Create a restClient to set HTTP requests to a Corda instance
* @param restResource the class of the Rest Resource you want to use
* @param apiVersion the Corda RestApiVersion, defaults to 5.0.0.0 value
* @param insecure allow insecure requests, false by default
* @param minimumServerProtocolVersion integer value used in client config, default is 1
* @param username the REST username, has default value
* @param password the REST password, has default value
* @param targetUrl the base of the REST URL, has default value
* @return a RestClient of your specified class type
*/
@Suppress("LongParameterList")
fun <I : RestResource> createRestClient(
restResource: KClass<I>,
apiVersion: RestApiVersion = RestApiVersion.C5_0,
insecure: Boolean = false,
minimumServerProtocolVersion: Int = 1,
username: String = "admin",
password: String = "admin",
targetUrl: String = "https://localhost:8888"
): RestClient<I> {
validateTargetUrl(targetUrl)
val localTargetUrl = if (targetUrl.endsWith("/")) {
targetUrl.dropLast(1)
} else {
targetUrl
}
val restClient = RestClient(
baseAddress = "$localTargetUrl/api/${apiVersion.versionPath}/",
restResource.java,
RestClientConfig()
.enableSSL(true)
.secureSSL(!insecure)
.minimumServerProtocolVersion(minimumServerProtocolVersion)
.username(username)
.password(password),
healthCheckInterval = 0
)

restClient.addConnectionListener(ConnectionListener())
return restClient
}

private class ConnectionListener<I : RestResource> : RestConnectionListener<I> {
override fun onConnect(context: RestConnectionListener.RestConnectionContext<I>) {
// do nothing
}

override fun onDisconnect(context: RestConnectionListener.RestConnectionContext<I>) {
// do nothing
}

override fun onPermanentFailure(context: RestConnectionListener.RestConnectionContext<I>) {
when (context.throwableOpt) {
is ClientSslHandshakeException -> {
errOut.error(
"Unable to verify server's SSL certificate. " +
"Please check the target parameter or use '--insecure' option."
)
exitProcess(1)
}
}
}
}

private fun validateTargetUrl(url: String) {
try {
URL(url)
} catch (e: MalformedURLException) {
throw IllegalArgumentException("Error: Invalid target URL")
}
}

/**
* Retry a given block of code until we time out
* @param waitDuration the overall Duration to wait got before timing out, has default value
Expand Down
13 changes: 0 additions & 13 deletions libs/rest/rest-client/README.md

This file was deleted.

47 changes: 0 additions & 47 deletions libs/rest/rest-client/build.gradle

This file was deleted.

5 changes: 0 additions & 5 deletions libs/rest/rest-client/detekt-baseline.xml

This file was deleted.

This file was deleted.

This file was deleted.

Loading