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;
}
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;
}
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();
}
}
}
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;
}
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();
}
Aggregations