mirror of
https://github.com/corda/corda.git
synced 2025-05-31 22:50:53 +00:00
Retire FileUploader and subtypes (#1154)
This commit is contained in:
parent
3fbc5fe555
commit
42e29d3b22
@ -213,10 +213,6 @@ interface CordaRPCOps : RPCOps {
|
|||||||
*/
|
*/
|
||||||
fun uploadAttachment(jar: InputStream): SecureHash
|
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.
|
* 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.
|
* This will store the upgrade authorisation in the vault, and will be queried by [ContractUpgradeFlow.Acceptor] during contract upgrade process.
|
||||||
|
@ -211,8 +211,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
// TODO Remove this once the cash stuff is in its own CorDapp
|
// TODO Remove this once the cash stuff is in its own CorDapp
|
||||||
registerInitiatedFlow(IssuerFlow.Issuer::class.java)
|
registerInitiatedFlow(IssuerFlow.Issuer::class.java)
|
||||||
|
|
||||||
initUploaders()
|
|
||||||
|
|
||||||
runOnStop += network::stop
|
runOnStop += network::stop
|
||||||
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
|
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
|
||||||
smm.start()
|
smm.start()
|
||||||
@ -478,11 +476,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
.filterNot { isAbstract(it.modifiers) }
|
.filterNot { isAbstract(it.modifiers) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initUploaders() {
|
|
||||||
_services.uploaders += attachments
|
|
||||||
cordappServices.values.filterIsInstanceTo(_services.uploaders, AcceptsFileUpload::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun makeVaultObservers() {
|
private fun makeVaultObservers() {
|
||||||
VaultSoftLockManager(services.vaultService, smm)
|
VaultSoftLockManager(services.vaultService, smm)
|
||||||
ScheduledActivityObserver(services)
|
ScheduledActivityObserver(services)
|
||||||
@ -765,7 +758,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
|
|
||||||
private inner class ServiceHubInternalImpl : ServiceHubInternal, SingletonSerializeAsToken() {
|
private inner class ServiceHubInternalImpl : ServiceHubInternal, SingletonSerializeAsToken() {
|
||||||
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
|
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
|
||||||
override val uploaders = ArrayList<FileUploader>()
|
|
||||||
override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage()
|
override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage()
|
||||||
override val auditService = DummyAuditService()
|
override val auditService = DummyAuditService()
|
||||||
override val monitoringService = MonitoringService(MetricRegistry())
|
override val monitoringService = MonitoringService(MetricRegistry())
|
||||||
|
@ -148,14 +148,6 @@ class CordaRPCOpsImpl(
|
|||||||
override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class<out UpgradedContract<*, *>>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass)
|
override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class<out UpgradedContract<*, *>>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass)
|
||||||
override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state)
|
override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state)
|
||||||
override fun currentNodeTime(): Instant = Instant.now(services.clock)
|
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 waitUntilRegisteredWithNetworkMap() = services.networkMapCache.mapServiceRegistered
|
||||||
override fun partyFromKey(key: PublicKey) = services.identityService.partyFromKey(key)
|
override fun partyFromKey(key: PublicKey) = services.identityService.partyFromKey(key)
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ -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<String>
|
|
||||||
|
|
||||||
override fun accepts(type: String) = type == dataTypePrefix
|
|
||||||
}
|
|
@ -23,7 +23,6 @@ import net.corda.node.services.messaging.MessagingService
|
|||||||
import net.corda.node.services.statemachine.FlowLogicRefFactoryImpl
|
import net.corda.node.services.statemachine.FlowLogicRefFactoryImpl
|
||||||
import net.corda.node.services.statemachine.FlowStateMachineImpl
|
import net.corda.node.services.statemachine.FlowStateMachineImpl
|
||||||
import net.corda.node.utilities.CordaPersistence
|
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
|
* 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()
|
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 {
|
interface ServiceHubInternal : PluginServiceHub {
|
||||||
companion object {
|
companion object {
|
||||||
private val log = loggerFor<ServiceHubInternal>()
|
private val log = loggerFor<ServiceHubInternal>()
|
||||||
@ -108,10 +89,6 @@ interface ServiceHubInternal : PluginServiceHub {
|
|||||||
val database: CordaPersistence
|
val database: CordaPersistence
|
||||||
val configuration: NodeConfiguration
|
val configuration: NodeConfiguration
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
@Deprecated("This service will be removed in a future milestone")
|
|
||||||
val uploaders: List<FileUploader>
|
|
||||||
|
|
||||||
override fun recordTransactions(txs: Iterable<SignedTransaction>) {
|
override fun recordTransactions(txs: Iterable<SignedTransaction>) {
|
||||||
val recordedTransactions = txs.filter { validatedTransactions.addTransaction(it) }
|
val recordedTransactions = txs.filter { validatedTransactions.addTransaction(it) }
|
||||||
require(recordedTransactions.isNotEmpty()) { "No transactions passed in for recording" }
|
require(recordedTransactions.isNotEmpty()) { "No transactions passed in for recording" }
|
||||||
|
@ -12,7 +12,6 @@ import net.corda.core.crypto.SecureHash
|
|||||||
import net.corda.core.node.services.AttachmentStorage
|
import net.corda.core.node.services.AttachmentStorage
|
||||||
import net.corda.core.serialization.*
|
import net.corda.core.serialization.*
|
||||||
import net.corda.core.utilities.loggerFor
|
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.database.RequeryConfiguration
|
||||||
import net.corda.node.services.persistence.schemas.requery.AttachmentEntity
|
import net.corda.node.services.persistence.schemas.requery.AttachmentEntity
|
||||||
import net.corda.node.services.persistence.schemas.requery.Models
|
import net.corda.node.services.persistence.schemas.requery.Models
|
||||||
@ -31,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe
|
|||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?)
|
class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?)
|
||||||
: AttachmentStorage, AcceptsFileUpload, SingletonSerializeAsToken() {
|
: AttachmentStorage, SingletonSerializeAsToken() {
|
||||||
companion object {
|
companion object {
|
||||||
private val log = loggerFor<NodeAttachmentService>()
|
private val log = loggerFor<NodeAttachmentService>()
|
||||||
}
|
}
|
||||||
@ -196,9 +195,4 @@ class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricReg
|
|||||||
}
|
}
|
||||||
require(count > 0) { "Stream is either empty or not a JAR/ZIP" }
|
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()
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ open class MockServiceHubInternal(
|
|||||||
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
|
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
|
||||||
override val attachments: AttachmentStorage = MockAttachmentStorage(),
|
override val attachments: AttachmentStorage = MockAttachmentStorage(),
|
||||||
override val validatedTransactions: WritableTransactionStorage = MockTransactionStorage(),
|
override val validatedTransactions: WritableTransactionStorage = MockTransactionStorage(),
|
||||||
override val uploaders: List<FileUploader> = listOf<FileUploader>(),
|
|
||||||
override val stateMachineRecordedTransactionMapping: StateMachineRecordedTransactionMappingStorage = MockStateMachineRecordedTransactionMappingStorage(),
|
override val stateMachineRecordedTransactionMapping: StateMachineRecordedTransactionMappingStorage = MockStateMachineRecordedTransactionMappingStorage(),
|
||||||
val mapCache: NetworkMapCacheInternal? = null,
|
val mapCache: NetworkMapCacheInternal? = null,
|
||||||
val scheduler: SchedulerService? = null,
|
val scheduler: SchedulerService? = null,
|
||||||
|
@ -17,7 +17,6 @@ class DataUploadServlet : HttpServlet() {
|
|||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
|
override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
|
||||||
@Suppress("DEPRECATION") // Bogus warning due to superclass static method being deprecated.
|
|
||||||
val isMultipart = ServletFileUpload.isMultipartContent(req)
|
val isMultipart = ServletFileUpload.isMultipartContent(req)
|
||||||
val rpc = servletContext.getAttribute("rpc") as CordaRPCOps
|
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")
|
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fun reportError(message: String) {
|
||||||
|
println(message) // Show in webserver window.
|
||||||
|
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message)
|
||||||
|
}
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val item = iterator.next()
|
val item = iterator.next()
|
||||||
log.info("Receiving ${item.name}")
|
log.info("Receiving ${item.name}")
|
||||||
|
val dataType = req.pathInfo.substring(1).substringBefore('/')
|
||||||
try {
|
if (dataType != "attachment") {
|
||||||
val dataType = req.pathInfo.substring(1).substringBefore('/')
|
reportError("Got a file upload request for an unknown data type $dataType")
|
||||||
@Suppress("DEPRECATION") // TODO: Replace the use of uploadFile
|
continue
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
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.
|
// Send back the hashes as a convenience for the user.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user