Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Netty dependency #587

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ Add the following dependency to your project's `pom.xml` file:

```xml
<dependency>
<groupId>org.hyperledger.fabric</groupId>
<artifactId>fabric-gateway</artifactId>
<version>1.1.0</version>
<groupId>org.hyperledger.fabric</groupId>
<artifactId>fabric-gateway</artifactId>
<version>1.2.2</version>
</dependency>
```

A suitable gRPC channel service provider must also be specified (as described in the [gRPC security documentation](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#transport-security-tls)), such as:

```xml
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.54.1</version>
<scope>runtime</scope>
</dependency>
```

Expand All @@ -37,7 +48,13 @@ Add the following dependency to your project's `pom.xml` file:
Add the following dependency to your project's `build.gradle` file:

```groovy
implementation 'org.hyperledger.fabric:fabric-gateway:1.1.0'
implementation 'org.hyperledger.fabric:fabric-gateway:1.2.2'
```

A suitable gRPC channel service provider must also be specified (as described in the [gRPC security documentation](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#transport-security-tls)), such as:

```groovy
runtimeOnly 'io.grpc:grpc-netty-shaded:1.54.1'
```

## Compatibility
Expand Down
13 changes: 7 additions & 6 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaVersion>8</javaVersion>
<grpcVersion>1.54.0</grpcVersion>
<protobufVersion>3.21.12</protobufVersion> <!-- keep in step with the version used by io.grpc:grpc-protobuf -->
<grpcVersion>1.54.1</grpcVersion>
<protobufVersion>3.21.12</protobufVersion> <!-- keep major/minor version in step with one used by io.grpc:grpc-protobuf -->
<enforceJavaVersion>1.8</enforceJavaVersion> <!-- this is overridden in the release profile -->
<bouncyCastleVersion>1.72</bouncyCastleVersion>
<bouncyCastleVersion>1.73</bouncyCastleVersion>
<skipUnitTests>${skipTests}</skipUnitTests>
</properties>

Expand All @@ -50,14 +50,14 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.11.2</version>
<version>7.12.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.9.2</version>
<version>5.9.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -130,6 +130,7 @@
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down Expand Up @@ -372,7 +373,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.9.3</version>
<version>10.10.0</version>
</dependency>
</dependencies>
</plugin>
Expand Down
6 changes: 3 additions & 3 deletions java/src/main/javadoc/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
the ledger state using an instantiated smart contract.</p>

<pre><code>
import io.grpc.Grpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.TlsChannelCredentials;
import org.hyperledger.fabric.client.*;
import org.hyperledger.fabric.client.identity.*;

Expand All @@ -38,8 +39,7 @@
PrivateKey privateKey = Identities.readPrivateKey(keyReader);
Signer signer = Signers.newPrivateKeySigner(privateKey);

ManagedChannel grpcChannel = ManagedChannelBuilder.forAddress("gateway.example.org", 1337)
.usePlaintext()
ManagedChannel grpcChannel = Grpc.newChannelBuilder("gateway.example.org:1337", TlsChannelCredentials.create())
.build();

Gateway.Builder builder = Gateway.newInstance()
Expand Down
13 changes: 6 additions & 7 deletions java/src/test/java/scenario/ScenarioSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.grpc.ChannelCredentials;
import io.grpc.Grpc;
import io.grpc.ManagedChannel;
import io.grpc.Status;
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import io.grpc.TlsChannelCredentials;
import org.hyperledger.fabric.client.ChaincodeEvent;
import org.hyperledger.fabric.client.GatewayException;
import org.hyperledger.fabric.client.identity.Identities;
Expand Down Expand Up @@ -330,11 +330,10 @@ public void createGatewayWithoutSigner(String name, String user, String mspId) t
@Given("I connect the gateway to {word}")
public void connectGateway(String name) throws Exception {
ConnectionInfo info = peerConnectionInfo.get(name);
SslContext sslContext = GrpcSslContexts.forClient()
.trustManager(Files.newInputStream(Paths.get(info.tlsRootCertPath)))
ChannelCredentials credentials = TlsChannelCredentials.newBuilder()
.trustManager(Paths.get(info.tlsRootCertPath).toFile())
.build();
ManagedChannel channel = NettyChannelBuilder.forTarget(info.url)
.sslContext(sslContext)
ManagedChannel channel = Grpc.newChannelBuilder(info.url, credentials)
.overrideAuthority(info.serverNameOverride)
.build();
currentGateway.connect(channel);
Expand Down