Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 043af87

Browse files
FGJ-111: Minimise explicit gRPC dependencies (#135)
The versions of transient dependencies resolved were not consistent in some consuming projects; particularly projects built with Gradle rather than Maven. This inconsistency caused errors at runtime. This change removes some explicit dependencies on packages that are also transient dependencies to avoid these dependency resolution issues. Also update dependency versions and some minor code tidy-up. Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
1 parent 66aecdf commit 043af87

35 files changed

+99
-176
lines changed

pom.xml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
<url>http://github.com/hyperledger/fabric-sdk-java</url>
2828
</scm>
2929
<properties>
30-
<grpc.version>1.35.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
31-
<protobuf.version>3.12.4</protobuf.version>
32-
<bouncycastle.version>1.62</bouncycastle.version>
30+
<grpc.version>1.38.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
31+
<protobuf.version>3.17.3</protobuf.version>
32+
<bouncycastle.version>1.69</bouncycastle.version>
3333
<httpclient.version>4.5.13</httpclient.version>
3434
<javadoc.version>3.2.0</javadoc.version>
3535
<skipITs>true</skipITs>
@@ -81,9 +81,14 @@
8181
<version>4.13.1</version>
8282
<scope>test</scope>
8383
</dependency>
84+
<dependency>
85+
<groupId>io.netty</groupId>
86+
<artifactId>netty-tcnative-boringssl-static</artifactId>
87+
<version>2.0.39.Final</version>
88+
</dependency>
8489
<dependency>
8590
<groupId>io.grpc</groupId>
86-
<artifactId>grpc-netty</artifactId>
91+
<artifactId>grpc-netty-shaded</artifactId>
8792
<version>${grpc.version}</version>
8893
</dependency>
8994
<dependency>
@@ -96,17 +101,12 @@
96101
<artifactId>grpc-stub</artifactId>
97102
<version>${grpc.version}</version>
98103
</dependency>
99-
<dependency>
100-
<groupId>io.netty</groupId>
101-
<artifactId>netty-tcnative-boringssl-static</artifactId>
102-
<version>2.0.34.Final</version>
103-
</dependency>
104-
<dependency>
105-
<groupId>io.netty</groupId>
106-
<artifactId>netty-codec-http2</artifactId>
107-
<version>4.1.60.Final</version>
104+
<dependency> <!-- necessary for Java 9+ -->
105+
<groupId>org.apache.tomcat</groupId>
106+
<artifactId>annotations-api</artifactId>
107+
<version>6.0.53</version>
108+
<scope>provided</scope>
108109
</dependency>
109-
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
110110
<dependency>
111111
<groupId>com.google.protobuf</groupId>
112112
<artifactId>protobuf-java</artifactId>
@@ -117,7 +117,6 @@
117117
<artifactId>protobuf-java-util</artifactId>
118118
<version>${protobuf.version}</version>
119119
</dependency>
120-
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
121120
<dependency>
122121
<groupId>org.bouncycastle</groupId>
123122
<artifactId>bcpkix-jdk15on</artifactId>

src/main/java/org/hyperledger/fabric/sdk/BlockDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class BlockDeserializer {
3131
private final Block block;
32-
private final Map<Integer, WeakReference<EnvelopeDeserializer>> envelopes = Collections.synchronizedMap(new WeakHashMap<Integer, WeakReference<EnvelopeDeserializer>>());
32+
private final Map<Integer, WeakReference<EnvelopeDeserializer>> envelopes = Collections.synchronizedMap(new WeakHashMap<>());
3333

3434
public Block getBlock() {
3535
return block;

src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Peer getPeer() {
8888
}
8989

9090
List<TransactionEvent> getTransactionEventsList() {
91-
ArrayList<TransactionEvent> ret = new ArrayList<TransactionEvent>(getTransactionCount());
91+
ArrayList<TransactionEvent> ret = new ArrayList<>(getTransactionCount());
9292
for (TransactionEvent transactionEvent : getTransactionEvents()) {
9393
ret.add(transactionEvent);
9494
}

src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.regex.Matcher;
3030
import java.util.regex.Pattern;
3131

32-
import io.netty.util.internal.StringUtil;
32+
import io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
3333
import org.apache.commons.io.IOUtils;
3434
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal;
3535
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPRole;

src/main/java/org/hyperledger/fabric/sdk/Channel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ private void addPeerMSPIDMap(final Peer peer) {
697697
if (!isNullOrEmpty(mspid)) {
698698
logger.debug(format("Channel %s mapping peer %s to mspid %s", name, peer, mspid));
699699
synchronized (peerMSPIDMap) {
700-
peerMSPIDMap.computeIfAbsent(mspid, k -> new HashSet<Peer>()).add(peer);
700+
peerMSPIDMap.computeIfAbsent(mspid, k -> new HashSet<>()).add(peer);
701701
}
702702
}
703703
}

src/main/java/org/hyperledger/fabric/sdk/Endpoint.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
import java.security.PrivateKey;
2727
import java.security.cert.X509Certificate;
2828
import java.util.AbstractMap;
29+
import java.util.Arrays;
2930
import java.util.Base64;
3031
import java.util.Collections;
3132
import java.util.HashMap;
3233
import java.util.Map;
3334
import java.util.Properties;
3435
import java.util.regex.Matcher;
3536
import java.util.regex.Pattern;
36-
3737
import javax.net.ssl.SSLException;
3838

3939
import com.google.common.collect.ImmutableMap;
4040
import io.grpc.ManagedChannelBuilder;
41-
import io.grpc.netty.GrpcSslContexts;
42-
import io.grpc.netty.NegotiationType;
43-
import io.grpc.netty.NettyChannelBuilder;
44-
import io.netty.handler.ssl.SslContext;
45-
import io.netty.handler.ssl.SslContextBuilder;
46-
import io.netty.handler.ssl.SslProvider;
41+
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
42+
import io.grpc.netty.shaded.io.grpc.netty.NegotiationType;
43+
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
44+
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
45+
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
46+
import io.grpc.netty.shaded.io.netty.handler.ssl.SslProvider;
4747
import org.apache.commons.codec.binary.Hex;
4848
import org.apache.commons.logging.Log;
4949
import org.apache.commons.logging.LogFactory;
@@ -73,7 +73,7 @@ class Endpoint {
7373
private final String url;
7474
private byte[] clientTLSCertificateDigest;
7575
private byte[] tlsClientCertificatePEMBytes;
76-
private NettyChannelBuilder channelBuilder = null;
76+
private NettyChannelBuilder channelBuilder;
7777

7878
private static final Map<String, String> CN_CACHE = Collections.synchronizedMap(new HashMap<>());
7979

@@ -392,15 +392,8 @@ private void addNettyBuilderProps(NettyChannelBuilder channelBuilder, Properties
392392
method.invoke(channelBuilder, parmsArray);
393393

394394
if (logger.isTraceEnabled()) {
395-
StringBuilder sb = new StringBuilder(200);
396-
String sep = "";
397-
for (Object p : parmsArray) {
398-
sb.append(sep).append(p + "");
399-
sep = ", ";
400-
401-
}
402395
logger.trace(format("Endpoint with url: %s set managed channel builder method %s (%s) ", url,
403-
method, sb.toString()));
396+
method, Arrays.toString(parmsArray)));
404397

405398
}
406399

src/main/java/org/hyperledger/fabric/sdk/HFClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ExecutorService getExecutorService() {
7272
if (null == executorService) { // no other thread has done it ...
7373
executorService = new ThreadPoolExecutor(CLIENT_THREAD_EXECUTOR_COREPOOLSIZE, CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE,
7474
CLIENT_THREAD_EXECUTOR_KEEPALIVETIME, CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT,
75-
new SynchronousQueue<Runnable>(),
75+
new SynchronousQueue<>(),
7676
r -> {
7777
Thread t = threadFactory.newThread(r);
7878
t.setDaemon(true);

src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.regex.Pattern;
2121

2222
import com.google.protobuf.ByteString;
23-
import io.netty.util.internal.StringUtil;
23+
import io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
2424
import org.apache.commons.io.IOUtils;
2525
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal;
2626
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPRole;

src/main/java/org/hyperledger/fabric/sdk/Orderer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.Serializable;
2020
import java.util.Properties;
2121

22-
import io.netty.util.internal.StringUtil;
2322
import org.apache.commons.logging.Log;
2423
import org.apache.commons.logging.LogFactory;
2524
import org.hyperledger.fabric.protos.common.Common;
@@ -54,7 +53,7 @@ public class Orderer implements Serializable {
5453

5554
Orderer(String name, String url, Properties properties) throws InvalidArgumentException {
5655

57-
if (StringUtil.isNullOrEmpty(name)) {
56+
if (isNullOrEmpty(name)) {
5857
throw new InvalidArgumentException("Invalid name for orderer");
5958
}
6059
Exception e = checkGrpcUrl(url);

src/main/java/org/hyperledger/fabric/sdk/Peer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.concurrent.ExecutorService;
2626
import java.util.concurrent.atomic.AtomicLong;
2727

28-
import io.netty.util.internal.StringUtil;
2928
import org.apache.commons.logging.Log;
3029
import org.apache.commons.logging.LogFactory;
3130
import org.hyperledger.fabric.protos.discovery.Protocol;
@@ -93,7 +92,7 @@ boolean hasConnected() {
9392

9493
}
9594

96-
if (StringUtil.isNullOrEmpty(name)) {
95+
if (isNullOrEmpty(name)) {
9796
throw new InvalidArgumentException("Invalid name for peer");
9897
}
9998

0 commit comments

Comments
 (0)