mq-load/src/main/java/com/mobai/service/impl/FluxGetInfoServiceImpl.java

57 lines
1.9 KiB
Java

package com.mobai.service.impl;
import com.alibaba.fastjson2.JSON;
import com.mobai.domain.AcceptToken;
import com.mobai.domain.ApifoxModel;
import com.mobai.domain.Result;
import com.mobai.domain.User;
import com.mobai.service.FluxGetInfoService;
import okhttp3.*;
import org.apache.catalina.authenticator.SpnegoAuthenticator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @ClassName FluxGetInfoServiceImpl
* @Description 描述
* @Author SaiSai.Liu
* @Date 2024/5/28 22:01
*/
@Service
public class FluxGetInfoServiceImpl implements FluxGetInfoService {
@Autowired
private RestTemplate restTemplate;
@Override
public Result getInfo() {
String url = "http://39.98.50.223:8080/public/";
User user = new User("fluxmq", "fluxmq");
//登录
AcceptToken token = restTemplate.postForObject(url+"login", user, AcceptToken.class);
//请求头
HttpHeaders headers = new HttpHeaders();
headers.add("token", token.getAccessToken());
//封装请求头
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(headers);
ResponseEntity<String> exchange = restTemplate.exchange(url + "cluster", HttpMethod.GET, formEntity, String.class);
System.out.println(exchange);
System.out.println(exchange.getBody());
List<ApifoxModel> apifoxModel = JSON.parseArray(exchange.getBody(), ApifoxModel.class);
// get 获取具体所有信息
return Result.success(apifoxModel);
}
}