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();
}
Aggregations