HttpClient&FastJson

1823 단어
액세스 URL
http://xxx.xxx.com/xxx-unify-query-web/employeeInfo?clientKey=cpPA8%2Fa%5C4%26%24g&clientId=mwbops-sit&employeeId=13075054
반환 메시지
{"data":{"employeeId":"xxx","employeeName":" xx","orgId":"xxx","orgName":"xxxx","positionId":"xxx","positionName":" ","ismajorPosition":"X","prefix":"emp"},"serviceResponse":{"status":"complete"}}

메시지를 가져오고, 실체를 해석하고 봉인합니다.
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;  
    }

좋은 웹페이지 즐겨찾기