【问题标题】:Running hyperledger fabric java gateway example code throws The gateway identity must be set运行 hyperledger fabric java gateway example code throws 必须设置网关身份
【发布时间】:2020-01-21 06:46:08
【问题描述】:

我正在尝试在基本网络上编写一个结构网关应用程序,我的代码如下所示。


     public static void main(String[] args) throws Exception {
       // Load a file system based wallet for managing identities.
       Path walletPath = Paths.get("wallet");
       Wallet wallet = Wallet.createFileSystemWallet(walletPath);

       // load a CCP
       Path networkConfigPath = Paths.get("..", "..", "basic-network", "connection.yaml");

       Gateway.Builder builder = Gateway.createBuilder();
       builder.identity(wallet, "user1");
       builder.networkConfig(networkConfigPath).discovery(true);

       // create a gateway connection
       try (Gateway gateway = builder.connect()) {
          System.out.println("Hello");
       }
       catch(Exception e) {
          e.printStackTrace();
     }
   }

当我运行代码时,它会抛出错误

Exception in thread "main" java.lang.IllegalStateException: The gateway identity must be set

请帮我看看如何设置这个网络的身份?

我的 connection.yaml 是

name: basic-network
version: 1.0.0
client:
    organization: Org1
    connection:
        timeout:
            peer:
                endorser: '300'
            orderer: '300'
channels:
    mychannel:
        orderers:
        - orderer.example.com
        peers:
            peer0.org1.example.com: {}
organizations:
    Org1:
        mspid: Org1MSP
        peers:
        - peer0.org1.example.com
        certificateAuthorities:
        - ca.example.com
orderers:
    orderer.example.com:
        url: grpc://localhost:7050
peers:
    peer0.org1.example.com:
        url: grpc://localhost:7051
certificateAuthorities:
    ca.example.com:
        url: http://localhost:7054
        caName: ca.example.com

basic-network/crypto-config/peerOrganizations/org1.example.com/users/中有一个名为User1@org1.example.com的文件夹

【问题讨论】:

  • 你能使用调试模式并了解是什么函数启动了这个异常吗?你也可以发布你的connection.yaml吗?您是否先生成了 user1 证书?
  • @RicNtt builder.connect() 函数抛出错误,我在问题描述中添加了详细信息。

标签: hyperledger-fabric hyperledger-fabric-sdk-java


【解决方案1】:

好的,我了解您的问题。您从织物样本中错误地运行了 fabcar 示例。

在 Java 文件夹中有 2 个目录:walletsrc。 在 src 中你会找到你的代码,而在钱包中你会存储你的用户证书。

在运行应用程序之前,您应该创建证书并且您目前没有证书。 在您运行 ClientApp.java 的文件夹中,您应该找到另外 2 个文件:EnrollAdmin.javaRegisterUser.java

首先,运行 EnrollAdmin.java。这将联系您的 CA 并为管理员用户获取证书。 接下来,运行 RegisterUser.java 来创建用户证书。

您的 ClientApp 目前正在寻找 user1 证书,但您的钱包文件夹中没有 user1。 这样做之后,再次运行 ClientApp.java 就可以了。 在您的评论中,您提到了 basic-network/crypto-config/peerOrganizations/org1.example.com/users/ 中的 User1@org1.example.com 文件夹,但您不应在此示例中使用它,因为您需要与 CA 联系的 SDK 发布的 X509 证书。

【讨论】:

  • 感谢您的回答。我对你关于 X509 证书的答案的最后一部分仍有疑问,你的意思是这个例子不支持 X509 证书吗?我必须在非 X509 认证的网络中运行这个应用程序?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
相关资源
最近更新 更多