【问题标题】:No installed Cordapp and localhost:1009/api returns a 404 via Http未安装 Cordapp 和 localhost:1009/api 通过 Http 返回 404
【发布时间】:2020-06-01 23:16:08
【问题描述】:

我正在尝试为 CorDapp 公开 API,但未显示函数。 我正在使用命令 ./runnodes 启动节点。构建过程是成功的。 WebserverPluginRegistry 也实现了。 但是,如果我尝试使用 http://localhost:10009/ 连接到 Web 服务器,我会收到消息“未安装自定义 Cordapp”。如果插件为空,我应该只收到此消息。但是Plugin不是空的!

如果我尝试使用http://localhost:10009/api/XXX/me 连接节点网络服务器端点,我会收到错误消息:HTTP ERROR 404 Problem access api/XXX/me Reason: Not found

我知道这很模糊,但我找不到任何指示特定区域的错误。任何帮助将不胜感激。

TransactionAPI.kt

package com.YYY.api

import ……

val SERVICE_NAMES = listOf("Notary", "Network Map Service")

// This API is accessible from /api/XXX. All paths specified below are relative to it.
@Path("XXX")
class TransactionApi(private val rpcOps: CordaRPCOps) {
    private val myLegalName: CordaX500Name = rpcOps.nodeInfo().legalIdentities.first().name

    companion object {
        private val logger: Logger = loggerFor<TransactionApi>()
    }

    /**
     * Returns the node's name.
     */
    @GET
    @Path("me")
    @Produces(MediaType.APPLICATION_JSON)
    fun whoami() = mapOf("me" to myLegalName)

    /**
     * Returns all parties registered with the [NetworkMapService]. These names can be used to look up identities
     * using the [IdentityService].
     */
    @GET
    @Path("peers")
    @Produces(MediaType.APPLICATION_JSON)
    fun getPeers(): Map<String, List<CordaX500Name>> {
        val nodeInfo = rpcOps.networkMapSnapshot()
        return mapOf("peers" to nodeInfo
                .map { it.legalIdentities.first().name }
                //filter out myself, notary and eventual network map started by driver
                .filter { it.organisation !in (SERVICE_NAMES + myLegalName.organisation)})
    }

    /**
     * Displays all XYZ that exist in the node's vault.
     */
    @GET
    @Path("XYZ")
    @Produces(MediaType.APPLICATION_JSON)
    fun getXYZ() = rpcOps.vaultQueryBy<XYZ>().states


`

WebserverPluginRegistry

# Register a ServiceLoader service extending from net.corda.webserver.services.WebServerPluginRegistry.
com.XXX.plugin.TransactionPlugin

事务插件

package com.XXX.plugin

import com.XXX.api.TransactionApi
import net.corda.core.messaging.CordaRPCOps
import net.corda.webserver.services.WebServerPluginRegistry
import java.util.function.Function


class TransactionPlugin : WebServerPluginRegistry {

    // A list of classes that exposes web APIs.
    override val webApis:   List<Function<CordaRPCOps, out Any>> = listOf(Function(::TransactionApi))

    // A list of directories in the resources directory that will be served by Jetty under /web.
    override val staticServeDirs = mapOf(
            "XXX" to javaClass.classLoader.getResource("XXXWeb").toExternalForm()
    )

}

【问题讨论】:

  • 你能在 GitHub 上分享你的代码吗?你有没有像这样注册你的插件? github.com/corda/cordapp-example/blob/release-V3/kotlin-source/…
  • 我的插件注册在:....cordapp\src\main\resources\META-INF.services\net.corda.webserver.services.WebServerPluginRegistry
  • 可以把插件文件和WebServerPluginRegistry文件的内容贴出来吗?
  • 已经更新

标签: api plugins webserver http-status-code-404 corda


【解决方案1】:

这是一个重复的问题。你可以找到答案in this question


对于 2020 年之前的任何用户,Corda 网络服务器已弃用。

我们现在推荐用户使用 Spring boot。您可以查看this project 为例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-23
    • 2021-03-11
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    相关资源
    最近更新 更多