From 42e29d3b2284a281ead78d7fe60abed21e4f98ae Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Fri, 4 Aug 2017 15:57:11 +0100 Subject: [PATCH] Retire FileUploader and subtypes (#1154) --- .../net/corda/core/messaging/CordaRPCOps.kt | 4 --- .../net/corda/node/internal/AbstractNode.kt | 8 ------ .../corda/node/internal/CordaRPCOpsImpl.kt | 8 ------ .../node/services/api/AcceptsFileUpload.kt | 15 ----------- .../node/services/api/ServiceHubInternal.kt | 23 ---------------- .../persistence/NodeAttachmentService.kt | 8 +----- .../node/services/MockServiceHubInternal.kt | 1 - .../webserver/servlets/DataUploadServlet.kt | 26 +++++++++++-------- 8 files changed, 16 insertions(+), 77 deletions(-) delete mode 100644 node/src/main/kotlin/net/corda/node/services/api/AcceptsFileUpload.kt diff --git a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt index 5ffcbdbe6f..7ffd767b15 100644 --- a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt +++ b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt @@ -213,10 +213,6 @@ interface CordaRPCOps : RPCOps { */ fun uploadAttachment(jar: InputStream): SecureHash - // TODO: Remove this from the interface - @Deprecated("This service will be removed in a future milestone") - fun uploadFile(dataType: String, name: String?, file: InputStream): String - /** * Authorise a contract state upgrade. * This will store the upgrade authorisation in the vault, and will be queried by [ContractUpgradeFlow.Acceptor] during contract upgrade process. diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 284dfca87b..119449f811 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -211,8 +211,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, // TODO Remove this once the cash stuff is in its own CorDapp registerInitiatedFlow(IssuerFlow.Issuer::class.java) - initUploaders() - runOnStop += network::stop _networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured()) smm.start() @@ -478,11 +476,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, .filterNot { isAbstract(it.modifiers) } } - private fun initUploaders() { - _services.uploaders += attachments - cordappServices.values.filterIsInstanceTo(_services.uploaders, AcceptsFileUpload::class.java) - } - private fun makeVaultObservers() { VaultSoftLockManager(services.vaultService, smm) ScheduledActivityObserver(services) @@ -765,7 +758,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, private inner class ServiceHubInternalImpl : ServiceHubInternal, SingletonSerializeAsToken() { override val rpcFlows = ArrayList>>() - override val uploaders = ArrayList() override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage() override val auditService = DummyAuditService() override val monitoringService = MonitoringService(MetricRegistry()) diff --git a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt index 2bc78e1e2a..77fc84b277 100644 --- a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt +++ b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt @@ -148,14 +148,6 @@ class CordaRPCOpsImpl( override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass) override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state) override fun currentNodeTime(): Instant = Instant.now(services.clock) - @Suppress("OverridingDeprecatedMember", "DEPRECATION") - override fun uploadFile(dataType: String, name: String?, file: InputStream): String { - val acceptor = services.uploaders.firstOrNull { it.accepts(dataType) } - return database.transaction { - acceptor?.upload(file) ?: throw RuntimeException("Cannot find file upload acceptor for $dataType") - } - } - override fun waitUntilRegisteredWithNetworkMap() = services.networkMapCache.mapServiceRegistered override fun partyFromKey(key: PublicKey) = services.identityService.partyFromKey(key) @Suppress("DEPRECATION") diff --git a/node/src/main/kotlin/net/corda/node/services/api/AcceptsFileUpload.kt b/node/src/main/kotlin/net/corda/node/services/api/AcceptsFileUpload.kt deleted file mode 100644 index 14dafbea77..0000000000 --- a/node/src/main/kotlin/net/corda/node/services/api/AcceptsFileUpload.kt +++ /dev/null @@ -1,15 +0,0 @@ -package net.corda.node.services.api - -/** - * A service that implements AcceptsFileUpload can have new binary data provided to it via an HTTP upload. - */ -// TODO This is no longer used and can be removed -interface AcceptsFileUpload : FileUploader { - /** A string that prefixes the URLs, e.g. "attachments" or "interest-rates". Should be OK for URLs. */ - val dataTypePrefix: String - - /** What file extensions are acceptable for the file to be handed to upload() */ - val acceptableFileExtensions: List - - override fun accepts(type: String) = type == dataTypePrefix -} diff --git a/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt b/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt index f95ab30e45..12817520bb 100644 --- a/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt +++ b/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt @@ -23,7 +23,6 @@ import net.corda.node.services.messaging.MessagingService import net.corda.node.services.statemachine.FlowLogicRefFactoryImpl import net.corda.node.services.statemachine.FlowStateMachineImpl import net.corda.node.utilities.CordaPersistence -import java.io.InputStream /** * Session ID to use for services listening for the first message in a session (before a @@ -68,24 +67,6 @@ sealed class NetworkCacheError : Exception() { class DeregistrationFailed : NetworkCacheError() } -/** - * An interface that denotes a service that can accept file uploads. - */ -// TODO This is no longer used and can be removed -interface FileUploader { - /** - * Accepts the data in the given input stream, and returns some sort of useful return message that will be sent - * back to the user in the response. - */ - fun upload(file: InputStream): String - - /** - * Check if this service accepts this type of upload. For example if you are uploading interest rates this could - * be "my-service-interest-rates". Type here does not refer to file extentions or MIME types. - */ - fun accepts(type: String): Boolean -} - interface ServiceHubInternal : PluginServiceHub { companion object { private val log = loggerFor() @@ -108,10 +89,6 @@ interface ServiceHubInternal : PluginServiceHub { val database: CordaPersistence val configuration: NodeConfiguration - @Suppress("DEPRECATION") - @Deprecated("This service will be removed in a future milestone") - val uploaders: List - override fun recordTransactions(txs: Iterable) { val recordedTransactions = txs.filter { validatedTransactions.addTransaction(it) } require(recordedTransactions.isNotEmpty()) { "No transactions passed in for recording" } diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/NodeAttachmentService.kt b/node/src/main/kotlin/net/corda/node/services/persistence/NodeAttachmentService.kt index 354ebb3609..7dac06f5a0 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/NodeAttachmentService.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/NodeAttachmentService.kt @@ -12,7 +12,6 @@ import net.corda.core.crypto.SecureHash import net.corda.core.node.services.AttachmentStorage import net.corda.core.serialization.* import net.corda.core.utilities.loggerFor -import net.corda.node.services.api.AcceptsFileUpload import net.corda.node.services.database.RequeryConfiguration import net.corda.node.services.persistence.schemas.requery.AttachmentEntity import net.corda.node.services.persistence.schemas.requery.Models @@ -31,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe */ @ThreadSafe class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?) - : AttachmentStorage, AcceptsFileUpload, SingletonSerializeAsToken() { + : AttachmentStorage, SingletonSerializeAsToken() { companion object { private val log = loggerFor() } @@ -196,9 +195,4 @@ class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricReg } require(count > 0) { "Stream is either empty or not a JAR/ZIP" } } - - // Implementations for AcceptsFileUpload - override val dataTypePrefix = "attachment" - override val acceptableFileExtensions = listOf(".jar", ".zip") - override fun upload(file: InputStream) = importAttachment(file).toString() } diff --git a/node/src/test/kotlin/net/corda/node/services/MockServiceHubInternal.kt b/node/src/test/kotlin/net/corda/node/services/MockServiceHubInternal.kt index 6565680a00..62cd05bd79 100644 --- a/node/src/test/kotlin/net/corda/node/services/MockServiceHubInternal.kt +++ b/node/src/test/kotlin/net/corda/node/services/MockServiceHubInternal.kt @@ -34,7 +34,6 @@ open class MockServiceHubInternal( val identity: IdentityService? = MOCK_IDENTITY_SERVICE, override val attachments: AttachmentStorage = MockAttachmentStorage(), override val validatedTransactions: WritableTransactionStorage = MockTransactionStorage(), - override val uploaders: List = listOf(), override val stateMachineRecordedTransactionMapping: StateMachineRecordedTransactionMappingStorage = MockStateMachineRecordedTransactionMappingStorage(), val mapCache: NetworkMapCacheInternal? = null, val scheduler: SchedulerService? = null, diff --git a/webserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt b/webserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt index a81adb9a1b..e2c4c49e3d 100644 --- a/webserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt +++ b/webserver/src/main/kotlin/net/corda/webserver/servlets/DataUploadServlet.kt @@ -17,7 +17,6 @@ class DataUploadServlet : HttpServlet() { @Throws(IOException::class) override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) { - @Suppress("DEPRECATION") // Bogus warning due to superclass static method being deprecated. val isMultipart = ServletFileUpload.isMultipartContent(req) val rpc = servletContext.getAttribute("rpc") as CordaRPCOps @@ -34,20 +33,25 @@ class DataUploadServlet : HttpServlet() { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files") return } - + fun reportError(message: String) { + println(message) // Show in webserver window. + resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message) + } while (iterator.hasNext()) { val item = iterator.next() log.info("Receiving ${item.name}") - - try { - val dataType = req.pathInfo.substring(1).substringBefore('/') - @Suppress("DEPRECATION") // TODO: Replace the use of uploadFile - messages += rpc.uploadFile(dataType, item.name, item.openStream()) - log.info("${item.name} successfully accepted: ${messages.last()}") - } catch(e: RuntimeException) { - println(e) - resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got a file upload request for an unknown data type") + val dataType = req.pathInfo.substring(1).substringBefore('/') + if (dataType != "attachment") { + reportError("Got a file upload request for an unknown data type $dataType") + continue } + try { + messages += rpc.uploadAttachment(item.openStream()).toString() + } catch (e: RuntimeException) { + reportError(e.toString()) + continue + } + log.info("${item.name} successfully accepted: ${messages.last()}") } // Send back the hashes as a convenience for the user.