package cmcc.iot.onenet.javasdk.api.cmds;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import cmcc.iot.onenet.javasdk.api.AbstractAPI;
import cmcc.iot.onenet.javasdk.exception.OnenetApiException;
import cmcc.iot.onenet.javasdk.http.HttpGetMethod;
import cmcc.iot.onenet.javasdk.request.RequestInfo.Method;
import cmcc.iot.onenet.javasdk.response.BasicResponse;
import cmcc.iot.onenet.javasdk.response.cmds.CmdsResponse;
import cmcc.iot.onenet.javasdk.utils.Config;

public class QueryCmdsRespApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private  String cmdUuid;


	/**
	 * @param cmduuid:命令id,String
	 * @param key:masterkey或者设备apikey
	 */
	public QueryCmdsRespApi(String cmdUuid,String key) {
		this.cmdUuid = cmdUuid;
		this.key=key;
		this.method= Method.GET;
		this.HttpMethod=new HttpGetMethod(method);
	}


	@Override
	public void build() {
		// TODO Auto-generated method stub
		Map<String, Object> headmap = new HashMap<String, Object>();
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		this.url = Config.getString("test.url") + "/cmds/" + cmdUuid+"/resp";
		HttpMethod.setcompleteUrl(url,null);
	}
	public BasicResponse<Void> executeApi() {
		ObjectMapper mapper = new ObjectMapper();
		BasicResponse response=null;
		HttpResponse httpResponse=HttpMethod.execute();
		try {
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsResponse.class);
			response.setData(newData);
		} catch (Exception e) {
			// TODO Auto-generated catch block
		//	e.printStackTrace();
			logger.error("json error", e.getMessage());
			throw new OnenetApiException();
		}
		try{
			HttpMethod.httpClient.close();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("http close error:" + e.getMessage());
			throw new OnenetApiException();
		}
		return response;
	}
}
@@ -1414,111 +1414,49 @@
 lic 
-BasicResponse%3CVoid%3E executeApi() %7B%0A%09%09ObjectMapper mapper = new ObjectMapper();%0A%09%09BasicResponse
+String executeApi() %7B%0A        String
  resp
-onse
 =nul
@@ -1523,387 +1523,92 @@
 %0A%09%09%09
+ 
 resp
-onse = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);%0A%09%09%09response.setJson(mapper.writeValueAsString(response));%0A%09%09%09Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsResponse.class);%0A%09%09%09response.setData(newData);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09//%09e.printStackTrace();
+= EntityUtils.toString(httpResponse.getEntity());%0A%09%09%09%0A%09%09%7D catch (Exception e) %7B
 %0A%09%09%09
@@ -1905,14 +1905,11 @@
 resp
-onse
 ;%0A%09%7D%0A%7D
+%0A

Update QueryCmdsRespApi.java