特定于Corda的Web服务器已弃用,以后将被删除

时间:2018-10-31 18:09:38

标签: corda

在我们的Mac OS上运行的节点显示__reduce_ex__(HIGHEST_PROTOCOL)信息,如下所示。这是在两台单独的计算机上发生的。

error

我应该使用Last login: Wed Oct 31 12:48:00 on ttys004 bash -c 'cd "/Users/chrisceliberti/PropertyListing/PropertyListing/PropertyListing/PropertyListing/PropertyListing/PropertyListing/build/nodes/PartyB" ; "/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/jre/bin/java" "-Dname=PartyB-corda-webserver.jar" "-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009 -javaagent:drivers/jolokia-jvm-1.3.7-agent.jar=port=7009,logHandlerClass=net.corda.webserver.JolokiaSlf4Adapter" "-jar" "corda-webserver.jar" && exit' chriss-Air-2:~ chrisceliberti$ bash -c 'cd "/Users/chrisceliberti/PropertyListing/PropertyListing/PropertyListing/PropertyListing/PropertyListing/PropertyListing/build/nodes/PartyB" ; "/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/jre/bin/java" "-Dname=PartyB-corda-webserver.jar" "-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009 -javaagent:drivers/jolokia-jvm-1.3.7-agent.jar=port=7009,logHandlerClass=net.corda.webserver.JolokiaSlf4Adapter" "-jar" "corda-webserver.jar" && exit' Listening for transport dt_socket at address: 5009 This Corda-specific web server is deprecated and will be removed in future. Please switch to a regular web framework like Spring, J2EE or Play Framework. 之类的其他Web服务器还是有其他修复程序?

1 个答案:

答案 0 :(得分:0)

您应该切换到其他Web服务器,例如Spring。

尽管Corda 3包含一个节点Web服务器,但此功能已弃用,仅出于演示目的而继续存在。您应该使用现有技术创建自己的生产级网络服务器。

请参阅Spring Webserver示例here。这是一个连接到Corda节点的Spring Web服务器。这个示例如何工作?

  1. 我们创建一个Component,该值在服务器启动时初始化,并建立与该节点的持久RPC连接:

    /**
    * Wraps a node RPC proxy.
    *
    * The RPC proxy is configured based on the properties in `application.properties`.
    *
    * @param host The host of the node we are connecting to.
    * @param rpcPort The RPC port of the node we are connecting to.
    * @param username The username for logging into the RPC client.
    * @param password The password for logging into the RPC client.
    * @property proxy The RPC proxy.
    */
    @Component
    open class NodeRPCConnection(
        @Value("\${$CORDA_NODE_HOST}") private val host: String,
        @Value("\${$CORDA_USER_NAME}") private val username: String,
        @Value("\${$CORDA_USER_PASSWORD}") private val password: String,
        @Value("\${$CORDA_RPC_PORT}") private val rpcPort: Int): AutoCloseable {
    
        lateinit var rpcConnection: CordaRPCConnection
            private set
        lateinit var proxy: CordaRPCOps
            private set
    
        @PostConstruct
        fun initialiseNodeRPCConnection() {
            val rpcAddress = NetworkHostAndPort(host, rpcPort)
            val rpcClient = CordaRPCClient(rpcAddress)
            val rpcConnection = rpcClient.start(username, password)
            proxy = rpcConnection.proxy
        }
    
        @PreDestroy
        override fun close() {
            rpcConnection.notifyServerAndClose()
        }
    }
    
  2. 我们将此Component注入到每个控制器中,并使用它与节点进行交互:

    /**
     * A CorDapp-agnostic controller that exposes standard endpoints.
     */
    @RestController
    @RequestMapping("/") // The paths for GET and POST requests are relative to this base path.
    class StandardController(private val rpc: NodeRPCConnection) {
    
        companion object {
            private val logger = LoggerFactory.getLogger(RestController::class.java)
        }
    
        private val proxy = rpc.proxy
    
        @GetMapping(value = "/status", produces = arrayOf("text/plain"))
        private fun status() = "200"
    
        @GetMapping(value = "/servertime", produces = arrayOf("text/plain"))
        private fun serverTime() = LocalDateTime.ofInstant(proxy.currentNodeTime(), ZoneId.of("UTC")).toString()
    
        @GetMapping(value = "/addresses", produces = arrayOf("text/plain"))
        private fun addresses() = proxy.nodeInfo().addresses.toString()
    
        @GetMapping(value = "/identities", produces = arrayOf("text/plain"))
        private fun identities() = proxy.nodeInfo().legalIdentities.toString()
    
        @GetMapping(value = "/platformversion", produces = arrayOf("text/plain"))
        private fun platformVersion() = proxy.nodeInfo().platformVersion.toString()
    
        @GetMapping(value = "/peers", produces = arrayOf("text/plain"))
        private fun peers() = proxy.networkMapSnapshot().flatMap { it.legalIdentities }.toString()
    
        @GetMapping(value = "/notaries", produces = arrayOf("text/plain"))
        private fun notaries() = proxy.notaryIdentities().toString()
    
        @GetMapping(value = "/flows", produces = arrayOf("text/plain"))
        private fun flows() = proxy.registeredFlows().toString()
    
        @GetMapping(value = "/states", produces = arrayOf("text/plain"))
        private fun states() = proxy.vaultQueryBy<ContractState>().states.toString()
    }