Example usage for com.fasterxml.jackson.core JsonProcessingException getMessage

List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonProcessingException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Default method overridden so that we can add location information

Usage

From source file:com.vmware.photon.controller.api.frontend.lib.UsageTagHelper.java

public static String serialize(List<UsageTag> usageTags) {
    if (usageTags == null) {
        throw new IllegalArgumentException("Null usage tag list cannot be serialized");
    }//from   w  w  w.java 2s. c  o  m

    try {
        return objectMapper
                .writeValueAsString(Ordering.usingToString().natural().immutableSortedCopy(usageTags));
    } catch (JsonProcessingException e) {
        logger.error("Error serializing usageTags list", e);
        throw new IllegalArgumentException(
                String.format("Error serializing usageTags list: %s", e.getMessage()));
    }
}

From source file:info.donsun.cache.filecache.FileCacheManager.java

/**
 * Parse cache config file//from  ww w.j a v  a 2  s  .c o  m
 * 
 * @param resourceAsStream
 * @return
 */
private static void parseConfigFile(InputStream resourceAsStream) {
    try {

        XmlMapper mapper = new XmlMapper();

        fileCacheConfig = mapper.reader(FileCacheConfig.class).readValue(resourceAsStream);
        String defaultDir = fileCacheConfig.getDefaultDir();
        Long defaultExpireTime = fileCacheConfig.getDefaultExpireTime();

        List<CacheConfig> cacheConfigs = fileCacheConfig.getCaches();
        if (cacheConfigs != null && cacheConfigs.size() > 0) {
            for (CacheConfig cache : cacheConfigs) {
                Assert.notNull(cache.getName(), "Cache name must not be null.");

                if (StringUtils.isBlank(cache.getDir())) {
                    cache.setDir(defaultDir);
                }
                if (cache.getExpireTime() == null) {
                    cache.setExpireTime(defaultExpireTime);
                }
                caches.put(cache.getName(), cache);
            }
        }
    } catch (JsonProcessingException e) {
        LOG.error("Parse cache config file exception.", e);
    } catch (IOException e) {
        LOG.error("Reade cache config file exception.", e);
    } catch (IllegalArgumentException e) {
        LOG.error("Illegal argument of cache name." + e.getMessage(), e);
    }
}

From source file:com.wealdtech.gcm.GCMClient.java

/**
 * Encode a message as JSON, capturing errors
 * @param message the message/*w  w w  . j a  va  2  s.  c  o m*/
 * @return a JSON string
 */
private static String encodeMessageAsJson(final Map<String, Object> message) {
    try {
        return WealdMapper.getMapper().writeValueAsString(message);
    } catch (JsonProcessingException e) {
        throw new ServerError(
                "Failed to create JSON message from \"" + message.toString() + "\": " + e.getMessage());
    }
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

public static String createEdsRequest(List<BeanMethod> methods) {

    List<ExtDirectRequest> edrs = new ArrayList<ExtDirectRequest>();
    for (BeanMethod method : methods) {
        ExtDirectRequest dr = new ExtDirectRequest();
        dr.setAction(method.getBean());//  w  w w .  j  a v  a  2s .  c om
        dr.setMethod(method.getMethod());
        dr.setTid(method.getTid());
        dr.setType("rpc");
        dr.setData(method.getData());
        edrs.add(dr);
    }

    try {
        return mapper.writeValueAsString(edrs);
    } catch (JsonProcessingException e) {
        fail("createEdsRequest: " + e.getMessage());
    }
    return null;
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

public static String createEdsRequest(String action, String method, boolean namedParameter, int tid,
        Object data, Map<String, Object> metadata) {
    ExtDirectRequest dr = new ExtDirectRequest();
    dr.setAction(action);//w ww.j  a  v  a 2s.  c om
    dr.setMethod(method);
    dr.setTid(tid);
    dr.setType("rpc");

    if (metadata != null) {
        dr.setMetadata(metadata);
    } else {
        dr.setMetadata(null);
    }

    if (namedParameter && data != null) {
        if (Arrays.isArray(data)) {
            dr.setData(((Object[]) data)[0]);
        } else {
            dr.setData(data);
        }
    } else if (data instanceof Object[] || data == null) {
        dr.setData(data);
    } else {
        dr.setData(new Object[] { data });
    }
    try {
        return mapper.writeValueAsString(dr);
    } catch (JsonProcessingException e) {
        fail("createEdsRequest: " + e.getMessage());
    }
    return null;
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

public static Object sendAndReceiveObject(MockMvc mockMvc, String bean, String method) {
    int tid = (int) (Math.random() * 1000);

    MvcResult result = null;// w w w . ja v a2 s  . c  o  m
    try {
        result = performRouterRequest(mockMvc, createEdsRequest(bean, method, false, tid, null, null), null,
                null, null, false);
    } catch (JsonProcessingException e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    } catch (Exception e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    }

    List<ExtDirectResponse> responses = readDirectResponses(result.getResponse().getContentAsByteArray());
    assertThat(responses).hasSize(1);

    ExtDirectResponse edResponse = responses.get(0);

    assertThat(edResponse.getAction()).isEqualTo(bean);
    assertThat(edResponse.getMethod()).isEqualTo(method);
    assertThat(edResponse.getTid()).isEqualTo(tid);
    assertThat(edResponse.getWhere()).isNull();

    return edResponse.getResult();
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

@SuppressWarnings("unchecked")
public static List<Map<String, Object>> sendAndReceiveMultiple(MockMvc mockMvc, List<BeanMethod> beanMethods) {
    for (BeanMethod beanMethod : beanMethods) {
        beanMethod.setTid((int) (Math.random() * 1000));
    }//from w  w w .  j  av  a  2  s. co m

    MvcResult result = null;
    try {
        result = performRouterRequest(mockMvc, createEdsRequest(beanMethods));
    } catch (JsonProcessingException e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    } catch (Exception e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    }

    List<ExtDirectResponse> responses = readDirectResponses(result.getResponse().getContentAsByteArray());
    assertThat(responses).hasSize(beanMethods.size());

    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < beanMethods.size(); i++) {
        ExtDirectResponse edResponse = responses.get(i);
        BeanMethod beanMethod = beanMethods.get(i);
        assertThat(edResponse.getAction()).isEqualTo(beanMethod.getBean());
        assertThat(edResponse.getMethod()).isEqualTo(beanMethod.getMethod());
        assertThat(edResponse.getTid()).isEqualTo(beanMethod.getTid());
        assertThat(edResponse.getWhere()).isNull();

        results.add((Map<String, Object>) edResponse.getResult());
    }

    return results;
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

public static Object sendAndReceive(MockMvc mockMvc, boolean withSession, HttpHeaders headers,
        List<Cookie> cookies, Map<String, Object> metadata, String bean, String method, boolean namedParameters,
        Object expectedResultOrType, Object... requestData) {

    int tid = (int) (Math.random() * 1000);

    MvcResult result = null;//w  w  w .  j  a v a 2 s.co m
    try {
        result = performRouterRequest(mockMvc,
                createEdsRequest(bean, method, namedParameters, tid, requestData, metadata), null, headers,
                cookies, withSession);
    } catch (JsonProcessingException e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    } catch (Exception e) {
        fail("perform post to /router" + e.getMessage());
        return null;
    }

    List<ExtDirectResponse> responses = readDirectResponses(result.getResponse().getContentAsByteArray());
    assertThat(responses).hasSize(1);

    ExtDirectResponse edResponse = responses.get(0);

    assertThat(edResponse.getAction()).isEqualTo(bean);
    assertThat(edResponse.getMethod()).isEqualTo(method);
    assertThat(edResponse.getTid()).isEqualTo(tid);
    assertThat(edResponse.getWhere()).isNull();

    if (expectedResultOrType == null) {
        assertThat(edResponse.getType()).isEqualTo("exception");
        assertThat(edResponse.getResult()).isNull();
        assertThat(edResponse.getMessage()).isEqualTo("Server Error");
    } else {
        assertThat(edResponse.getType()).isEqualTo("rpc");
        assertThat(edResponse.getMessage()).isNull();
        if (expectedResultOrType == Void.TYPE) {
            assertThat(edResponse.getResult()).isNull();
        } else if (expectedResultOrType instanceof Class<?>) {
            return ControllerUtil.convertValue(edResponse.getResult(), (Class<?>) expectedResultOrType);
        } else if (expectedResultOrType instanceof TypeReference) {
            return ControllerUtil.convertValue(edResponse.getResult(), (TypeReference<?>) expectedResultOrType);
        } else {
            assertThat(edResponse.getResult()).isEqualTo(expectedResultOrType);
        }
    }

    return edResponse.getResult();

}

From source file:io.fabric8.maven.plugin.AbstractDeployMojo.java

public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service,
        Log log) {//from w  ww .jav  a 2s.c  o  m
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && shouldCreateExternalURLForService(log, service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        ObjectReference objectRef = new ObjectReference();
        objectRef.setName(id);
        objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (!Strings.isNullOrBlank(routeDomainPostfix)) {
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        } else {
            routeSpec.setHost("");
        }
        route.setSpec(routeSpec);
        String json;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
        log.debug("Created route: " + json);
    }
    return route;
}

From source file:org.apache.streams.converter.HoconConverterUtil.java

public static Object convert(Object object, Class outClass, Config hocon, String outPath) {
    String json = null;//w w w .  j a v  a  2 s .  c om
    Object outDoc = null;
    if (object instanceof String) {
        json = (String) object;
    } else {
        try {
            json = mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            LOGGER.warn("Failed to process input:", object);
            return outDoc;
        }
    }

    Config base = ConfigFactory.parseString(json);
    Config converted = hocon.withFallback(base);

    String outJson = null;
    try {
        if (outPath == null)
            outJson = converted.resolve().root().render(ConfigRenderOptions.concise());
        else {
            Config resolved = converted.resolve();
            ConfigObject outObject = resolved.withOnlyPath(outPath).root();
            ConfigValue outValue = outObject.get(outPath);
            outJson = outValue.render(ConfigRenderOptions.concise());
        }
    } catch (Exception e) {
        LOGGER.warn("Failed to convert:", json);
        LOGGER.warn(e.getMessage());
    }
    if (outClass == String.class)
        return outJson;
    else {
        try {
            outDoc = mapper.readValue(outJson, outClass);
        } catch (IOException e) {
            LOGGER.warn("Failed to convert:", object);
        }
    }
    return outDoc;
}