未安装Cordapp和localhost:1009 / api通过Http返回404

问题描述 投票:0回答:1

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

如果我尝试将节点Web服务器端点与http://localhost:10009/api/XXX/me连接,则会收到错误消息:HTTP错误404访问api / XXX / me问题,原因:未找到

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

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

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()
    )

}
api plugins webserver http-status-code-404 corda
1个回答
0
投票

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


对于2020年之前的所有用户,我们已弃用Corda网络服务器。

我们现在建议用户使用Spring Boot。您可以以this project为例。

© www.soinside.com 2019 - 2024. All rights reserved.