Skip to content

Commit

Permalink
Fix a bug where providers headers was not correctly set for `ClientV2…
Browse files Browse the repository at this point in the history
…`. (#264)

* Fix a bug where additional headers were not set for clientv2.

* Changelog.

* Fix examples project dep version.
  • Loading branch information
MilkywayPirate authored Sep 18, 2023
1 parent 9847b47 commit 8104419
Show file tree
Hide file tree
Showing 39 changed files with 114 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased changes
- Fix a bug that caused custom http headers to be set for `ClientV2`.

## 5.0.0

Expand Down
2 changes: 1 addition & 1 deletion concordium-sdk-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>5.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
17 changes: 14 additions & 3 deletions concordium-sdk/src/main/java/com/concordium/sdk/ClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import io.grpc.ManagedChannel;
import jdk.nashorn.internal.runtime.options.Option;
import lombok.val;

import java.io.File;
Expand Down Expand Up @@ -76,16 +77,26 @@ public final class ClientV2 {

public static ClientV2 from(final Connection connection) throws ClientInitializationException {
try {
return new ClientV2(connection.getTimeout(), connection.newChannel());
return new ClientV2(connection.getTimeout(), connection.newChannel(), Optional.ofNullable(connection.getCredentials()));
} catch (IOException e) {
throw ClientInitializationException.from(e);
}
}

ClientV2(final int timeout, final ManagedChannel channel) {
/**
* Construct a new client
* @param timeout The timeout in milliseconds.
* @param channel the underlying grpc channel.
* @param credentials Optionally extra headers.
*/
ClientV2(final int timeout, final ManagedChannel channel, final Optional<Credentials> credentials) {
this.timeout = timeout;
this.channel = channel;
this.blockingStub = QueriesGrpc.newBlockingStub(channel);
if (credentials.isPresent()) {
this.blockingStub = QueriesGrpc.newBlockingStub(channel).withCallCredentials(credentials.get().getCallCredentials());
} else {
this.blockingStub = QueriesGrpc.newBlockingStub(channel);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -68,7 +70,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -59,7 +61,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -68,7 +70,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.concordium.sdk.transactions.Hash;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import io.grpc.CallCredentials;
import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
Expand All @@ -19,6 +20,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -86,7 +89,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -58,7 +60,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void setUp() throws IOException {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -160,7 +162,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.Rule;
import org.junit.Test;

import java.util.Optional;

import static com.concordium.sdk.ClientV2MapperExtensions.to;
import static com.concordium.sdk.ClientV2MapperExtensions.toTransactionHash;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -134,7 +136,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
Expand Down Expand Up @@ -635,7 +636,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
Expand Down Expand Up @@ -243,7 +244,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -74,7 +76,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -63,7 +65,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.Rule;
import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -188,7 +190,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -92,7 +94,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -96,7 +98,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -88,7 +90,7 @@ public void setUp() throws Exception {
.forName(serverName).directExecutor().addService(serviceImpl).build().start());
ManagedChannel channel = grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build());
client = new ClientV2(10000, channel);
client = new ClientV2(10000, channel, Optional.empty());
}

@Test
Expand Down
Loading

0 comments on commit 8104419

Please sign in to comment.