訪問URLjava
返回報文this
{"data":{"employeeId":"xxx","employeeName":"黃xx","orgId":"xxx","orgName":"xxxx","positionId":"xxx","positionName":"開發工程師","ismajorPosition":"X","prefix":"emp"},"serviceResponse":{"status":"complete"}}
獲取報文,解析並封裝實體。url
public EmployeeDto getEmployee(String employeeId, String orgId) throws Exception{ String url = null; String params = null; if(StringUtil.isBlank(orgId)){ url = this.urlEmploee; params = "clientKey="+URLEncoder.encode(this.clientKey, "utf-8")+"&clientId="+this.clientId+"&employeeId="+employeeId; }else{ url = this.urlManager; params = "clientKey="+URLEncoder.encode(this.clientKey, "utf-8")+"&clientId="+this.clientId+"&orgId="+orgId; } HttpClient httpClient = new HttpClient(); HttpMethod method = getMethod(url, params); httpClient.executeMethod(method); String response = method.getResponseBodyAsString(); JSONObject jo = JSON.parseObject(response); JSONObject sjo = jo.getJSONObject("serviceResponse"); if("complete".equals(sjo.getString("status"))){ EmployeeDto emp = jo.getObject("data", EmployeeDto.class); return emp; } return null; } private static HttpMethod getMethod(String url,String param) throws IOException{ GetMethod getMethod = new GetMethod(url+"?"+param); getMethod.releaseConnection(); return getMethod; }