This commit is contained in:
parent
ae37e501f6
commit
2254f94de7
5 changed files with 56 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
gateway-api.inbound-server.port=8080
|
||||
gateway-api.inbound-server.pathLOCM=test_tomcat9/p1
|
||||
gateway-api.inbound-server.pathLOSC=test_tomcat9/p2
|
||||
Loading…
Add table
Reference in a new issue