@Test public void partyInfoGet() { final String partyInfoJson = "{\"url\":\"http: NodeInfo partyInfo = NodeInfo.Builder.create() .withUrl("http: .withRecipients( List.of( com.quorum.tessera.partyinfo.node.Recipient.of( PublicKey.from( Base64.getDecoder() .decode( "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")), "http: com.quorum.tessera.partyinfo.node.Recipient.of( PublicKey.from( Base64.getDecoder() .decode( "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=")), "http: .build(); when(discovery.getCurrent()).thenReturn(partyInfo); when(partyStore.getParties()) .thenReturn(Set.of(URI.create("http: final Response response = partyInfoResource.getPartyInfo(); assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(200); final String output = response.getEntity().toString(); final JsonReader expected = Json.createReader(new StringReader(partyInfoJson)); final JsonReader actual = Json.createReader(new StringReader(output)); JsonObject expectedJsonObject = expected.readObject(); JsonObject actualJsonObject = actual.readObject(); assertThat(actualJsonObject.getJsonArray("keys")) .containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("keys")); assertThat(actualJsonObject.getJsonArray("peers")) .containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("peers")); assertThat(actualJsonObject.getString("url")).isEqualTo(expectedJsonObject.getString("url")); verify(discovery).getCurrent(); }
@GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) public Response getPartyInfo() { final NodeInfo current = this.discovery.getCurrent(); final JsonArrayBuilder peersBuilder = Json.createArrayBuilder(); partyStore.getParties().stream() .map(party -> Json.createObjectBuilder().add("url", party.toString()).build()) .forEach(peersBuilder::add); final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder(); current.getRecipients().stream() .map( recipient -> Json.createObjectBuilder() .add("key", recipient.getKey().encodeToBase64()) .add("url", recipient.getUrl()) .build()) .forEach(recipientBuilder::add); final String output = Json.createObjectBuilder() .add("url", current.getUrl()) .add("peers", peersBuilder.build()) .add("keys", recipientBuilder.build()) .build() .toString(); LOGGER.debug("Sending json {} from {}", output, current); return Response.status(Response.Status.OK).entity(output).build(); }
PartyInfoResource { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) public Response getPartyInfo() { final NodeInfo current = this.discovery.getCurrent(); final JsonArrayBuilder peersBuilder = Json.createArrayBuilder(); partyStore.getParties().stream() .map(party -> Json.createObjectBuilder().add("url", party.toString()).build()) .forEach(peersBuilder::add); final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder(); current.getRecipients().stream() .map( recipient -> Json.createObjectBuilder() .add("key", recipient.getKey().encodeToBase64()) .add("url", recipient.getUrl()) .build()) .forEach(recipientBuilder::add); final String output = Json.createObjectBuilder() .add("url", current.getUrl()) .add("peers", peersBuilder.build()) .add("keys", recipientBuilder.build()) .build() .toString(); LOGGER.debug("Sending json {} from {}", output, current); return Response.status(Response.Status.OK).entity(output).build(); } }
PartyInfoResource { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) public Response getPartyInfo() { final NodeInfo current = this.discovery.getCurrent(); final JsonArrayBuilder peersBuilder = Json.createArrayBuilder(); partyStore.getParties().stream() .map(party -> Json.createObjectBuilder().add("url", party.toString()).build()) .forEach(peersBuilder::add); final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder(); current.getRecipients().stream() .map( recipient -> Json.createObjectBuilder() .add("key", recipient.getKey().encodeToBase64()) .add("url", recipient.getUrl()) .build()) .forEach(recipientBuilder::add); final String output = Json.createObjectBuilder() .add("url", current.getUrl()) .add("peers", peersBuilder.build()) .add("keys", recipientBuilder.build()) .build() .toString(); LOGGER.debug("Sending json {} from {}", output, current); return Response.status(Response.Status.OK).entity(output).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); }
PartyInfoResource { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) public Response getPartyInfo() { final NodeInfo current = this.discovery.getCurrent(); final JsonArrayBuilder peersBuilder = Json.createArrayBuilder(); partyStore.getParties().stream() .map(party -> Json.createObjectBuilder().add("url", party.toString()).build()) .forEach(peersBuilder::add); final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder(); current.getRecipients().stream() .map( recipient -> Json.createObjectBuilder() .add("key", recipient.getKey().encodeToBase64()) .add("url", recipient.getUrl()) .build()) .forEach(recipientBuilder::add); final String output = Json.createObjectBuilder() .add("url", current.getUrl()) .add("peers", peersBuilder.build()) .add("keys", recipientBuilder.build()) .build() .toString(); LOGGER.debug("Sending json {} from {}", output, current); return Response.status(Response.Status.OK).entity(output).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @ApiOperation(value = "Request key/url of other nodes") @ApiResponses({ @ApiResponse( code = 200, message = "Empty response if node is using remote key validation, else an encoded partyinfo containing only the local node's URL", response = byte[].class), @ApiResponse(code = 500, message = "If node is using remote key validation, indicates validation failed") }) Response partyInfo(
        @ApiParam(required = true) final byte[] payload,
        @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers); @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) Response getPartyInfo(); @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) Response validate(byte[] payloadData); }
PartyInfoResource { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) public Response getPartyInfo() { final NodeInfo current = this.discovery.getCurrent(); final JsonArrayBuilder peersBuilder = Json.createArrayBuilder(); partyStore.getParties().stream() .map(party -> Json.createObjectBuilder().add("url", party.toString()).build()) .forEach(peersBuilder::add); final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder(); current.getRecipients().stream() .map( recipient -> Json.createObjectBuilder() .add("key", recipient.getKey().encodeToBase64()) .add("url", recipient.getUrl()) .build()) .forEach(recipientBuilder::add); final String output = Json.createObjectBuilder() .add("url", current.getUrl()) .add("peers", peersBuilder.build()) .add("keys", recipientBuilder.build()) .build() .toString(); LOGGER.debug("Sending json {} from {}", output, current); return Response.status(Response.Status.OK).entity(output).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @ApiOperation(value = "Request key/url of other nodes") @ApiResponses({ @ApiResponse( code = 200, message = "Empty response if node is using remote key validation, else an encoded partyinfo containing only the local node's URL", response = byte[].class), @ApiResponse(code = 500, message = "If node is using remote key validation, indicates validation failed") }) Response partyInfo(
        @ApiParam(required = true) final byte[] payload,
        @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers); @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) Response getPartyInfo(); @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) Response validate(byte[] payloadData);  }