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

修改配置文件

parent 46b82b0a
...@@ -2,6 +2,7 @@ package com.mortals.xhx.busiz.web; ...@@ -2,6 +2,7 @@ package com.mortals.xhx.busiz.web;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.busiz.rsp.ApiResp; import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -95,8 +96,7 @@ public class ProxyController { ...@@ -95,8 +96,7 @@ public class ProxyController {
@PostMapping("/post") @PostMapping("/post")
@UnAuth @UnAuth
@CrossOrigin public Rest<String> proxyPost(
public ResponseEntity<String> proxyPost(
@RequestParam Map<String, String> params, // 透传 Query Params @RequestParam Map<String, String> params, // 透传 Query Params
@RequestBody(required = false) String body, // 透传 Body @RequestBody(required = false) String body, // 透传 Body
@RequestHeader Map<String, String> headers // 透传 Headers @RequestHeader Map<String, String> headers // 透传 Headers
...@@ -108,7 +108,10 @@ public class ProxyController { ...@@ -108,7 +108,10 @@ public class ProxyController {
if (ObjectUtils.isEmpty(path)) { if (ObjectUtils.isEmpty(path)) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue()); rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("path is empty!"); rsp.setMsg("path is empty!");
return ResponseEntity.ok().body(JSON.toJSONString(rsp));
return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
} }
String method = params.getOrDefault("method", "post"); String method = params.getOrDefault("method", "post");
...@@ -142,13 +145,17 @@ public class ProxyController { ...@@ -142,13 +145,17 @@ public class ProxyController {
// 发送请求 // 发送请求
try (Response response = client.newCall(requestBuilder.build()).execute()) { try (Response response = client.newCall(requestBuilder.build()).execute()) {
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
return ResponseEntity.status(response.code()).body(response.message()); return Rest.fail(response.code(), response.message());
// return ResponseEntity.status(response.code()).body(response.message());
} }
return ResponseEntity.status(response.code()).body(response.body().string()); return Rest.ok(response.body().string());
// return ResponseEntity.status(response.code()).body(response.body().string());
} catch (IOException e) { } catch (IOException e) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue()); rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("Proxy error: " + e.getMessage()); rsp.setMsg("Proxy error: " + e.getMessage());
return ResponseEntity.ok().body(JSON.toJSONString(rsp)); return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
} }
} else if ("get".equalsIgnoreCase(method)) { } else if ("get".equalsIgnoreCase(method)) {
Request.Builder requestBuilder = new Request.Builder() Request.Builder requestBuilder = new Request.Builder()
...@@ -164,19 +171,23 @@ public class ProxyController { ...@@ -164,19 +171,23 @@ public class ProxyController {
// 发送请求 // 发送请求
try (Response response = client.newCall(requestBuilder.build()).execute()) { try (Response response = client.newCall(requestBuilder.build()).execute()) {
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
return ResponseEntity.status(response.code()).body(response.message()); return Rest.fail(response.code(), response.message());
//return ResponseEntity.status(response.code()).body(response.message());
} }
return ResponseEntity.status(response.code()).body(response.body().string()); return Rest.ok(response.body().string());
// return ResponseEntity.status(response.code()).body(response.body().string());
} catch (IOException e) { } catch (IOException e) {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue()); rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("Proxy error: " + e.getMessage()); rsp.setMsg("Proxy error: " + e.getMessage());
return ResponseEntity.ok().body(JSON.toJSONString(rsp)); return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
} }
} else { } else {
rsp.setCode(ApiRespCodeEnum.FAILED.getValue()); rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg("method is not support!"); rsp.setMsg("method is not support!");
return ResponseEntity.ok().body(JSON.toJSONString(rsp)); return Rest.fail(rsp.getMsg());
// return ResponseEntity.ok().body(JSON.toJSONString(rsp));
} }
} }
......
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