Commit 13329924 authored by 赵啸非's avatar 赵啸非

修改配置文件

parent 5e180d6f
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
......@@ -17,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
......@@ -27,6 +32,8 @@ import java.util.Map;
public class ProxyController {
private final WebClient webClient;
@Autowired
private UploadService uploadService;
private final OkHttpClient client = new OkHttpClient();
......@@ -177,48 +184,48 @@ public class ProxyController {
}
} else if ("get".equalsIgnoreCase(method)) {
Map<String, Object> map = req.toJavaObject(Map.class);
/* String bodyParams = getBodyParams(map);
log.info(bodyParams);*/
// String urlGet = HttpUtil.urlWithForm(url.toString(), map, Charset.forName("utf-8"), false);
try {
String resp = HttpUtil.get(url.toString(), map, 30 * 1000);
//String resp = HttpUtil.get(urlGet);
return Rest.ok("透传请求成功!", resp);
} catch (Exception e) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("Proxy error: " + e.getMessage());
return Rest.fail(rsp.getMsg());
}
//todo 将文件转换成base64
/* //url拼接参数
Request.Builder requestBuilder = new Request.Builder()
.url(urlGet);
// 透传 Headers(过滤掉 Host 避免冲突)
headers.forEach((key, value) -> {
if (!key.equalsIgnoreCase("host")) {
requestBuilder.addHeader(key, value);
if ("/base/matter/interinfo".equals(path)) {
JSONObject rspJson = JSON.parseObject(resp);
JSONObject data = rspJson.getJSONObject("data");
JSONObject interdata = data.getJSONObject("data");
String tid = interdata.getString("tid");
if (!ObjectUtils.isEmpty(tid) && "/file".startsWith(tid)) {
String filePath = uploadService.getFilePath(tid);
String base64Str = Base64.encode(new File(filePath));
log.info("base64Str:{}", base64Str);
interdata.put("tid", base64Str);
return Rest.ok("透传请求成功!", rspJson.toJSONString());
}
});
log.info("get透传请求地址,urlGet:{},rquestBuilder:{}",urlGet, JSON.toJSONString(requestBuilder));
// 发送请求
try (Response response = client.newCall(requestBuilder.build()).execute()) {
if (!response.isSuccessful()) {
return Rest.fail(response.code(), response.message());
//return ResponseEntity.status(response.code()).body(response.message());
}
return Rest.ok("透传请求成功!", response.body().string());
// return ResponseEntity.status(response.code()).body(response.body().string());
} catch (IOException e) {
// rspJson.get
//String resp = HttpUtil.get(urlGet);
return Rest.ok("透传请求成功!", resp);
} catch (Exception e) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("Proxy error: " + e.getMessage());
return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
}
}*/
} else {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("method is not support!");
......
......@@ -78,7 +78,7 @@ Content-Type: application/json
{
"id": "1",
"path": "/entservice/ent/life/cycle/interinfo",
"path": "/base/matter/interinfo",
"method": "get"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment