服务挂了异常处理的方法
String value = HttpClientUtil.postContent(ecampusUrl + jobUrl, "UTF-8", params);//比如这行的服务挂了,直接报异常了 if(StringUtils.isNotEmpty(value)){ try { JSONObject jsonObject = JSON.parseObject(value); String success = jsonObject.getString("success"); if("true".equals(success)){ String jobName = StringUtils.defaultIfEmpty(jsonObject.getJSONObject("data").getString("jobName"),""); result.put("jobName", jobName); } } catch (Exception e) { logger.error("获取职务出错,spaceUid=" + spaceUid); } }
修改为:try { String value = HttpClientUtil.postContent(ecampusUrl + jobUrl, "UTF-8", params); JSONObject jsonObject = JSON.parseObject(value); String success = jsonObject.getString("success"); if("true".equals(success)){ String jobName = StringUtils.defaultIfEmpty(jsonObject.getJSONObject("data").getString("jobName"),""); result.put("jobName", jobName); } } catch (Exception e) { logger.error("获取职务出错,spaceUid=" + spaceUid); }