Search in sources :

Example 1 with APPLICATION_OCTET_STREAM

use of jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM in project tessera by ConsenSys.

the class RecoveryResource method push.

// path /push with application/octet-stream is overloaded (RecoveryResource &
// TransactionResource); swagger annotations cannot handle situations like this so hide this
// operation and use TransactionResource::push to document both
@Hidden
@POST
@Path("push")
@Consumes(APPLICATION_OCTET_STREAM)
public Response push(final byte[] payload, @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers) {
    LOGGER.debug("Received push request during recovery mode");
    final Set<String> versions = Optional.ofNullable(headers).orElse(emptyList()).stream().filter(Objects::nonNull).flatMap(v -> Arrays.stream(v.split(","))).collect(Collectors.toSet());
    final EncodedPayloadCodec codec = EncodedPayloadCodec.getPreferredCodec(versions);
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(codec);
    final EncodedPayload encodedPayload = payloadEncoder.decode(payload);
    if (encodedPayload.getPrivacyMode() != PrivacyMode.STANDARD_PRIVATE) {
        return Response.status(Response.Status.FORBIDDEN).entity("Transactions with enhanced privacy are not accepted during recovery mode").build();
    }
    final MessageHash messageHash = transactionManager.storePayload(encodedPayload);
    LOGGER.debug("Push request generated hash {}", messageHash);
    return Response.status(Response.Status.CREATED).entity(Objects.toString(messageHash)).build();
}
Also used : java.util(java.util) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) HeaderParam(jakarta.ws.rs.HeaderParam) LoggerFactory(org.slf4j.LoggerFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PushBatchRequest(com.quorum.tessera.p2p.recovery.PushBatchRequest) Valid(jakarta.validation.Valid) NotNull(jakarta.validation.constraints.NotNull) Path(jakarta.ws.rs.Path) Operation(io.swagger.v3.oas.annotations.Operation) Response(jakarta.ws.rs.core.Response) APPLICATION_OCTET_STREAM(jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) MessageHash(com.quorum.tessera.data.MessageHash) Constants(com.quorum.tessera.shared.Constants) Consumes(jakarta.ws.rs.Consumes) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Logger(org.slf4j.Logger) Hidden(io.swagger.v3.oas.annotations.Hidden) POST(jakarta.ws.rs.POST) Collections.emptyList(java.util.Collections.emptyList) TransactionManager(com.quorum.tessera.transaction.TransactionManager) Collectors(java.util.stream.Collectors) Tag(io.swagger.v3.oas.annotations.tags.Tag) APPLICATION_JSON(jakarta.ws.rs.core.MediaType.APPLICATION_JSON) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Hidden(io.swagger.v3.oas.annotations.Hidden)

Aggregations

MessageHash (com.quorum.tessera.data.MessageHash)1 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)1 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)1 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)1 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)1 PushBatchRequest (com.quorum.tessera.p2p.recovery.PushBatchRequest)1 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)1 Constants (com.quorum.tessera.shared.Constants)1 TransactionManager (com.quorum.tessera.transaction.TransactionManager)1 Hidden (io.swagger.v3.oas.annotations.Hidden)1 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 Tag (io.swagger.v3.oas.annotations.tags.Tag)1 Valid (jakarta.validation.Valid)1 NotNull (jakarta.validation.constraints.NotNull)1 Consumes (jakarta.ws.rs.Consumes)1 HeaderParam (jakarta.ws.rs.HeaderParam)1 POST (jakarta.ws.rs.POST)1 Path (jakarta.ws.rs.Path)1 APPLICATION_JSON (jakarta.ws.rs.core.MediaType.APPLICATION_JSON)1