Search in sources :

Example 1 with JSONObject

use of com.alibaba.fastjson2.JSONObject in project canal by alibaba.

the class DescribeBackupPolicyRequest method processResult.

@Override
protected RdsBackupPolicy processResult(HttpResponse response) throws Exception {
    String result = EntityUtils.toString(response.getEntity());
    JSONObject jsonObj = JSON.parseObject(result);
    RdsBackupPolicy policy = new RdsBackupPolicy();
    policy.setBackupRetentionPeriod(jsonObj.getString("BackupRetentionPeriod"));
    policy.setBackupLog(jsonObj.getString("BackupLog").equalsIgnoreCase("Enable"));
    policy.setLogBackupRetentionPeriod(jsonObj.getIntValue("LogBackupRetentionPeriod"));
    policy.setPreferredBackupPeriod(jsonObj.getString("PreferredBackupPeriod"));
    policy.setPreferredBackupTime(jsonObj.getString("PreferredBackupTime"));
    return policy;
}
Also used : JSONObject(com.alibaba.fastjson2.JSONObject) RdsBackupPolicy(com.alibaba.otter.canal.parse.inbound.mysql.rds.data.RdsBackupPolicy)

Example 2 with JSONObject

use of com.alibaba.fastjson2.JSONObject in project canal by alibaba.

the class CanalClusterController method clustersAndServers.

@GetMapping(value = "/clustersAndServers")
public BaseModel<List<?>> clustersAndServers(@PathVariable String env) {
    List<CanalCluster> clusters = canalClusterServic.findList(new CanalCluster());
    JSONObject group = new JSONObject();
    group.put("label", "集群");
    JSONArray jsonArray = new JSONArray();
    clusters.forEach(cluster -> {
        JSONObject item = new JSONObject();
        item.put("label", cluster.getName());
        item.put("value", "cluster:" + cluster.getId());
        jsonArray.add(item);
    });
    group.put("options", jsonArray);
    NodeServer param = new NodeServer();
    param.setClusterId(-1L);
    // 取所有standalone的节点
    List<NodeServer> servers = nodeServerService.findAll(param);
    JSONObject group2 = new JSONObject();
    group2.put("label", "单机主机");
    JSONArray jsonArray2 = new JSONArray();
    servers.forEach(server -> {
        JSONObject item = new JSONObject();
        item.put("label", server.getName());
        item.put("value", "server:" + server.getId());
        jsonArray2.add(item);
    });
    group2.put("options", jsonArray2);
    List<JSONObject> result = new ArrayList<>();
    result.add(group);
    result.add(group2);
    return BaseModel.getInstance(result);
}
Also used : JSONObject(com.alibaba.fastjson2.JSONObject) JSONArray(com.alibaba.fastjson2.JSONArray) ArrayList(java.util.ArrayList) CanalCluster(com.alibaba.otter.canal.admin.model.CanalCluster) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with JSONObject

use of com.alibaba.fastjson2.JSONObject in project SpringBoot-Hello by ruiyeclub.

the class FastJson2ApplicationTests method testParseObject.

/**
 * JSON字符串转换成对象
 */
@Test
public void testParseObject() {
    String str = "{\"id\":123}";
    JSONObject jsonObject = JSON.parseObject(str);
    Integer id = jsonObject.getInteger("id");
    System.out.println(id);
}
Also used : JSONObject(com.alibaba.fastjson2.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with JSONObject

use of com.alibaba.fastjson2.JSONObject in project druid by alibaba.

the class MonitorStatService method getWebURIStatDataList.

@SuppressWarnings("unchecked")
private String getWebURIStatDataList(Map<String, String> parameters) {
    Map<String, ServiceNode> allNodeMap = getServiceAllNodeMap(parameters);
    List<Map<String, Object>> arrayMap = new ArrayList<>();
    for (String nodeKey : allNodeMap.keySet()) {
        ServiceNode serviceNode = allNodeMap.get(nodeKey);
        String url = getRequestUrl(parameters, serviceNode, "/druid/weburi.json");
        WebResult dataSourceResult = HttpUtil.get(url, WebResult.class);
        if (dataSourceResult != null) {
            List<WebResult.ContentBean> nodeContent = dataSourceResult.getContent();
            if (nodeContent != null) {
                for (WebResult.ContentBean contentBean : nodeContent) {
                    Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(contentBean), Map.class);
                    arrayMap.add(map);
                }
            }
        }
    }
    List<Map<String, Object>> maps = comparatorOrderBy(arrayMap, parameters);
    String jsonString = JSON.toJSONString(maps);
    JSONArray objects = JSON.parseArray(jsonString);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("ResultCode", RESULT_CODE_SUCCESS);
    jsonObject.put("Content", objects);
    return jsonObject.toJSONString();
}
Also used : ServiceNode(com.alibaba.druid.admin.model.ServiceNode) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson2.JSONArray) JSONObject(com.alibaba.fastjson2.JSONObject) JSONObject(com.alibaba.fastjson2.JSONObject) WebResult(com.alibaba.druid.admin.model.dto.WebResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with JSONObject

use of com.alibaba.fastjson2.JSONObject in project sakura-boot by yanjingfan.

the class ESTemplate method sendPostRequest.

public String sendPostRequest(String url, JSONObject params) {
    RestTemplate client = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    // 这里设置为APPLICATION_JSON
    headers.setContentType(MediaType.APPLICATION_JSON);
    // 将请求头部和参数合成一个请求
    HttpEntity<JSONObject> requestEntity = new HttpEntity<>(params, headers);
    // 执行POST请求
    ResponseEntity<String> entity = client.postForEntity(url, requestEntity, String.class);
    return entity.getBody();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) JSONObject(com.alibaba.fastjson2.JSONObject) HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate)

Aggregations

JSONObject (com.alibaba.fastjson2.JSONObject)18 HashMap (java.util.HashMap)5 JSONArray (com.alibaba.fastjson2.JSONArray)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ServiceNode (com.alibaba.druid.admin.model.ServiceNode)2 JSONException (com.alibaba.fastjson2.JSONException)2 LinkedHashMap (java.util.LinkedHashMap)2 RestTemplate (org.springframework.web.client.RestTemplate)2 ChatDao (cn.wzpmc.dao.ChatDao)1 Message (cn.wzpmc.pojo.Message)1 SqlListResult (com.alibaba.druid.admin.model.dto.SqlListResult)1 WebResult (com.alibaba.druid.admin.model.dto.WebResult)1 CanalCluster (com.alibaba.otter.canal.admin.model.CanalCluster)1 NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)1 CanalParseException (com.alibaba.otter.canal.parse.exception.CanalParseException)1 RdsBackupPolicy (com.alibaba.otter.canal.parse.inbound.mysql.rds.data.RdsBackupPolicy)1 MetaSnapshotDO (com.alibaba.otter.canal.parse.inbound.mysql.tsdb.dao.MetaSnapshotDO)1 EntryPosition (com.alibaba.otter.canal.protocol.position.EntryPosition)1 ServiceException (com.ruoyi.common.exception.ServiceException)1