Search in sources :

Example 1 with PrivacyGroupNotSupportedException

use of com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException in project tessera by ConsenSys.

the class PrivacyGroupNotSupportedExceptionMapperTest method handleException.

@Test
public void handleException() {
    final String message = ".. all outta gum";
    final PrivacyGroupNotSupportedException exception = new PrivacyGroupNotSupportedException(message);
    final Response result = mapper.toResponse(exception);
    assertThat(result.getStatus()).isEqualTo(403);
    assertThat(result.getEntity()).isEqualTo(message);
}
Also used : Response(jakarta.ws.rs.core.Response) PrivacyGroupNotSupportedException(com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException) Test(org.junit.Test)

Example 2 with PrivacyGroupNotSupportedException

use of com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException in project tessera by ConsenSys.

the class RestPrivacyGroupPublisher method publishPrivacyGroup.

@Override
public void publishPrivacyGroup(byte[] data, PublicKey recipientKey) {
    final NodeInfo remoteNodeInfo = discovery.getRemoteNodeInfo(recipientKey);
    if (!remoteNodeInfo.supportedApiVersions().contains(PrivacyGroupVersion.API_VERSION_3)) {
        throw new PrivacyGroupNotSupportedException("Transactions with privacy group is not currently supported on recipient " + recipientKey.encodeToBase64());
    }
    final String targetUrl = remoteNodeInfo.getUrl();
    LOGGER.info("Publishing privacy group to {}", targetUrl);
    try (Response response = restClient.target(targetUrl).path("/pushPrivacyGroup").request().post(Entity.entity(data, MediaType.APPLICATION_OCTET_STREAM_TYPE))) {
        if (Response.Status.OK.getStatusCode() != response.getStatus()) {
            throw new PrivacyGroupPublishException("Unable to push privacy group to recipient url " + targetUrl);
        }
        LOGGER.info("Published privacy group to {}", targetUrl);
    } catch (ProcessingException ex) {
        LOGGER.debug("", ex);
        throw new NodeOfflineException(URI.create(targetUrl));
    }
}
Also used : Response(jakarta.ws.rs.core.Response) PrivacyGroupNotSupportedException(com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException) PrivacyGroupPublishException(com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) NodeOfflineException(com.quorum.tessera.transaction.publish.NodeOfflineException) ProcessingException(jakarta.ws.rs.ProcessingException)

Example 3 with PrivacyGroupNotSupportedException

use of com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException in project tessera by ConsenSys.

the class RestPrivacyGroupPublisherTest method remoteNodeDoesNotSupportPrivacyGroup.

@Test
public void remoteNodeDoesNotSupportPrivacyGroup() {
    String targetUrl = "url2.com";
    final List<String> versions = List.of(MultiTenancyVersion.API_VERSION_2_1);
    final NodeInfo oldNode = NodeInfo.Builder.create().withUrl(targetUrl).withRecipients(Collections.emptyList()).withSupportedApiVersions(versions).build();
    PublicKey recipient = PublicKey.from("OLD_KEY".getBytes());
    when(discovery.getRemoteNodeInfo(recipient)).thenReturn(oldNode);
    final byte[] data = new byte[] { 15 };
    try {
        publisher.publishPrivacyGroup(data, recipient);
    } catch (PrivacyGroupNotSupportedException privacyGroupNotSupportedException) {
        assertThat(privacyGroupNotSupportedException).isNotNull().hasMessageContaining(recipient.encodeToBase64());
        verify(discovery).getRemoteNodeInfo(recipient);
    }
}
Also used : PrivacyGroupNotSupportedException(com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Aggregations

PrivacyGroupNotSupportedException (com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException)3 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)2 Response (jakarta.ws.rs.core.Response)2 Test (org.junit.Test)2 PublicKey (com.quorum.tessera.encryption.PublicKey)1 PrivacyGroupPublishException (com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException)1 NodeOfflineException (com.quorum.tessera.transaction.publish.NodeOfflineException)1 ProcessingException (jakarta.ws.rs.ProcessingException)1