From 2254f94de7df37e78cade9e0e210680266930d47 Mon Sep 17 00:00:00 2001 From: akulikov Date: Mon, 5 Jun 2023 18:15:52 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-301 --- .../gatewayapi/config/LoggingInterceptor.java | 34 +++++++++++++++++++ .../gatewayapi/config/RestTemplateConfig.java | 5 ++- .../gatewayapi/request/InboundRequest.java | 12 ++++++- .../gatewayapi/service/GatewayService.java | 5 +-- .../src/main/resources/application.properties | 8 ++--- 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/LoggingInterceptor.java diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/LoggingInterceptor.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/LoggingInterceptor.java new file mode 100644 index 000000000..2c9d269fe --- /dev/null +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/LoggingInterceptor.java @@ -0,0 +1,34 @@ +package ru.spcex.clearing.gatewayapi.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.util.StreamUtils; + +import java.io.IOException; +import java.nio.charset.Charset; + +public class LoggingInterceptor implements ClientHttpRequestInterceptor { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Override + public ClientHttpResponse intercept(HttpRequest request, + byte[] body, + ClientHttpRequestExecution execution) throws IOException { + + log.info("Request URI: " + request.getURI()); + log.info("Request method: " + request.getMethod()); + log.info("Request body: " + new String(body, "UTF-8")); + + ClientHttpResponse response = execution.execute(request, body); + + log.info("Response status code: " + response.getStatusCode()); + log.info("Response body: " + StreamUtils.copyToString(response.getBody(), Charset.defaultCharset())); + + return response; + } +} \ No newline at end of file diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/RestTemplateConfig.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/RestTemplateConfig.java index 08d62366d..f92c5ab3f 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/RestTemplateConfig.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/RestTemplateConfig.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; import java.time.Duration; +import java.util.Collections; @Configuration public class RestTemplateConfig { @@ -19,9 +20,11 @@ public class RestTemplateConfig { @Bean("rest-template") public RestTemplate restTemplate() { - return builder + RestTemplate restTemplate = builder .setConnectTimeout(Duration.ofMillis(10000)) .setReadTimeout(Duration.ofMillis(40000)) .build(); + restTemplate.setInterceptors(Collections.singletonList(new LoggingInterceptor())); + return restTemplate; } } \ No newline at end of file diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/request/InboundRequest.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/request/InboundRequest.java index 539dc9e67..56d4801bf 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/request/InboundRequest.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/request/InboundRequest.java @@ -2,8 +2,10 @@ package ru.spcex.clearing.gatewayapi.request; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.swagger.annotations.ApiModelProperty; import ru.spcex.clearing.gatewayapi.config.deserializers.InstantDeserializer; +import ru.spcex.clearing.gatewayapi.config.serializers.InstantSerializer; import java.time.Instant; import java.util.UUID; @@ -32,6 +34,7 @@ public class InboundRequest { @JsonProperty("datetime") @JsonDeserialize(using = InstantDeserializer.class) + @JsonSerialize(using = InstantSerializer.class) @ApiModelProperty( value = "Передавать дату и время формирования JSON объекта в формате «ДД.ММ.ГГГГ ЧЧ:ММ:СС:ссс».", example = "01.01.2023 12:34:56:789" @@ -42,7 +45,14 @@ public class InboundRequest { @ApiModelProperty( value = "Секция (FOND или MKR)", example = "FOND" ) - private String section; + private String section = ""; + + // todo Пока так, чтобы отсылал null, в дальнейшем тип надо заменить на используемый в запросе. Возможно с помощью параметризации + @JsonProperty("content") + @ApiModelProperty( + value = "Контент", example = "null" + ) + private String content = null; public UUID getId() { diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java index 124b86a6d..360545a3f 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java @@ -22,6 +22,7 @@ import ru.spcex.platform.enumeration.Section; import ru.spcex.platform.enumeration.Task; import java.time.Instant; +import java.util.Collections; import java.util.Map; import java.util.UUID; @@ -66,6 +67,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); + httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); InboundRequest inboundRequest = new InboundRequest(); inboundRequest.setId(UUID.randomUUID()); inboundRequest.setType("MEMBER_ON_DEMAND"); @@ -89,11 +91,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean { String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); + httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); InboundRequest inboundRequest = new InboundRequest(); inboundRequest.setId(UUID.randomUUID()); inboundRequest.setType("ON_DEMAND"); - // todo здесь возникла проблема: место обработки LOCM одно, но в этом месте могут быть сформированы запросы с разными - // section, нужно уточнить как определять какой именно section отправлять в запросе inboundRequest.setSection(Section.FOND.getKey()); inboundRequest.setDatetime(Instant.now()); HttpEntity request = new HttpEntity<>(inboundRequest, httpHeaders); diff --git a/clearing-parent/gateway-api/src/main/resources/application.properties b/clearing-parent/gateway-api/src/main/resources/application.properties index a67693f48..0b44aca31 100644 --- a/clearing-parent/gateway-api/src/main/resources/application.properties +++ b/clearing-parent/gateway-api/src/main/resources/application.properties @@ -25,8 +25,8 @@ gateway-api.kafka-consumer.auto-offset-reset=latest gateway-api.kafka-consumer.linger-ms=1 gateway-api.kafka-consumer.buffer-memory=33554432 -gateway-api.inbound-server.enable-ssl=true +gateway-api.inbound-server.enable-ssl=false gateway-api.inbound-server.host=localhost -gateway-api.inbound-server.port=9999 -gateway-api.inbound-server.pathLOCM=/inbound_request -gateway-api.inbound-server.pathLOSC=/inbound_request \ No newline at end of file +gateway-api.inbound-server.port=8080 +gateway-api.inbound-server.pathLOCM=test_tomcat9/p1 +gateway-api.inbound-server.pathLOSC=test_tomcat9/p2 \ No newline at end of file