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

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

import org.apache.http.HttpResponse;
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.HttpPostMethod;
import cmcc.iot.onenet.javasdk.request.RequestInfo.Method;
import cmcc.iot.onenet.javasdk.response.BasicResponse;
import cmcc.iot.onenet.javasdk.utils.Config;

public class CreateMqttTopicApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpPostMethod HttpMethod;
	private String name;
	/**
	 * @param name:设备订阅的主题（必选）,String
	 * @param key：masterkey
	 */
	public CreateMqttTopicApi(String name,String key) {
		this.name = name;
		this.key = key;
		this.method = Method.POST;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/mqtt"+"/topic";
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if(name!=null){
            bodymap.put("name", name);
        }
        String json=null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            logger.error("json error", e.getMessage());
            throw new OnenetApiException();
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}
	
	

	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		HttpResponse httpResponse = HttpMethod.execute();
		try {

			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
		} catch (Exception e) {
			logger.error("json error", e.getMessage());
			throw new OnenetApiException();
		}
		try {
			HttpMethod.httpClient.close();
		} catch (Exception e) {
			logger.error("http close error:" + e.getMessage());
			throw new OnenetApiException();
		}
		return response;
	}
}

@@ -1515,90 +1515,8 @@
 ) %7B%0A
-            // TODO Auto-generated catch block%0A            //e.printStackTrace();%0A
     
@@ -2060,32 +2060,35 @@
 rror(%22json error
+ %7B%7D
 %22, e.getMessage(
@@ -2236,11 +2236,14 @@
 ror:
+ %7B%7D
 %22 
-+
+,
  e.g

Update CreateMqttTopicApi.java