|
@@ -4,6 +4,7 @@ package com.fdkankan.mqcontroller.utils;
|
|
import cn.hutool.core.codec.Base64;
|
|
import cn.hutool.core.codec.Base64;
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.mqcontroller.entity.MqMsg;
|
|
import com.fdkankan.mqcontroller.entity.MqMsg;
|
|
import com.fdkankan.mqcontroller.entity.MqQueueConfig;
|
|
import com.fdkankan.mqcontroller.entity.MqQueueConfig;
|
|
@@ -26,19 +27,25 @@ public class RabbitMqUtils {
|
|
log.warn("getRabbitMqMsg-url:{}",url);
|
|
log.warn("getRabbitMqMsg-url:{}",url);
|
|
// 添加请求头
|
|
// 添加请求头
|
|
// 设置认证信息
|
|
// 设置认证信息
|
|
|
|
+ HttpResponse execute = null;
|
|
try {
|
|
try {
|
|
HttpRequest request = HttpRequest.get(url)
|
|
HttpRequest request = HttpRequest.get(url)
|
|
.header("authorization", "Basic " +
|
|
.header("authorization", "Basic " +
|
|
Base64.encode((userName + ":" + password).getBytes(CharsetUtil.UTF_8)));
|
|
Base64.encode((userName + ":" + password).getBytes(CharsetUtil.UTF_8)));
|
|
// 发送请求,并获取响应字符串
|
|
// 发送请求,并获取响应字符串
|
|
- String response = request.execute().body();
|
|
|
|
|
|
+ execute = request.execute();
|
|
|
|
+ String response = execute.body();
|
|
log.warn("getRabbitMqMsg-resp:{}",response);
|
|
log.warn("getRabbitMqMsg-resp:{}",response);
|
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
|
return JSONObject.toJavaObject(jsonObject,MqMsg.class);
|
|
return JSONObject.toJavaObject(jsonObject,MqMsg.class);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
log.info("获取mq信息失败:",e);
|
|
log.info("获取mq信息失败:",e);
|
|
|
|
+ }finally {
|
|
|
|
+ if(execute != null){
|
|
|
|
+ execute.close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ return new MqMsg();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|