APISonar


pl.allegro.tech.hermes.api.ContentType.JSON

> pl > allegro > tech > hermes > api > ContentType > JSON
pl APIs allegro APIs tech APIs hermes APIs api APIs ContentType APIs JSON APIs

Example 1
public boolean test(Message message) {
        check(message.getContentType() == ContentType.JSON, "This filter supports only JSON contentType.");
        try {
            List<Object> result = JsonPath.parse(new ByteArrayInputStream(message.getData()), configuration).read(path);
            return !result.isEmpty() && result.stream()
                    .map(Objects::toString)
                    .allMatch(o -> matcher.matcher(o).matches());
        } catch (Exception ex) {
            throw new FilteringException(ex);
        }
    }
Example 2
public void createBatchSubscription(Topic topic, String endpoint, BatchSubscriptionPolicy policy) {
        Subscription subscription = subscription(topic, "batchSubscription")
                .withEndpoint(endpoint)
                .withContentType(ContentType.JSON)
                .withSubscriptionPolicy(policy)
                .build();

        createSubscription(topic, subscription);
    }
Example 3
public Message convert(Message message, Topic topic) {
        return message()
                .fromMessage(message)
                .withContentType(ContentType.JSON)
                .withData(converter.convertToJson(recordWithoutMetadata(message.getData(), message.<Schema>getSchema().get().getSchema())))
                .withNoSchema()
                .build();
    }
Example 4
public MessageConverter converterFor(Message message, Subscription subscription) {
        if (message.getContentType() == ContentType.AVRO && subscription.getContentType() == ContentType.JSON) {
            return avroToJsonMessageConverter;
        }

        return noOperationMessageConverter;
    }
Example 5
public void check(Message message, Topic topic) {
        if (ContentType.AVRO != topic.getContentType() || (ContentType.JSON == topic.getContentType() && !topic.isJsonToAvroDryRunEnabled())) {
            return;
        }

        BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(message.getData(), null);
        try {
            new GenericDatumReader<>(message.getSchema()).read(null, binaryDecoder);
        } catch (Exception e) {
            String reason = e.getMessage() == null ? ExceptionUtils.getRootCauseMessage(e) : e.getMessage();
            throw new InvalidMessageException("Could not deserialize avro message with provided schema", ImmutableList.of(reason));
        }
    }
Example 6
private UnwrappedMessageContent getUnwrappedMessageContent(ConsumerRecord<byte[], byte[]> message,
                                                               ContentType contentType) {
        if (contentType == ContentType.AVRO) {
            return messageContentWrapper.unwrapAvro(message.value(), topic);
        } else if (contentType == ContentType.JSON) {
            return messageContentWrapper.unwrapJson(message.value());
        }
        throw new UnsupportedContentTypeException(topic);
    }