Search in sources :

Example 1 with MandatoryRecipientsNotSupportedException

use of com.quorum.tessera.transaction.exception.MandatoryRecipientsNotSupportedException in project tessera by ConsenSys.

the class MandatoryRecipientsNotSupportedExceptionMapperTest method toResponse.

@Test
public void toResponse() {
    final MandatoryRecipientsNotSupportedException ex = new MandatoryRecipientsNotSupportedException("OUCH");
    final Response result = instance.toResponse(ex);
    assertThat(result).isNotNull();
    final String message = (String) result.getEntity();
    assertThat(message).isEqualTo("OUCH");
    assertThat(result.getStatus()).isEqualTo(403);
}
Also used : Response(jakarta.ws.rs.core.Response) MandatoryRecipientsNotSupportedException(com.quorum.tessera.transaction.exception.MandatoryRecipientsNotSupportedException) Test(org.junit.Test)

Example 2 with MandatoryRecipientsNotSupportedException

use of com.quorum.tessera.transaction.exception.MandatoryRecipientsNotSupportedException in project tessera by ConsenSys.

the class RestPayloadPublisher method publishPayload.

@Override
public void publishPayload(EncodedPayload payload, PublicKey recipientKey) {
    final NodeInfo remoteNodeInfo = discovery.getRemoteNodeInfo(recipientKey);
    final Set<String> supportedApiVersions = remoteNodeInfo.supportedApiVersions();
    final EncodedPayloadCodec preferredCodec = EncodedPayloadCodec.getPreferredCodec(supportedApiVersions);
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(preferredCodec);
    if (PrivacyMode.STANDARD_PRIVATE != payload.getPrivacyMode() && !supportedApiVersions.contains(EnhancedPrivacyVersion.API_VERSION_2)) {
        throw new EnhancedPrivacyNotSupportedException("Transactions with enhanced privacy is not currently supported on recipient " + recipientKey.encodeToBase64());
    }
    if (PrivacyMode.MANDATORY_RECIPIENTS == payload.getPrivacyMode() && !supportedApiVersions.contains(MandatoryRecipientsVersion.API_VERSION_4)) {
        throw new MandatoryRecipientsNotSupportedException("Transactions with mandatory recipients are not currently supported on recipient " + recipientKey.encodeToBase64());
    }
    final String targetUrl = remoteNodeInfo.getUrl();
    LOGGER.info("Publishing message to {}", targetUrl);
    final byte[] encoded = payloadEncoder.encode(payload);
    try (Response response = client.target(targetUrl).path("/push").request().post(Entity.entity(encoded, MediaType.APPLICATION_OCTET_STREAM_TYPE))) {
        if (Response.Status.OK.getStatusCode() != response.getStatus() && Response.Status.CREATED.getStatusCode() != response.getStatus()) {
            throw new PublishPayloadException("Unable to push payload to recipient url " + targetUrl);
        }
        LOGGER.info("Published to {}", targetUrl);
    } catch (ProcessingException ex) {
        LOGGER.debug("", ex);
        throw new NodeOfflineException(URI.create(targetUrl));
    }
}
Also used : Response(jakarta.ws.rs.core.Response) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PublishPayloadException(com.quorum.tessera.transaction.publish.PublishPayloadException) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) MandatoryRecipientsNotSupportedException(com.quorum.tessera.transaction.exception.MandatoryRecipientsNotSupportedException) NodeOfflineException(com.quorum.tessera.transaction.publish.NodeOfflineException) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) ProcessingException(jakarta.ws.rs.ProcessingException)

Aggregations

MandatoryRecipientsNotSupportedException (com.quorum.tessera.transaction.exception.MandatoryRecipientsNotSupportedException)2 Response (jakarta.ws.rs.core.Response)2 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)1 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)1 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)1 EnhancedPrivacyNotSupportedException (com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException)1 NodeOfflineException (com.quorum.tessera.transaction.publish.NodeOfflineException)1 PublishPayloadException (com.quorum.tessera.transaction.publish.PublishPayloadException)1 ProcessingException (jakarta.ws.rs.ProcessingException)1 Test (org.junit.Test)1