|
@@ -1,17 +1,28 @@
|
|
|
-package com.jzg.quotation.taikang.client;
|
|
|
|
|
|
|
+package com.jzg.quotation.taikang.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
-import com.jzg.quotation.commons.config.WebClientConfig;
|
|
|
|
|
|
|
+import com.jzg.quotation.taikang.client.HttpClient;
|
|
|
import com.jzg.quotation.taikang.model.api.*;
|
|
import com.jzg.quotation.taikang.model.api.*;
|
|
|
import com.jzg.quotation.taikang.model.entity.*;
|
|
import com.jzg.quotation.taikang.model.entity.*;
|
|
|
-import com.jzg.quotation.taikang.service.TKHttpAPIService;
|
|
|
|
|
|
|
+import io.netty.channel.ChannelOption;
|
|
|
|
|
+import io.netty.handler.timeout.ReadTimeoutHandler;
|
|
|
|
|
+import io.netty.handler.timeout.WriteTimeoutHandler;
|
|
|
import net.sf.cglib.beans.BeanCopier;
|
|
import net.sf.cglib.beans.BeanCopier;
|
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.api.*;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
|
|
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
+import reactor.netty.resources.ConnectionProvider;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.time.Duration;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -21,6 +32,8 @@ import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
|
|
public class TKHttpAPIServiceTest1 {
|
|
public class TKHttpAPIServiceTest1 {
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(TKHttpAPIServiceTest1.class);
|
|
|
|
|
+
|
|
|
private static TKHttpAPIService httpService;
|
|
private static TKHttpAPIService httpService;
|
|
|
|
|
|
|
|
private static String orderID;
|
|
private static String orderID;
|
|
@@ -35,7 +48,42 @@ public class TKHttpAPIServiceTest1 {
|
|
|
|
|
|
|
|
@BeforeAll
|
|
@BeforeAll
|
|
|
public static void before() {
|
|
public static void before() {
|
|
|
- WebClient webClient = new WebClientConfig().clientBuilder();
|
|
|
|
|
|
|
+ // 配置HTTP连接池
|
|
|
|
|
+ ConnectionProvider connectionProvider = ConnectionProvider
|
|
|
|
|
+ .builder("http")
|
|
|
|
|
+ .maxConnections(500)
|
|
|
|
|
+ .maxIdleTime(Duration.ofSeconds(30))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ // 配置HTTP客户端
|
|
|
|
|
+ reactor.netty.http.client.HttpClient httpClient = reactor.netty.http.client.HttpClient
|
|
|
|
|
+ .create(connectionProvider)
|
|
|
|
|
+ .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
|
|
|
|
+ .responseTimeout(Duration.ofSeconds(50))
|
|
|
|
|
+ .doOnConnected(conn ->
|
|
|
|
|
+ conn
|
|
|
|
|
+ .addHandlerLast(new ReadTimeoutHandler(50))
|
|
|
|
|
+ .addHandlerLast(new WriteTimeoutHandler(50)));
|
|
|
|
|
+ // 构建WebClient实例
|
|
|
|
|
+ WebClient webClient = WebClient
|
|
|
|
|
+ .builder()
|
|
|
|
|
+ .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
|
|
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ .defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ .filter(ExchangeFilterFunction.ofRequestProcessor(
|
|
|
|
|
+ clientRequest -> {
|
|
|
|
|
+ // 打印请求头信息
|
|
|
|
|
+ clientRequest
|
|
|
|
|
+ .headers()
|
|
|
|
|
+ .forEach((key, values) -> {
|
|
|
|
|
+ logger.info("请求头: {}: {}", key, values);
|
|
|
|
|
+ });
|
|
|
|
|
+ return Mono.just(clientRequest);
|
|
|
|
|
+ }
|
|
|
|
|
+ ))
|
|
|
|
|
+ .codecs(item->item.defaultCodecs().maxInMemorySize(10 * 1024 * 1024))
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
|
|
|
RequestComponent requestComponent = new RequestComponent(webClient);
|
|
RequestComponent requestComponent = new RequestComponent(webClient);
|
|
|
|
|
|
|
@@ -1165,4 +1213,21 @@ public class TKHttpAPIServiceTest1 {
|
|
|
System.out.println();
|
|
System.out.println();
|
|
|
System.out.println(JSON.toJSONString(result));
|
|
System.out.println(JSON.toJSONString(result));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @Order(22)
|
|
|
|
|
+ public void orderCompleteAgent() {
|
|
|
|
|
+ String no = "00671070808142500000005233";
|
|
|
|
|
+
|
|
|
|
|
+ long begin = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ OrderCompleteAgentResult orderCompleteAgentResult = httpService.orderCompleteAgent(no);
|
|
|
|
|
+
|
|
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("消耗时间:" + (end - begin));
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(JSON.toJSONString(orderCompleteAgentResult));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|