Search in sources :

Example 6 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class P2pClientProvider method provider.

public static P2pClient provider() {
    Config config = ConfigFactory.create().getConfig();
    SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    return new RestP2pClient(client);
}
Also used : Config(com.quorum.tessera.config.Config) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client) P2pClient(com.quorum.tessera.partyinfo.P2pClient)

Example 7 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class RecoveryClientProvider method provider.

public static RecoveryClient provider() {
    final Config config = ConfigFactory.create().getConfig();
    final ServerConfig serverConfig = config.getP2PServerConfig();
    final Map<String, String> properties = serverConfig.getProperties();
    final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
    final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    client.property("jersey.config.client.readTimeout", waitTime);
    return new RestRecoveryClient(client);
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client)

Example 8 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class ResendClientProvider method provider.

public static ResendClient provider() {
    final Config config = ConfigFactory.create().getConfig();
    final ServerConfig serverConfig = config.getP2PServerConfig();
    final Map<String, String> properties = serverConfig.getProperties();
    final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
    final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    client.property("jersey.config.client.readTimeout", waitTime);
    return new RestResendClient(client);
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client)

Example 9 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class MetricsIT method metrics.

@Test
public void metrics() {
    final PartyHelper partyHelper = PartyHelper.create();
    Set<ServerConfig> serverConfigs = partyHelper.getParties().map(Party::getConfig).map(Config::getServerConfigs).flatMap(List::stream).collect(Collectors.toUnmodifiableSet());
    ClientFactory clientFactory = new ClientFactory();
    for (ServerConfig serverConfig : serverConfigs) {
        Client c = clientFactory.buildFrom(serverConfig);
        Response response = c.target(serverConfig.getServerUri()).path("metrics").request().get();
        assertThat(response).isNotNull();
        assertThat(response.getStatus()).isEqualTo(200);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) PartyHelper(com.quorum.tessera.test.PartyHelper) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 10 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class PeerToPeerIT method benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo.

@Test
public void benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo() throws Exception {
    Party partyB = partyHelper.findByAlias(NodeAlias.B);
    ServerConfig serverConfig = partyB.getConfig().getP2PServerConfig();
    PublicKey publicKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    Recipient itself = Recipient.of(publicKey, serverConfig.getServerUri().toString());
    String validKeyFromOtherNode = partyHelper.findByAlias(NodeAlias.C).getPublicKey();
    PublicKey validButIncorrectKey = Optional.of(validKeyFromOtherNode).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    String workingUrlFromSomeOtherNode = partyHelper.findByAlias(NodeAlias.D).getConfig().getP2PServerConfig().getServerAddress();
    Recipient badRecipient = Recipient.of(validButIncorrectKey, workingUrlFromSomeOtherNode);
    Set<Recipient> recipients = Stream.of(itself, badRecipient).collect(Collectors.toSet());
    assertThat(recipients).containsExactlyInAnyOrder(itself, badRecipient);
    PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), recipients, Collections.emptySet());
    Client client = new ClientFactory().buildFrom(serverConfig);
    PartyInfoParser partyInfoParser = PartyInfoParser.create();
    byte[] data = partyInfoParser.to(partyInfo);
    StreamingOutput output = out -> out.write(data);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) PublicKey(com.quorum.tessera.encryption.PublicKey) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)10 Client (jakarta.ws.rs.client.Client)10 Config (com.quorum.tessera.config.Config)9 ServerConfig (com.quorum.tessera.config.ServerConfig)6 Response (jakarta.ws.rs.core.Response)4 Test (org.junit.Test)4 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)3 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)3 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)3 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)3 Recipient (com.quorum.tessera.partyinfo.model.Recipient)3 ClientSSLContextFactory (com.quorum.tessera.ssl.context.ClientSSLContextFactory)3 SSLContextFactory (com.quorum.tessera.ssl.context.SSLContextFactory)3 JsonObject (jakarta.json.JsonObject)3 Entity (jakarta.ws.rs.client.Entity)3 MediaType (jakarta.ws.rs.core.MediaType)3