Search in sources :

Example 16 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project bamboobsc by billchen198318.

the class CxfServerBean method shutdownOrReloadCallOneSystem.

@SuppressWarnings("unchecked")
public static Map<String, Object> shutdownOrReloadCallOneSystem(HttpServletRequest request, String system, String type) throws ServiceException, Exception {
    if (StringUtils.isBlank(system) || StringUtils.isBlank(type)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    String urlStr = ApplicationSiteUtils.getBasePath(system, request) + "config-services?type=" + type + "&value=" + createParamValue();
    logger.info("shutdownOrReloadCallSystem , url=" + urlStr);
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(urlStr);
    client.executeMethod(method);
    byte[] responseBody = method.getResponseBody();
    if (null == responseBody) {
        throw new Exception("no response!");
    }
    String content = new String(responseBody, Constants.BASE_ENCODING);
    logger.info("shutdownOrReloadCallSystem , system=" + system + " , type=" + type + " , response=" + content);
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> dataMap = null;
    try {
        dataMap = (Map<String, Object>) mapper.readValue(content, HashMap.class);
    } catch (JsonParseException e) {
        logger.error(e.getMessage().toString());
    } catch (JsonMappingException e) {
        logger.error(e.getMessage().toString());
    }
    if (null == dataMap) {
        throw new Exception("response content error!");
    }
    return dataMap;
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HttpClient(org.apache.commons.httpclient.HttpClient) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonParseException(com.fasterxml.jackson.core.JsonParseException) HttpMethod(org.apache.commons.httpclient.HttpMethod) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 17 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project atsd-api-test by axibase.

the class TableMetaDataDeserializer method deserialize.

@Override
public TableMetaData deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    String jsonText = jsonParser.readValueAsTree().toString();
    TableMetaData result;
    try {
        result = SqlTableParser.parseMeta(new JSONObject(jsonText));
    } catch (JSONException je) {
        throw new JsonParseException(jsonParser, je.getMessage());
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 18 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project portal by ixinportal.

the class WeixinUtil method getAccTokenFromWeixin.

/**
 * 获得token
 */
public void getAccTokenFromWeixin() {
    synchronized (atLock) {
        String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APPID}&secret={APPSECRET}";
        try {
            Long nowDate = System.currentTimeMillis();
            if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(ACCESS_TOKEN.getInDate()))
                return;
            ByteArrayResource retRes = restTemplate.getForObject(tokenUrl, ByteArrayResource.class, appid, secret);
            Map<String, Object> tokenMap = jsonTool.readValue(new String(retRes.getByteArray()), Map.class);
            if (tokenMap == null || tokenMap.isEmpty()) {
                log.error("微信获取token失败,返回为空");
                return;
            }
            Integer ei = (Integer) tokenMap.get("expires_in");
            Date inDate = new Date(nowDate + ei * 1000);
            AccToken ACCESS_TOKEN_TMP = new AccToken((String) tokenMap.get("access_token"), inDate);
            ACCESS_TOKEN = ACCESS_TOKEN_TMP;
        } catch (RestClientException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (JsonParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestClientException(org.springframework.web.client.RestClientException) ByteArrayResource(org.springframework.core.io.ByteArrayResource) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Date(java.util.Date)

Example 19 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project portal by ixinportal.

the class AuthService method getToken.

// @Autowired
// private static RealNameAuthenticationSerivceImpl authenticationSerivceImpl = new RealNameAuthenticationSerivceImpl();
/**
 * 获得token
 * 访问其他接口的时候 在头信息增加 Authorization :bear+token bear和token之间加个空格
 */
private static String getToken() {
    // client_secret:43b484748d3a936330bc50da70d6ce69e1dfef90
    try {
        // RealNameAuthentication realNameAuthentication =  authenticationSerivceImpl.getRealNameAuthenticationExample(new RealNameAuthenticationExample());
        long nowDate = System.currentTimeMillis();
        if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(inDate)) {
            return ACCESS_TOKEN;
        }
        RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
        if (realNameAuthentication == null) {
            List<RealNameAuthentication> list = SpringContextHolder.getBean(SqlSession.class).selectList("com.itrus.portal.db.RealNameAuthenticationMapper.selectByExample", new RealNameAuthenticationExample());
            if (list == null || list.isEmpty()) {
                return null;
            }
            for (RealNameAuthentication nameAuthentication : list) {
                if (nameAuthentication.getType() == 2)
                    realNameAuthentication = nameAuthentication;
            }
            if (realNameAuthentication == null) {
                return null;
            }
        }
        Map params = new HashMap();
        params.put("grant_type", "client_credentials");
        params.put("client_id", realNameAuthentication.getIdCode());
        params.put("client_secret", realNameAuthentication.getKeyCode());
        String rep = HttpClientUtil.postForm(realNameAuthentication.getAccessTokenaddress() + TOKEN, null, params);
        // System.out.println("AuthService getToken()_rep : " + rep);
        JSONObject data = JSON.parseObject(rep);
        ACCESS_TOKEN = data.getString("access_token");
        inDate = new Date(nowDate + data.getLongValue("expires_in"));
        return ACCESS_TOKEN;
    } catch (RestClientException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) IOException(java.io.IOException) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Date(java.util.Date) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample) JSONObject(com.alibaba.fastjson.JSONObject) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestClientException(org.springframework.web.client.RestClientException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project fabric8 by jboss-fuse.

the class ClusterListAction method printCluster.

protected void printCluster(String dir, PrintStream out) throws Exception {
    // do we have any clusters at all?
    if (exists(getCurator(), dir) == null) {
        return;
    }
    List<String> children = getAllChildren(getCurator(), dir);
    Map<String, Map<String, ClusterNode>> clusters = new TreeMap<String, Map<String, ClusterNode>>();
    for (String child : children) {
        byte[] data = getCurator().getData().forPath(child);
        if (data != null && data.length > 0) {
            String text = new String(data).trim();
            if (!text.isEmpty()) {
                String clusterName = getClusterName(dir, child);
                Map<String, ClusterNode> cluster = clusters.get(clusterName);
                if (cluster == null) {
                    cluster = new TreeMap<String, ClusterNode>();
                    clusters.put(clusterName, cluster);
                }
                ObjectMapper mapper = new ObjectMapper();
                Map<String, Object> map = null;
                try {
                    map = mapper.readValue(data, HashMap.class);
                } catch (JsonParseException e) {
                    log.error("Error parsing JSON string: {}", text);
                    throw e;
                }
                ClusterNode node = null;
                Object id = value(map, "id", "container");
                if (id != null) {
                    Object agent = value(map, "container", "agent");
                    List services = (List) value(map, "services");
                    node = cluster.get(id);
                    if (node == null) {
                        node = new ClusterNode();
                        cluster.put(id.toString(), node);
                    }
                    if (services != null) {
                        if (!services.isEmpty()) {
                            for (Object service : services) {
                                node.services.add(getSubstitutedData(getCurator(), service.toString()));
                            }
                            node.masters.add(agent);
                        } else {
                            node.slaves.add(agent);
                        }
                    } else {
                        Object started = value(map, "started");
                        if (started == Boolean.TRUE) {
                            node.masters.add(agent);
                        } else {
                            node.slaves.add(agent);
                        }
                    }
                }
            }
        }
    }
    TablePrinter table = new TablePrinter();
    table.columns("cluster", "masters", "slaves", "services");
    for (String clusterName : clusters.keySet()) {
        Map<String, ClusterNode> nodes = clusters.get(clusterName);
        table.row(clusterName, "", "", "", "");
        for (String nodeName : nodes.keySet()) {
            ClusterNode node = nodes.get(nodeName);
            table.row("   " + nodeName, printList(node.masters), printList(node.slaves), printList(node.services));
        }
    }
    table.print();
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) JsonParseException(com.fasterxml.jackson.core.JsonParseException) TablePrinter(io.fabric8.utils.TablePrinter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)120 IOException (java.io.IOException)59 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)53 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 JsonParser (com.fasterxml.jackson.core.JsonParser)21 Map (java.util.Map)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)12 HashMap (java.util.HashMap)12 JsonToken (com.fasterxml.jackson.core.JsonToken)11 JsonFactory (com.fasterxml.jackson.core.JsonFactory)9 File (java.io.File)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4