페이지

2020년 5월 26일 화요일

Indy SDK Java 예제 빌드 및 실행

Indy SDK Java 예제 빌드 및 실행

아래 문서를 참고하여 Ubuntu에서 Indy SDK Java 예제를 빌드하고 실행하는 실습을 진행합니다.

1. 실습 환경

2. Java 빌드 프로그램 설치

  1. Java SDK를 설치합니다.

    $ sudo apt-get install openjdk-8-jdk
    
  2. Maven을 설치합니다.

    $ sudo apt-get install maven
    

3. Java 예제 빌드

  1. Indy SDK 소스를 다운로드합니다.

    $ cd $HOME
    $ git clone https://github.com/hyperledger/indy-sdk.git
    
  2. Java 예제를 빌드합니다.

    $ cd $HOME/indy-sdk/samples/java
    $ mvn package
    

4. 테스트

  1. Indy 노드 풀을 실행합니다.

    $ cd $HOME/indy-sdk
    $ docker build -f ci/indy-pool.dockerfile -t indy_pool .
    $ docker run -itd -p 9701-9708:9701-9708 indy_pool
    
  2. Java 예제를 실행합니다.

    $ mvn exec:java -Dexec.mainClass=Main
    

    정상적인 실행 결과는 아래와 같은 메시지를 출력합니다.

    Anoncreds sample -> started
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    Anoncreds sample -> completed
    Anoncreds Revocation sample -> started
    Anoncreds Revocation sample -> completed
    Ledger sample -> started
    Ledger sample -> completed
    Crypto sample -> started
    Crypto sample -> completed
    Endorser sample -> started
    Endorser sample -> completed
    

    Indy 노드 풀이 실행중이 아닐 경우 아래와 같은 TimeoutException 오류 메시지가 출력됩니다.

    Anoncreds sample -> started
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    [WARNING] 
    java.util.concurrent.ExecutionException: org.hyperledger.indy.sdk.ledger.TimeoutException: Timeout happens for ledger operation.
        at java.util.concurrent.CompletableFuture.reportGet (CompletableFuture.java:395)
        at java.util.concurrent.CompletableFuture.get (CompletableFuture.java:1999)
        at Anoncreds.demo (Anoncreds.java:27)
        at Main.main (Main.java:4)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke (Method.java:566)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
        at java.lang.Thread.run (Thread.java:834)
    Caused by: org.hyperledger.indy.sdk.ledger.TimeoutException: Timeout happens for ledger operation.
        at org.hyperledger.indy.sdk.IndyException.fromSdkError (IndyException.java:164)
        at org.hyperledger.indy.sdk.IndyJava$API.checkResult (IndyJava.java:92)
        at org.hyperledger.indy.sdk.pool.Pool.access$100 (Pool.java:20)
        at org.hyperledger.indy.sdk.pool.Pool$1.callback (Pool.java:52)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke (Method.java:566)
        at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback (CallbackReference.java:520)
        at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback (CallbackReference.java:551)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    
  3. Indy 노드 풀 주소를 TEST_POOL_ID 환경변수에 지정하여 Java 예제를 실행할 수 있습니다.

    export TEST_POOL_IP=192.168.56.110
    $ mvn exec:java -Dexec.mainClass=Main
    

    이전에 다른 주소의 Indy 노드 풀에 접근하다가 실패한 적이 있다면 위와 같이 주소를 변경하여 실행할 때 아래와 같은 PoolLedgerConfigExistsException 오류 메시지가 발생할 수 있습니다.

    Anoncreds sample -> started
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    [WARNING] 
    java.util.concurrent.ExecutionException: org.hyperledger.indy.sdk.pool.PoolLedgerConfigExistsException: A pool ledger configuration already exists with the specified name.
        at java.util.concurrent.CompletableFuture.reportGet (CompletableFuture.java:395)
        at java.util.concurrent.CompletableFuture.get (CompletableFuture.java:1999)
        at utils.PoolUtils.createPoolLedgerConfig (PoolUtils.java:48)
        at Anoncreds.demo (Anoncreds.java:26)
        at Main.main (Main.java:4)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke (Method.java:566)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
        at java.lang.Thread.run (Thread.java:834)
    Caused by: org.hyperledger.indy.sdk.pool.PoolLedgerConfigExistsException: A pool ledger configuration already exists with the specified name.
        at org.hyperledger.indy.sdk.IndyException.fromSdkError (IndyException.java:162)
        at org.hyperledger.indy.sdk.IndyJava$API.checkResult (IndyJava.java:92)
        at org.hyperledger.indy.sdk.pool.Pool.access$400 (Pool.java:20)
        at org.hyperledger.indy.sdk.pool.Pool$2.callback (Pool.java:70)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke (Method.java:566)
        at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback (CallbackReference.java:520)
        at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback (CallbackReference.java:551)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    

    이럴 경우에는 $HOME/.indy_client 폴더를 지우고 다시 실행합니다.

Written with StackEdit.

댓글 없음:

댓글 쓰기

국어 맞춤법 참고 자료

  제목 설명(인용) 출처 IT 글쓰기와 번역 노트 IT 기술 문서 및 서적을 집필/번역/교정하면서 얻은 경험/정보/지식을 공유합니다. 전뇌해커 [우리말 바루기] ‘대로’의 띄어쓰기 명사 뒤에서는 붙여 쓰고, 그 외에는 띄어 쓴다고 생각하면 쉽다. 다...