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

Commit 61dff3a

Browse files
bestbeforetodaymastersingh24
authored andcommitted
FABJ-531: Remove deprecated use of NettyChannelBuilder.usePlaintext(boolean)
Also update gRPC and protobuf versions, and some code hygiene. Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
1 parent 78fe1b5 commit 61dff3a

21 files changed

+106
-107
lines changed

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
<tag>fabric-sdk-java-1.0</tag>
2929
</scm>
3030
<properties>
31-
<grpc.version>1.23.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
32-
<protobuf.version>3.10.0</protobuf.version>
31+
<grpc.version>1.31.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
32+
<protobuf.version>3.12.4</protobuf.version>
3333
<bouncycastle.version>1.62</bouncycastle.version>
3434
<httpclient.version>4.5.12</httpclient.version>
35-
<javadoc.version>3.1.1</javadoc.version>
35+
<javadoc.version>3.2.0</javadoc.version>
3636
<skipITs>true</skipITs>
3737
<alpn-boot-version>8.1.7.v20160121</alpn-boot-version>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39-
<jacoco.version>0.8.2</jacoco.version>
39+
<jacoco.version>0.8.5</jacoco.version>
4040
<log4j.version>2.13.3</log4j.version>
4141
<org.hyperledger.fabric.sdktest.ITSuite>IntegrationSuite.java</org.hyperledger.fabric.sdktest.ITSuite>
4242
<gpg.executable>gpg2</gpg.executable>
@@ -249,7 +249,7 @@
249249
<plugin>
250250
<groupId>org.apache.maven.plugins</groupId>
251251
<artifactId>maven-surefire-plugin</artifactId>
252-
<version>2.19.1</version>
252+
<version>3.0.0-M5</version>
253253
<configuration>
254254
<argLine>${surefireArgLine}</argLine>
255255
<includes>
@@ -261,7 +261,7 @@
261261
<plugin>
262262
<groupId>org.apache.maven.plugins</groupId>
263263
<artifactId>maven-failsafe-plugin</artifactId>
264-
<version>2.19.1</version>
264+
<version>3.0.0-M5</version>
265265
<configuration>
266266
<argLine>${failsafeArgLine}</argLine>
267267
<includes>
@@ -290,7 +290,7 @@
290290
protobuf-java directly, you will be transitively depending on the
291291
protobuf-java version that grpc depends on.
292292
-->
293-
<protocArtifact>com.google.protobuf:protoc:3.7.1:exe:${os.detected.classifier}</protocArtifact>
293+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
294294
<pluginId>grpc-java</pluginId>
295295
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
296296
</pluginArtifact>
@@ -566,7 +566,7 @@
566566
<plugin>
567567
<groupId>org.apache.maven.plugins</groupId>
568568
<artifactId>maven-jar-plugin</artifactId>
569-
<version>3.1.2</version>
569+
<version>3.2.0</version>
570570
<configuration>
571571
<archive>
572572
<manifestEntries>
@@ -597,7 +597,7 @@
597597
<plugin>
598598
<groupId>org.owasp</groupId>
599599
<artifactId>dependency-check-maven</artifactId>
600-
<version>4.0.2</version>
600+
<version>5.3.2</version>
601601
<executions>
602602
<execution>
603603
<goals>
@@ -628,7 +628,7 @@
628628
</plugin>
629629
<plugin>
630630
<artifactId>maven-assembly-plugin</artifactId>
631-
<version>3.1.1</version> <!-- was 2.3 -->
631+
<version>3.3.0</version> <!-- was 2.3 -->
632632
<configuration>
633633
<descriptorRefs>
634634
<descriptorRef>jar-with-dependencies</descriptorRef>
@@ -663,7 +663,7 @@
663663
<plugin>
664664
<groupId>org.apache.maven.plugins</groupId>
665665
<artifactId>maven-source-plugin</artifactId>
666-
<version>3.0.1</version> <!-- was 2.2.1 -->
666+
<version>3.2.1</version> <!-- was 2.2.1 -->
667667
<executions>
668668
<execution>
669669
<id>attach-sources</id>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public String getTransactionID() {
279279
* @return epoch and -1 if filtered block.
280280
* @deprecated
281281
*/
282+
@Deprecated
282283
public long getEpoch() {
283284
return BlockInfo.this.isFiltered() ? -1 : headerDeserializer.getChannelHeader().getEpoch();
284285
}
@@ -670,6 +671,7 @@ public byte[] getSignature() {
670671
* @return
671672
* @deprecated use getId and getMspid
672673
*/
674+
@Deprecated
673675
public byte[] getEndorser() {
674676
return endorsement.getEndorser().toByteArray();
675677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Collection.CollectionConfigPackage getCollectionConfigPackage() {
5555
return collectionConfigPackage;
5656
}
5757

58-
private Collection.CollectionConfigPackage collectionConfigPackage = null;
58+
private final Collection.CollectionConfigPackage collectionConfigPackage;
5959

6060
ChaincodeCollectionConfiguration(JsonArray jsonConfig) throws ChaincodeCollectionConfigurationException {
6161

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void fromFile(File policyFile) throws IOException {
236236
* @throws ChaincodeEndorsementPolicyParseException
237237
* @deprecated use {@link #fromYamlFile(Path)}
238238
*/
239-
239+
@Deprecated
240240
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException {
241241
final Yaml yaml = new Yaml(new SafeConstructor());
242242
final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile));

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
/**
1818
* ChaincodeID identifies chaincode.
19-
* @deprecated See lifecycle install {@link LifecycleChaincodePackage}
2019
*/
2120
public final class ChaincodeID {
2221

@@ -32,7 +31,6 @@ public org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID getFabricChainco
3231

3332
/**
3433
* @return
35-
* @deprecated See lifecycle install {@link LifecycleChaincodePackage}
3634
*/
3735
public String getName() {
3836
return fabricChaincodeID.getName();
@@ -104,10 +102,8 @@ public ChaincodeID build() {
104102
/**
105103
* Chaincode builder
106104
*
107-
* @deprecated See lifecycle install {@link LifecycleChaincodePackage}
108105
* @return ChaincodeID builder.
109106
*/
110-
111107
public static Builder newBuilder() {
112108
return new Builder();
113109
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ public SDOrdererAddition getSDOrdererAddition() {
15731573

15741574
}
15751575

1576+
@SafeVarargs
15761577
private static byte[] combineCerts(Collection<byte[]>... certCollections) throws IOException {
15771578
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
15781579
for (Collection<byte[]> certCollection : certCollections) {
@@ -2313,7 +2314,7 @@ public AnchorPeersConfigUpdateResult getConfigUpdateAnchorPeers(Peer peer, User
23132314

23142315
if (!peersToAddHS.contains(s)) {
23152316
String[] split = s.split(":");
2316-
anchorPeers.addAnchorPeers(Configuration.AnchorPeer.newBuilder().setHost(split[0]).setPort(new Integer(split[1])).build());
2317+
anchorPeers.addAnchorPeers(Configuration.AnchorPeer.newBuilder().setHost(split[0]).setPort(Integer.parseInt(split[1])).build());
23172318
peersFinalHS.add(s);
23182319
}
23192320
}
@@ -2322,7 +2323,7 @@ public AnchorPeersConfigUpdateResult getConfigUpdateAnchorPeers(Peer peer, User
23222323
if (!currentAP.contains(s)) {
23232324
peersAdded.add(s);
23242325
String[] split = s.split(":");
2325-
anchorPeers.addAnchorPeers(Configuration.AnchorPeer.newBuilder().setHost(split[0]).setPort(new Integer(split[1])).build());
2326+
anchorPeers.addAnchorPeers(Configuration.AnchorPeer.newBuilder().setHost(split[0]).setPort(Integer.parseInt(split[1])).build());
23262327
peersFinalHS.add(s);
23272328
}
23282329
}
@@ -2785,7 +2786,7 @@ public Collection<Orderer> getOrderers() {
27852786
* @throws ProposalException
27862787
* @deprecated See new lifecycle chaincode management. {@link LifecycleInstallChaincodeRequest}
27872788
*/
2788-
2789+
@Deprecated
27892790
public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest) throws InvalidArgumentException, ProposalException {
27902791

27912792
return sendInstantiationProposal(instantiateProposalRequest, getChaincodePeers());
@@ -2801,6 +2802,7 @@ public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposa
28012802
* @throws ProposalException
28022803
* @deprecated See new lifecycle chaincode management. {@link LifecycleInstallChaincodeRequest}
28032804
*/
2805+
@Deprecated
28042806
public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest,
28052807
Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
28062808
checkChannelState();
@@ -2874,7 +2876,7 @@ private TransactionContext newTransactionContext(final LifecycleRequest lifecycl
28742876
* @throws ProposalException
28752877
* @throws InvalidArgumentException
28762878
*/
2877-
2879+
@Deprecated
28782880
Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest)
28792881
throws ProposalException, InvalidArgumentException {
28802882
return sendInstallProposal(installProposalRequest, getChaincodePeers());
@@ -2890,7 +2892,7 @@ Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installP
28902892
* @throws ProposalException
28912893
* @throws InvalidArgumentException
28922894
*/
2893-
2895+
@Deprecated
28942896
Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest, Collection<Peer> peers)
28952897
throws ProposalException, InvalidArgumentException {
28962898

@@ -2933,7 +2935,7 @@ Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installP
29332935
* @throws InvalidArgumentException
29342936
* @deprecated See new Lifecycle chaincode management. {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, Peer)}
29352937
*/
2936-
2938+
@Deprecated
29372939
public Collection<ProposalResponse> sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest) throws ProposalException, InvalidArgumentException {
29382940

29392941
return sendUpgradeProposal(upgradeProposalRequest, getChaincodePeers());
@@ -2950,7 +2952,7 @@ public Collection<ProposalResponse> sendUpgradeProposal(UpgradeProposalRequest u
29502952
* @throws InvalidArgumentException
29512953
* @deprecated See new Lifecycle chaincode management. {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, Peer)}
29522954
*/
2953-
2955+
@Deprecated
29542956
public Collection<ProposalResponse> sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest, Collection<Peer> peers)
29552957
throws InvalidArgumentException, ProposalException {
29562958

@@ -6426,8 +6428,11 @@ public byte[] serializeChannel() throws IOException, InvalidArgumentException {
64266428

64276429
@Override
64286430
protected void finalize() throws Throwable {
6429-
shutdown(true);
6430-
super.finalize();
6431+
try {
6432+
shutdown(true);
6433+
} finally {
6434+
super.finalize();
6435+
}
64316436
}
64326437

64336438
/**

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.concurrent.CompletionException;
1919
import java.util.concurrent.TimeUnit;
2020

21-
import com.spotify.futures.CompletableFuturesExtra;
21+
import com.spotify.futures.ListenableFuturesExtra;
2222
import io.grpc.ManagedChannel;
2323
import io.grpc.ManagedChannelBuilder;
2424
import org.apache.commons.logging.Log;
@@ -119,7 +119,7 @@ public CompletableFuture<ProposalResponsePackage.ProposalResponse> sendProposalA
119119
return ret;
120120
}
121121

122-
CompletableFuture<ProposalResponsePackage.ProposalResponse> future = CompletableFuturesExtra.toCompletableFuture(futureStub.processProposal(proposal));
122+
CompletableFuture<ProposalResponsePackage.ProposalResponse> future = ListenableFuturesExtra.toCompletableFuture(futureStub.processProposal(proposal));
123123

124124
return future.exceptionally(throwable -> {
125125
throw new CompletionException(format("%s %s", toString, throwable.getMessage()), throwable);
@@ -136,7 +136,7 @@ public CompletableFuture<Protocol.Response> sendDiscoveryRequestAsync(Protocol.S
136136
return ret;
137137
}
138138

139-
CompletableFuture<Protocol.Response> future = CompletableFuturesExtra.toCompletableFuture(discoveryFutureStub.discover(signedRequest));
139+
CompletableFuture<Protocol.Response> future = ListenableFuturesExtra.toCompletableFuture(discoveryFutureStub.discover(signedRequest));
140140
return future.exceptionally(throwable -> {
141141
throw new CompletionException(format("%s %s", toString, throwable.getMessage()), throwable);
142142
});
@@ -163,11 +163,15 @@ boolean isChannelActive() {
163163
}
164164

165165
@Override
166-
public void finalize() {
167-
if (!shutdown) {
168-
logger.warn(toString() + " finalized not shutdown is Active" + isChannelActive());
169-
}
166+
public void finalize() throws Throwable {
167+
try {
168+
if (!shutdown) {
169+
logger.warn(toString() + " finalized not shutdown is Active" + isChannelActive());
170+
}
170171

171-
shutdown(true);
172+
shutdown(true);
173+
} finally {
174+
super.finalize();
175+
}
172176
}
173177
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class Endpoint {
237237

238238
try {
239239
if (protocol.equalsIgnoreCase("grpc")) {
240-
this.channelBuilder = NettyChannelBuilder.forAddress(addr, port).usePlaintext(true);
240+
this.channelBuilder = NettyChannelBuilder.forAddress(addr, port).negotiationType(NegotiationType.PLAINTEXT);
241241
addNettyBuilderProps(channelBuilder, properties);
242242
} else if (protocol.equalsIgnoreCase("grpcs")) {
243243
if (pemBytes == null) {
@@ -361,7 +361,7 @@ private void addNettyBuilderProps(NettyChannelBuilder channelBuilder, Properties
361361
parmsArray = (Object[]) parmsArrayO;
362362
}
363363

364-
Class<?>[] classParms = new Class[parmsArray.length];
364+
Class<?>[] classParms = new Class<?>[parmsArray.length];
365365
int i = -1;
366366
for (Object oparm : parmsArray) {
367367
++i;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public Channel getChannel(String name) {
446446
* @return InstallProposalRequest
447447
* @deprecated see {@link #newLifecycleQueryInstalledChaincodesRequest()}
448448
*/
449+
@Deprecated
449450
public InstallProposalRequest newInstallProposalRequest() {
450451
return new InstallProposalRequest(userContext);
451452
}
@@ -645,7 +646,7 @@ public Collection<LifecycleQueryInstalledChaincodesProposalResponse> sendLifecyc
645646
* @deprecated See {@link LifecycleCommitChaincodeDefinitionRequest } for defining the chaincode and
646647
* and then {@link TransactionProposalRequest#setInit(boolean)} to do the initialization if it's required by the chaincode.
647648
*/
648-
649+
@Deprecated
649650
public InstantiateProposalRequest newInstantiationProposalRequest() {
650651
return new InstantiateProposalRequest(userContext);
651652
}
@@ -654,7 +655,7 @@ public InstantiateProposalRequest newInstantiationProposalRequest() {
654655
* @return {@link UpgradeProposalRequest}
655656
* @deprecated See {@link LifecycleCommitChaincodeDefinitionRequest } for defining the chaincode and
656657
* and then {@link TransactionProposalRequest#setInit(boolean)} to do the initialization if it's required by the chaincode. */
657-
658+
@Deprecated
658659
public UpgradeProposalRequest newUpgradeProposalRequest() {
659660
return new UpgradeProposalRequest(userContext);
660661
}
@@ -809,7 +810,7 @@ public Set<String> queryChannels(Peer peer) throws InvalidArgumentException, Pro
809810
* @throws ProposalException
810811
* @deprecated See {@link LifecycleQueryInstalledChaincodesRequest}
811812
*/
812-
813+
@Deprecated
813814
public List<ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException {
814815

815816
clientCheck();
@@ -881,7 +882,7 @@ public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration
881882
* @throws ProposalException
882883
* @deprecated See {@link LifecycleInstallChaincodeRequest}
883884
*/
884-
885+
@Deprecated
885886
public Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest,
886887
Collection<Peer> peers) throws ProposalException, InvalidArgumentException {
887888

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* InstallProposalRequest.
1616
* @deprecated See {@link LifecycleInstallChaincodeRequest}
1717
*/
18+
@Deprecated
1819
public class InstallProposalRequest extends TransactionRequest {
1920

2021
private File chaincodeSourceLocation = null;

0 commit comments

Comments
 (0)