<repo_name>kentwood/MbcTestServer<file_sep>/src/main/java/com/just4fun/controller/MbcRecvController.java
package com.just4fun.controller;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import utils.GsonUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by sdt14096 on 2017/5/27.
 */
@Controller
@RequestMapping("test")
public class MbcRecvController {

    private static final Logger log = LoggerFactory.getLogger(MbcRecvController.class);

    @ResponseBody
    @RequestMapping(value = "logs")
    public Map<String,String> tttestMBCServer(@RequestBody String jsonString) throws IOException {
        log.info("----------");
        log.info("the MBC server got data:");
        log.info(jsonString);
        Map<String, String> map = new HashMap<String, String>();

        JsonArray myJsonArray = null;
        JsonObject myJsonObject = null;
        try {
            myJsonArray = GsonUtil.getJsonParser().parse(jsonString).getAsJsonArray();
            if (myJsonArray.isJsonNull()) {
                log.info("the jsonArray is empty");
                map.put("result", "ERROR");
                map.put("detail", " ");
                return map;
            } else {
                log.info("jsonArray:" + myJsonArray);
                map.put("result", "OK");
                map.put("detail", " ");
                log.info("MBC server send data to skyworth server");
                log.info(map.toString());
                return map;
            }
        }catch (Exception e){
            myJsonObject = GsonUtil.getJsonParser().parse(jsonString).getAsJsonObject();
            if (myJsonObject.isJsonNull()) {
                log.info("the jsonObject is empty");
                map.put("result", "ERROR");
                map.put("detail", " ");
                return map;
            } else {
                log.info("jsonObject:" + myJsonObject);
                map.put("result", "OK");
                map.put("detail", " ");
                log.info("MBC server send data to skyworth server");
                log.info(map.toString());
                return map;
            }
        }
    }
}
