Search in sources :

Example 86 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project tutorials by eugenp.

the class HttpClientTest method setup.

@BeforeClass
public static void setup() {
    // Unirest.setProxy(new HttpHost("localhost", 8080));
    Unirest.setTimeouts(20000, 15000);
    Unirest.setDefaultHeader("X-app-name", "baeldung-unirest");
    Unirest.setDefaultHeader("X-request-id", "100004f00ab5");
    Unirest.setConcurrency(20, 5);
    Unirest.setObjectMapper(new ObjectMapper() {

        com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();

        public String writeValue(Object value) {
            try {
                return mapper.writeValueAsString(value);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }

        public <T> T readValue(String value, Class<T> valueType) {
            try {
                return mapper.readValue(value, valueType);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : UnirestException(com.mashape.unirest.http.exceptions.UnirestException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.mashape.unirest.http.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 87 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project Server_Management_Plugin_vRealize by Huawei.

the class ServerDeviceBean method toString.

@Override
public String toString() {
    try {
        // 转换为json字符串
        // .withDefaultPrettyPrinter()
        ObjectWriter ow = new ObjectMapper().writer();
        String json = ow.writeValueAsString(this);
        return json;
    } catch (JsonProcessingException e) {
        return "";
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 88 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project Server_Management_Plugin_vRealize by Huawei.

the class ServerDeviceDetailBean method toString.

@Override
public String toString() {
    try {
        // 转换为json字符串
        // .withDefaultPrettyPrinter()
        ObjectWriter ow = new ObjectMapper().writer();
        String json = ow.writeValueAsString(this);
        return json;
    } catch (JsonProcessingException e) {
        return "";
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 89 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project incubator-pulsar by apache.

the class ConsumerHandler method receiveMessage.

private void receiveMessage() {
    if (log.isDebugEnabled()) {
        log.debug("[{}:{}] [{}] [{}] Receive next message", request.getRemoteAddr(), request.getRemotePort(), topic, subscription);
    }
    consumer.receiveAsync().thenAccept(msg -> {
        if (log.isDebugEnabled()) {
            log.debug("[{}] [{}] [{}] Got message {}", getSession().getRemoteAddress(), topic, subscription, msg.getMessageId());
        }
        ConsumerMessage dm = new ConsumerMessage();
        dm.messageId = Base64.getEncoder().encodeToString(msg.getMessageId().toByteArray());
        dm.payload = Base64.getEncoder().encodeToString(msg.getData());
        dm.properties = msg.getProperties();
        dm.publishTime = DateFormatter.format(msg.getPublishTime());
        if (msg.getEventTime() != 0) {
            dm.eventTime = DateFormatter.format(msg.getEventTime());
        }
        if (msg.hasKey()) {
            dm.key = msg.getKey();
        }
        final long msgSize = msg.getData().length;
        try {
            getSession().getRemote().sendString(ObjectMapperFactory.getThreadLocal().writeValueAsString(dm), new WriteCallback() {

                @Override
                public void writeFailed(Throwable th) {
                    log.warn("[{}/{}] Failed to deliver msg to {} {}", consumer.getTopic(), subscription, getRemote().getInetSocketAddress().toString(), th.getMessage());
                    pendingMessages.decrementAndGet();
                    // schedule receive as one of the delivery failed
                    service.getExecutor().execute(() -> receiveMessage());
                }

                @Override
                public void writeSuccess() {
                    if (log.isDebugEnabled()) {
                        log.debug("[{}/{}] message is delivered successfully to {} ", consumer.getTopic(), subscription, getRemote().getInetSocketAddress().toString());
                    }
                    updateDeliverMsgStat(msgSize);
                }
            });
        } catch (JsonProcessingException e) {
            close(WebSocketError.FailedToSerializeToJSON);
        }
        int pending = pendingMessages.incrementAndGet();
        if (pending < maxPendingMessages) {
            // Start next read in a separate thread to avoid recursion
            service.getExecutor().execute(() -> receiveMessage());
        }
    }).exceptionally(exception -> {
        return null;
    });
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) LoggerFactory(org.slf4j.LoggerFactory) Enums(com.google.common.base.Enums) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HttpServletRequest(javax.servlet.http.HttpServletRequest) DateFormatter(org.apache.pulsar.common.util.DateFormatter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Session(org.eclipse.jetty.websocket.api.Session) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse) Splitter(com.google.common.base.Splitter) ConsumerBusyException(org.apache.pulsar.client.api.PulsarClientException.ConsumerBusyException) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) TimeUnit(java.util.concurrent.TimeUnit) Consumer(org.apache.pulsar.client.api.Consumer) Base64(java.util.Base64) List(java.util.List) ConsumerMessage(org.apache.pulsar.websocket.data.ConsumerMessage) MessageId(org.apache.pulsar.client.api.MessageId) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) ConsumerAck(org.apache.pulsar.websocket.data.ConsumerAck) ConsumerMessage(org.apache.pulsar.websocket.data.ConsumerMessage) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 90 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project incubator-pulsar by apache.

the class ReaderHandler method receiveMessage.

private void receiveMessage() {
    if (log.isDebugEnabled()) {
        log.debug("[{}:{}] [{}] [{}] Receive next message", request.getRemoteAddr(), request.getRemotePort(), topic, subscription);
    }
    reader.readNextAsync().thenAccept(msg -> {
        if (log.isDebugEnabled()) {
            log.debug("[{}] [{}] [{}] Got message {}", getSession().getRemoteAddress(), topic, subscription, msg.getMessageId());
        }
        ConsumerMessage dm = new ConsumerMessage();
        dm.messageId = Base64.getEncoder().encodeToString(msg.getMessageId().toByteArray());
        dm.payload = Base64.getEncoder().encodeToString(msg.getData());
        dm.properties = msg.getProperties();
        dm.publishTime = DateFormatter.format(msg.getPublishTime());
        if (msg.getEventTime() != 0) {
            dm.eventTime = DateFormatter.format(msg.getEventTime());
        }
        if (msg.hasKey()) {
            dm.key = msg.getKey();
        }
        final long msgSize = msg.getData().length;
        try {
            getSession().getRemote().sendString(ObjectMapperFactory.getThreadLocal().writeValueAsString(dm), new WriteCallback() {

                @Override
                public void writeFailed(Throwable th) {
                    log.warn("[{}/{}] Failed to deliver msg to {} {}", reader.getTopic(), subscription, getRemote().getInetSocketAddress().toString(), th.getMessage());
                    pendingMessages.decrementAndGet();
                    // schedule receive as one of the delivery failed
                    service.getExecutor().execute(() -> receiveMessage());
                }

                @Override
                public void writeSuccess() {
                    if (log.isDebugEnabled()) {
                        log.debug("[{}/{}] message is delivered successfully to {} ", reader.getTopic(), subscription, getRemote().getInetSocketAddress().toString());
                    }
                    updateDeliverMsgStat(msgSize);
                }
            });
        } catch (JsonProcessingException e) {
            close(WebSocketError.FailedToSerializeToJSON);
        }
        int pending = pendingMessages.incrementAndGet();
        if (pending < maxPendingMessages) {
            // Start next read in a separate thread to avoid recursion
            service.getExecutor().execute(() -> receiveMessage());
        }
    }).exceptionally(exception -> {
        log.warn("[{}/{}] Failed to deliver msg to {} {}", reader.getTopic(), subscription, getRemote().getInetSocketAddress().toString(), exception);
        return null;
    });
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) LoggerFactory(org.slf4j.LoggerFactory) ReaderImpl(org.apache.pulsar.client.impl.ReaderImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) DateFormatter(org.apache.pulsar.common.util.DateFormatter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Session(org.eclipse.jetty.websocket.api.Session) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) Reader(org.apache.pulsar.client.api.Reader) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) Consumer(org.apache.pulsar.client.api.Consumer) Base64(java.util.Base64) ConsumerMessage(org.apache.pulsar.websocket.data.ConsumerMessage) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) MessageId(org.apache.pulsar.client.api.MessageId) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) ConsumerMessage(org.apache.pulsar.websocket.data.ConsumerMessage) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)741 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)241 IOException (java.io.IOException)174 HashMap (java.util.HashMap)108 Map (java.util.Map)83 ArrayList (java.util.ArrayList)74 JsonNode (com.fasterxml.jackson.databind.JsonNode)73 Test (org.junit.Test)65 List (java.util.List)56 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)36 Collectors (java.util.stream.Collectors)30 InputStream (java.io.InputStream)26 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 File (java.io.File)20 Function (java.util.function.Function)20 Logger (org.slf4j.Logger)20 Optional (java.util.Optional)19 Date (java.util.Date)18 Test (org.testng.annotations.Test)18