Code Monkey home page Code Monkey logo

fabric-gateway-java's Introduction

Hyperledger Fabric Gateway SDK for Java Build status

Note: This API is deprecated as of Fabric v2.5. When developing applications for Hyperledger Fabric v2.4 and later, you should use the Fabric Gateway client API.

The Fabric Gateway SDK allows applications to interact with a Fabric blockchain network. It provides a simple API to submit transactions to a ledger or query the contents of a ledger with minimal code.

The Gateway SDK implements the Fabric programming model as described in the Developing Applications chapter of the Fabric documentation.

How to use

The following shows a complete code sample of how to connect to a fabric network, submit a transaction and query the ledger state using an instantiated smart contract (fabcar sample).

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeoutException;

import org.hyperledger.fabric.gateway.Contract;
import org.hyperledger.fabric.gateway.ContractException;
import org.hyperledger.fabric.gateway.Gateway;
import org.hyperledger.fabric.gateway.Network;
import org.hyperledger.fabric.gateway.Wallet;
import org.hyperledger.fabric.gateway.Wallets;

class Sample {
    public static void main(String[] args) throws IOException {
        // Load an existing wallet holding identities used to access the network.
        Path walletDirectory = Paths.get("wallet");
        Wallet wallet = Wallets.newFileSystemWallet(walletDirectory);

        // Path to a common connection profile describing the network.
        Path networkConfigFile = Paths.get("connection.json");

        // Configure the gateway connection used to access the network.
        Gateway.Builder builder = Gateway.createBuilder()
                .identity(wallet, "user1")
                .networkConfig(networkConfigFile);

        // Create a gateway connection
        try (Gateway gateway = builder.connect()) {

            // Obtain a smart contract deployed on the network.
            Network network = gateway.getNetwork("mychannel");
            Contract contract = network.getContract("fabcar");

            // Submit transactions that store state to the ledger.
            byte[] createCarResult = contract.createTransaction("createCar")
                    .submit("CAR10", "VW", "Polo", "Grey", "Mary");
            System.out.println(new String(createCarResult, StandardCharsets.UTF_8));

            // Evaluate transactions that query state from the ledger.
            byte[] queryAllCarsResult = contract.evaluateTransaction("queryAllCars");
            System.out.println(new String(queryAllCarsResult, StandardCharsets.UTF_8));

        } catch (ContractException | TimeoutException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

API documentation

Full Javadoc documentation is published for each of the following versions:

Maven

Add the following dependency to your project's pom.xml file:

<dependency>
  <groupId>org.hyperledger.fabric</groupId>
  <artifactId>fabric-gateway-java</artifactId>
  <version>2.2.0</version>
</dependency>

Gradle

Add the following dependency to your project's build.gradle file:

implementation 'org.hyperledger.fabric:fabric-gateway-java:2.2.0'

Compatibility

The following table shows versions of Fabric, Java and other dependencies that are explicitly tested and that are supported for use with version 2.2 of the Fabric Gateway SDK. Refer to the appropriate GitHub branch for compatibility of other release versions.

Tested Supported
Fabric 2.2 2.2
Java 8, 11, 17 8+
Platform Ubuntu 22.04

Client applications running on POWER architecture

To run Java SDK clients on IBM POWER systems (e.g. zLinux), use Java 11 and set the SSL provider to ‘JDK’ by either supplying the -D command line option:

-Dorg.hyperledger.fabric.sdk.connections.ssl.sslProvider=JDK

or with the environment variable set as follows:

ORG_HYPERLEDGER_FABRIC_SDK_CONNECTIONS_SSL_SSLPROVIDER=JDK

Building and testing

git clone https://github.com/hyperledger/fabric-gateway-java.git
cd fabric-gateway-java
mvn install

The mvn install command will download the dependencies and run all the unit tests and scenario tests. It will also generate all the crypto material required by these tests.

Docker is required to run the scenario tests.

Unit tests

All classes and methods have a high coverage (~90%) of unit tests. These are written using the JUnit, AssertJ and Mockito frameworks.

Scenario tests

Scenario tests are written using the Cucumber BDD framework.

fabric-gateway-java's People

Contributors

andrew-coleman avatar bestbeforetoday avatar heatherlp avatar jt-nti avatar jwagantall avatar mergify[bot] avatar mrudav-shukla avatar paranjan avatar rameshthoomu avatar ryjones avatar sambhavdutt avatar tijohnson avatar yoshiteru-imamura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fabric-gateway-java's Issues

org.hyperledger.fabric.gateway.ContractException: error in simulation: transaction returned with failure: Undefined contract called

I exported the connection profile and wallet from IBP(IBM Blockchain Platform VSCode Extension) as my application configuration.

when I used the fabric-gateway-java v2.2.0 reported this error when invoking the chaincode I developed in IBP:

org.hyperledger.fabric.gateway.ContractException: error in simulation: transaction returned with failure: **Undefined contract called** at org.hyperledger.fabric.gateway.impl.query.SingleQueryHandler.evaluate(SingleQueryHandler.java:50) at org.hyperledger.fabric.gateway.impl.TransactionImpl.evaluate(TransactionImpl.java:220) at org.hyperledger.fabric.gateway.impl.ContractImpl.evaluateTransaction(ContractImpl.java:55)

I'm pretty sure the called method is defined in the contract, and I can successfully call it in IBP.

anyone can help me fix it?

It takes time to close gateway

There seems to be a 3 second wait on shutdown for managedchannel.
Therefore, the wait time increases with the number of peers.

Is there anything I can do to shorten the shutdown time?

Is it possible to select true as the argument for channel.shutdown in networkimpl.close?

Gateway.close->NetworkImpl.close->Channel.shutdown...PeerEventServiceClient.shutdown->lchannel.shutdown().awaitTermination(3,TimeUnit.SECONDS)

It takes time to close gateway

There seems to be a 3 second wait on shutdown for managedchannel.
Therefore, the wait time increases with the number of peers.

Is there anything I can do to shorten the shutdown time?

Can you shorten the waiting time?

Gateway.close->NetworkImpl.close->Channel.shutdown...PeerEventServiceClient.shutdown->lchannel.shutdown().awaitTermination(3,TimeUnit.SECONDS)

java.nio.file.NoSuchFileException: src\main\resources\crypto-config\peerOrganizations\org1.example.com\users\[email protected]\msp\signcerts\[email protected]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gateway' defined in class path resource [com/trace/app/config/fabric/HyperLedgerFabricGatewayConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hyperledger.fabric.gateway.Gateway]: Factory method 'gateway' threw exception; nested exception is java.nio.file.NoSuchFileException: src\main\resources\crypto-config\peerOrganizations\org1.example.com\users\[email protected]\msp\signcerts\[email protected]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
at com.trace.app.TraceApplication.main(TraceApplication.java:16) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hyperledger.fabric.gateway.Gateway]: Factory method 'gateway' threw exception; nested exception is java.nio.file.NoSuchFileException: src\main\resources\crypto-config\peerOrganizations\org1.example.com\users\[email protected]\msp\signcerts\[email protected]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
... 20 common frames omitted
Caused by: java.nio.file.NoSuchFileException: src\main\resources\crypto-config\peerOrganizations\org1.example.com\users\[email protected]\msp\signcerts\[email protected]
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79) ~[na:1.8.0_311]
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97) ~[na:1.8.0_311]
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102) ~[na:1.8.0_311]
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230) ~[na:1.8.0_311]
at java.nio.file.Files.newByteChannel(Files.java:361) ~[na:1.8.0_311]
at java.nio.file.Files.newByteChannel(Files.java:407) ~[na:1.8.0_311]
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384) ~[na:1.8.0_311]
at java.nio.file.Files.newInputStream(Files.java:152) ~[na:1.8.0_311]
at java.nio.file.Files.newBufferedReader(Files.java:2784) ~[na:1.8.0_311]
at com.trace.app.config.fabric.HyperLedgerFabricGatewayConfig.gateway(HyperLedgerFabricGatewayConfig.java:29) ~[classes/:na]
at com.trace.app.config.fabric.HyperLedgerFabricGatewayConfig$$EnhancerBySpringCGLIB$$af71f747.CGLIB$gateway$0() ~[classes/:na]
at com.trace.app.config.fabric.HyperLedgerFabricGatewayConfig$$EnhancerBySpringCGLIB$$af71f747$$FastClassBySpringCGLIB$$cbd155e0.invoke() ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
at com.trace.app.config.fabric.HyperLedgerFabricGatewayConfig$$EnhancerBySpringCGLIB$$af71f747.gateway() ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_311]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_311]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_311]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_311]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE]
... 21 common frames omitted

java.lang.NoSuchFieldError: id_RSASSA_PSS_SHAKE128

Use fabric-gateway-java to connect Fabric BlockChain throw this error:


Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hyperledger.fabric.gateway.Network]: Circular reference involving containing bean 'fabricConf' - consider declaring the factory method as static for independence from its containing instance. Factory method 'gainNetwork' threw exception; nested exception is java.lang.NoSuchFieldError: id_RSASSA_PSS_SHAKE128
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.1.jar!/:5.3.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.3.1.jar!/:5.3.1]
        ... 41 common frames omitted
Caused by: java.lang.NoSuchFieldError: id_RSASSA_PSS_SHAKE128
        at org.bouncycastle.operator.DefaultSignatureNameFinder.<clinit>(Unknown Source) ~[bcpkix-jdk15on-1.70.jar!/:1.70.00.0]
        at org.bouncycastle.operator.jcajce.OperatorHelper.<clinit>(Unknown Source) ~[bcpkix-jdk15on-1.70.jar!/:1.70.00.0]
        at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.<init>(Unknown Source) ~[bcpkix-jdk15on-1.70.jar!/:1.70.00.0]
        at org.hyperledger.fabric.sdk.security.certgen.TLSCertificateBuilder.createSelfSignedCertificate(TLSCertificateBuilder.java:125) ~[fabric-sdk-java-2.2.11.jar!/:na]
        at org.hyperledger.fabric.sdk.security.certgen.TLSCertificateBuilder.createCert(TLSCertificateBuilder.java:99) ~[fabric-sdk-java-2.2.11.jar!/:na]
        at org.hyperledger.fabric.sdk.security.certgen.TLSCertificateBuilder.clientCert(TLSCertificateBuilder.java:78) ~[fabric-sdk-java-2.2.11.jar!/:na]
        at org.hyperledger.fabric.sdk.Channel.addPeer(Channel.java:668) ~[fabric-sdk-java-2.2.11.jar!/:na]
        at org.hyperledger.fabric.gateway.impl.GatewayImpl.getNetwork(GatewayImpl.java:245) ~[fabric-gateway-java-2.2.0.jar!/:na]
        at com.example.czdemo.config.FabricConf.gainNetwork(FabricConf.java:77) ~[classes!/:0.0.1]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.1.jar!/:5.3.1]
        ... 42 common frames omitted

Use Centos 7.5 OS

builder.connect() does not connect properly unless within Java main.class (peer name resolution)

Hi,

I used to be able to place the following in a non-main class and just call it from anywhere with no issue. It would connect just fine and work as expected. (continue reading after the code snippet)

public class App {

	static {
		System.setProperty("org.hyperledger.fabric.sdk.service_discovery.as_localhost", "true");
	}

public App () {

		// Load a file system based wallet for managing identities.
		Path walletPath = Paths.get("wallet");
		Wallet wallet = Wallets.newFileSystemWallet(walletPath);
		// load a CCP
		Path networkConfigPath = Paths.get("connection-org1.yaml");

		// Configure the gateway connection used to access the network.
		Gateway.Builder builder = Gateway.createBuilder().identity(wallet, "alo").networkConfig(networkConfigPath);

		// Create a gateway connection
		Gateway gateway = builder.connect();

}
.....
....

However, it does not work properly now unless placed within a Java main class. Otherwise, it would produce a weird error that says something like unresolved DNS name, code: Unavailable node ..... something of this sort. It outputs multiple lines of errors related to gPRC library

I checked whether it is able to read the connection profile and so forth. everything seems just fine. It is able to connect but is not able to resolve peers names.

This issue only happens when executing the gateway connection outside the main class. For example by calling the class that contains the logic of the gateway connection.

tested with a local deployed test-network fabric 2.2 and 2.3. The java project on runs on the local machine as well.

Any resolution to this issue?

Copy constructor of GatewayImpl doesn't copy HFClient configuration properly

Regarding https://github.com/hyperledger/fabric-gateway-java/blob/main/src/main/java/org/hyperledger/fabric/gateway/impl/GatewayImpl.java#L206

When copying the gateway, a new HFClient instance is created. The channel config and crypto suite are not copied over.

Reproduction snippit

        final var gateway1 = new GatewayImpl.Builder()
                .identity(identity)
                .networkConfig(networkConfigFile)
                .connect();
        HFClient client1 = gateway1.getClient();
        client1.setCryptoSuite(myCryptoSuite);
        client1.loadChannelFromConfig("channelName", myNetworkConfig);

        // Copy gateway
        final var gateway2 = gateway1.newInstance();
        final var client2 = gateway2.getClient();

        // We expect client2 to have the same configuration as client1
        Assertions.assertEquals(myCryptoSuite, client2.getCryptoSuite());
        Assertions.assertEquals(myNetworkConfig, client2.getChannel("channelName"));

Context

The GatewayImpl#newInstance is called when ReplayListenerSession is constructed. Thus, whenever calling Contract#addContractListener (with an existing Checkpointer), the HFClient instance used will be the default one, which may not necessarily connect properly.

java.lang.UnsatisfiedLinkError in spring boot application

I am trying to build spring boot application with connection to hyperledger and receive java.lang.UnsatisfiedLinkError while trying to connect to blockchain.
build.gradle

plugins {
    id "org.springframework.boot" version "2.7.5"
    id "io.spring.dependency-management" version "1.1.0"
    id 'java'
    id "io.freefair.lombok" version "6.4.3"
}

group = 'com.plastic'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.hyperledger.fabric:fabric-gateway-java:2.1.1'
    implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.48.Final'


    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

Stacktrace

Error: failed to load the required native library] with root cause
java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_x86_64, netty_tcnative_linux_x86_64_fedora, netty_tcnative_x86_64, netty_tcnative]
        at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:114)
        at io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:710)
        at io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:149)
        at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:194)
        at org.hyperledger.fabric.sdk.Endpoint.getSslContextBuilder(Endpoint.java:294)
        at org.hyperledger.fabric.sdk.Endpoint.<init>(Endpoint.java:254)
        at org.hyperledger.fabric.sdk.Endpoint.createEndpoint(Endpoint.java:487)
        at org.hyperledger.fabric.sdk.Peer.setTLSCertificateKeyPair(Peer.java:447)
        at org.hyperledger.fabric.sdk.Channel.addPeer(Channel.java:669)
        at org.hyperledger.fabric.gateway.impl.GatewayImpl.getNetwork(GatewayImpl.java:245)
        *****
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:779)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:833)
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_linux_x86_64
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105)
                ... 61 common frames omitted
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative_linux_x86_64.so
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186)
                ... 62 common frames omitted
                Suppressed: java.lang.NoClassDefFoundError: Could not initialize class io.netty.internal.tcnative.SSL
                        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
                        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
                        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
                        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
                        at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
                        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287)
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 62 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_linux_x86_64_fedora
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105)
                ... 61 common frames omitted
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative_linux_x86_64_fedora.so
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186)
                ... 62 common frames omitted
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_linux_x86_64_fedora in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 62 common frames omitted
                        Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_linux_x86_64_fedora in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                                at java.base/java.lang.System.loadLibrary(System.java:1989)
                                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:425)
                                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:417)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:383)
                                ... 63 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_x86_64
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105)
                ... 61 common frames omitted
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative_x86_64.so
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186)
                ... 62 common frames omitted
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 62 common frames omitted
                        Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                                at java.base/java.lang.System.loadLibrary(System.java:1989)
                                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:425)
                                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:417)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:383)
                                ... 63 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105)
                ... 61 common frames omitted
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative.so
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186)
                ... 62 common frames omitted
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 62 common frames omitted
                        Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
                                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                                at java.base/java.lang.System.loadLibrary(System.java:1989)
                                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:425)
                                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:417)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:383)
                                ... 63 common frames omitted

I tried update hyperledger, set boringssl static dependencies, put directly libs to java library path - nothing works. How to solve this issue?

Please update fabric-gateway-java 2.2.2 to to use cloudant-java-sdk library instead of java-cloudant

MQ has received an ASOC hit for a DOS vulnerability on gson.jar 2.8.2, which is a dependency of cloudant-client.jar 2.19.0, which in turn is a dependency of fabric-gateway-java/2.2.2. This gson issue does not appear to be associated with a CVE, but recommends upgrading to gson.jar 2.8.9, although even the latest cloudant-client.jar version (2.20.1) does not include the latest gson.jar 2.8.9 yet.

See this slack conversation:

Mark Lewis said "Cloudant (and whatever JSON data it’s parsing) is the potential attack vector, and that fabric-gateway-java only makes use of Cloudant if you are using a CouchDB database as your wallet store."

Mark Taylor said "It's interesting that the cloudant library itself is marked "deprecated" with its EOL last month - they have an alternative library that should be used . See https://github.com/cloudant/java-cloudant In this particular case, the only use we have of that library is around reading Wallet data which we permit"

Therefor could you please switch to using the newer cloudant-java-sdk library instead of java-cloudant for cloudant CouchDB wallets.

Would it be possible to update this within the next week or two, so that we can include the update in our next MQ 9.2.x CD release, and remove the gson.jar dependency DOS vulnerability, thanks.

Memory issue due to BlockEvent

Hi Everyone. I am using Fabric Java SDK v2.2 for building my fabric client. We are using the Service Discovery for connection. We observed that the BlockEvent objects are retained and after every few days the memory consumption becomes very high and we start getting Out Of Memory Exception. Has anybody faced a similar issue or can help to resolve it? Thanks in advance

Memory was retaining for
org.hyperledger.fabric.gateway.impl.event.OrderedBlockEventSource

unable to convert key pair: ECDSA KeyFactory not available

Hi,

I'm trying to implement fabric gateway as a part of a larger Java application. The application is written in Java 17, and I know that it is not yet supported according to the readme. I was hoping there is a minor workaround I can do only for the Identities part because the Java application is too big and requires a lot of refactoring just to revert it back to Java 11.

Specifically I am having problem with this part of the code:

var privateKey = Identities.readPrivateKey(keyReader);

This is the error that I am encountering right now:

image

image

Thank and I appreciate your time reading my concern.

WalletImpl::get would not close "InputStream identityData"

public Identity get(final String label) throws IOException {
    final InputStream identityData = store.get(label);     // identityData not close from FileSystemWalletStore
    if (identityData == null) {
        return null;
    }

    try {
        return deserializeIdentity(identityData);
    } catch (RuntimeException e) {
        throw new IOException(e); 
    }
    // TODO Here should close identityData when it is from FileSystemWalletStore
}

Massive thread creation on listening for events -> unable to create new native thread

Hello,

I've found a memory / thread leak when listening to blockchain events, in this case is when trying to listen for block events. Too many threads are created and an error: java.lang.OutOfMemoryError: unable to create new native thread is throwed resulting in a lock when processing events.

How to replicate Case:

I create a new channel and I execute lots of transactions in the channel so a lot of new blocks are generated > 1000. Then I start listening to that channel, using network.addBlockListener(startBlock, blockConsumer); where startBlock is = 0 and blockConsumer is a simple consumer to print the BlockEvent. When I launch the app in debug mode I see that lots of threads are created and waiting for the previous block to be processed.

image

As many threads as available blocks are being created:

image

Ending in a java.lang.OutOfMemoryError: unable to create new native thread

error

public static Properties parseGrpcUrl(String url) {
Pattern p = Pattern.compile("([^:]+)[:]//([^:]+):", Pattern.CASE_INSENSITIVE);
}

The regularity here will directly lead to errors,Please modify

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.