|
|
@@ -67,9 +67,7 @@ public class RequestComponent {
|
|
|
return filtered;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
private final WebClient webClient;
|
|
|
|
|
|
private final WebClientConfig webClientConfig;
|
|
|
@@ -320,11 +318,11 @@ public class RequestComponent {
|
|
|
.block();
|
|
|
if (rawResponse == null) {
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "No response received",
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- "No response received".getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "No response received",
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ "No response received".getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
String responseBody = rawResponse.getBody();
|
|
|
@@ -341,11 +339,11 @@ public class RequestComponent {
|
|
|
} catch (Exception e) {
|
|
|
log.error("JSON解析失败,过滤后的响应内容: {}", filteredResponse, e);
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
- rawResponse.getHeaders(),
|
|
|
- filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
+ rawResponse.getHeaders(),
|
|
|
+ filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
// 构建返回的ResponseEntity
|
|
|
@@ -363,11 +361,11 @@ public class RequestComponent {
|
|
|
// 处理其他异常
|
|
|
log.error("请求失败", e);
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "Request failed: " + e.getMessage(),
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "Request failed: " + e.getMessage(),
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
@@ -380,8 +378,8 @@ public class RequestComponent {
|
|
|
* @param body
|
|
|
* @param responseClass
|
|
|
* @param headers
|
|
|
- * @return ResponseEntity<Response>
|
|
|
* @param <Response>
|
|
|
+ * @return ResponseEntity<Response>
|
|
|
*/
|
|
|
public <Response> ResponseEntity<Response> postWithMono(String url, String body, Class<Response> responseClass, HttpHeaders headers) {
|
|
|
WebClient webClient = selectNoSSLWebClient();
|
|
|
@@ -396,7 +394,6 @@ public class RequestComponent {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 构造post请求
|
|
|
*
|
|
|
@@ -431,11 +428,11 @@ public class RequestComponent {
|
|
|
|
|
|
if (rawResponse == null) {
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "No response received",
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- "No response received".getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "No response received",
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ "No response received".getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -453,11 +450,11 @@ public class RequestComponent {
|
|
|
} catch (Exception e) {
|
|
|
log.error("JSON解析失败,过滤后的响应内容: {}", filteredResponse, e);
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
- rawResponse.getHeaders(),
|
|
|
- filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
+ rawResponse.getHeaders(),
|
|
|
+ filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -478,11 +475,11 @@ public class RequestComponent {
|
|
|
// 处理其他异常
|
|
|
log.error("请求失败", e);
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "Request failed: " + e.getMessage(),
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "Request failed: " + e.getMessage(),
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
@@ -524,20 +521,18 @@ public class RequestComponent {
|
|
|
} catch (Exception e) {
|
|
|
// 如果JSON解析失败,抛出异常
|
|
|
return Mono.error(new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "JSON parsing failed after filtering: " + e.getMessage(),
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ filteredResponse.getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
));
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
// 等待结果并构建ResponseEntity
|
|
|
Response result = resultMono.block();
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
-
|
|
|
// 获取原始响应状态码
|
|
|
ResponseEntity<String> rawResponse = webClient.post()
|
|
|
.uri(url)
|
|
|
@@ -552,18 +547,17 @@ public class RequestComponent {
|
|
|
|
|
|
int statusCode = rawResponse != null ? rawResponse.getStatusCode().value() : 200;
|
|
|
return ResponseEntity.status(statusCode).headers(responseHeaders).body(result);
|
|
|
-
|
|
|
} catch (WebClientResponseException e) {
|
|
|
e.printStackTrace();
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
// 处理其他异常
|
|
|
throw new WebClientResponseException(
|
|
|
- 500,
|
|
|
- "Request failed: " + e.getMessage(),
|
|
|
- HttpHeaders.EMPTY,
|
|
|
- e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
- null
|
|
|
+ 500,
|
|
|
+ "Request failed: " + e.getMessage(),
|
|
|
+ HttpHeaders.EMPTY,
|
|
|
+ e.getMessage().getBytes(StandardCharsets.UTF_8),
|
|
|
+ null
|
|
|
);
|
|
|
}
|
|
|
}
|