This commit is contained in:
parent
8e156bca82
commit
992bbacce6
8 changed files with 168 additions and 60 deletions
|
|
@ -15,6 +15,7 @@ public class GatewayApiSettings {
|
|||
private KafkaProducerSettings kafkaProducer;
|
||||
private KafkaConsumerSettings kafkaConsumer;
|
||||
private InboundServerSettings inboundServer;
|
||||
private InboundExternalServerSettings inboundExternalServer;
|
||||
|
||||
public HazelcastClientParams getHazelcast() {
|
||||
return hazelcast;
|
||||
|
|
@ -47,4 +48,12 @@ public class GatewayApiSettings {
|
|||
public void setInboundServer(InboundServerSettings inboundServer) {
|
||||
this.inboundServer = inboundServer;
|
||||
}
|
||||
|
||||
public InboundExternalServerSettings getInboundExternalServer() {
|
||||
return inboundExternalServer;
|
||||
}
|
||||
|
||||
public void setInboundExternalServer(InboundExternalServerSettings inboundExternalServer) {
|
||||
this.inboundExternalServer = inboundExternalServer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package ru.spcex.clearing.gatewayapi.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InboundExternalServerSettings {
|
||||
private String host;
|
||||
private String pathLOCM;
|
||||
private String pathLOSC;
|
||||
private Integer port;
|
||||
private Boolean enableSsl;
|
||||
private List<String> allowedTypes = new ArrayList<>();
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Boolean getEnableSsl() {
|
||||
return enableSsl;
|
||||
}
|
||||
|
||||
public void setEnableSsl(Boolean enableSsl) {
|
||||
this.enableSsl = enableSsl;
|
||||
}
|
||||
|
||||
public String getPathLOCM() {
|
||||
return pathLOCM;
|
||||
}
|
||||
|
||||
public void setPathLOCM(String pathLOCM) {
|
||||
this.pathLOCM = pathLOCM;
|
||||
}
|
||||
|
||||
public String getPathLOSC() {
|
||||
return pathLOSC;
|
||||
}
|
||||
|
||||
public void setPathLOSC(String pathLOSC) {
|
||||
this.pathLOSC = pathLOSC;
|
||||
}
|
||||
|
||||
public List<String> getAllowedTypes() {
|
||||
return allowedTypes;
|
||||
}
|
||||
|
||||
public void setAllowedTypes(List<String> allowedTypes) {
|
||||
this.allowedTypes = allowedTypes;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
package ru.spcex.clearing.gatewayapi.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InboundServerSettings {
|
||||
private String host;
|
||||
private String pathLOCM;
|
||||
private String pathLOSC;
|
||||
private Integer port;
|
||||
private Boolean enableSsl;
|
||||
private List<String> allowedTypes = new ArrayList<>();
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
|
|
@ -46,4 +50,12 @@ public class InboundServerSettings {
|
|||
public void setPathLOSC(String pathLOSC) {
|
||||
this.pathLOSC = pathLOSC;
|
||||
}
|
||||
|
||||
public List<String> getAllowedTypes() {
|
||||
return allowedTypes;
|
||||
}
|
||||
|
||||
public void setAllowedTypes(List<String> allowedTypes) {
|
||||
this.allowedTypes = allowedTypes;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,8 @@ public class GatewayController {
|
|||
commonResponse.setType(request.getType());
|
||||
commonResponse.setDatetime(request.getDatetime());
|
||||
commonResponse.setSection(request.getSection());
|
||||
commonResponse.setSection(request.getSection());
|
||||
commonResponse.setClearingSystem(request.getClearingSystem());
|
||||
if (success) {
|
||||
commonResponse.setCode(0L);
|
||||
commonResponse.setMessage("success");
|
||||
|
|
|
|||
|
|
@ -50,6 +50,9 @@ public class CommonRequest {
|
|||
@JsonProperty("section")
|
||||
@ApiModelProperty(value = "Секция (FOND или MKR)", example = "FOND")
|
||||
private String section;
|
||||
@JsonProperty("clearing_system")
|
||||
@ApiModelProperty(value = "Клиринговая система", example = "SPVB/LCC")
|
||||
private String clearingSystem;
|
||||
|
||||
public void validate(List<String> typeValidValues, List<Section> sectionValidValues) {
|
||||
if (!typeValidValues.isEmpty() && !typeValidValues.contains(type.toUpperCase())) {
|
||||
|
|
@ -92,4 +95,12 @@ public class CommonRequest {
|
|||
public void setSection(String section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
public String getClearingSystem() {
|
||||
return clearingSystem;
|
||||
}
|
||||
|
||||
public void setClearingSystem(String clearingSystem) {
|
||||
this.clearingSystem = clearingSystem;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ public class CommonResponse {
|
|||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("clearing_system")
|
||||
@ApiModelProperty(value = "Клиринговая система", example = "SPVB/LCC")
|
||||
private String clearingSystem;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -92,4 +96,12 @@ public class CommonResponse {
|
|||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getClearingSystem() {
|
||||
return clearingSystem;
|
||||
}
|
||||
|
||||
public void setClearingSystem(String clearingSystem) {
|
||||
this.clearingSystem = clearingSystem;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.clearing.classes.statics.data.register.GatewayResult;
|
||||
import ru.spcex.clearing.gatewayapi.config.GatewayApiSettings;
|
||||
import ru.spcex.clearing.gatewayapi.config.InboundExternalServerSettings;
|
||||
import ru.spcex.clearing.gatewayapi.config.InboundServerSettings;
|
||||
import ru.spcex.clearing.gatewayapi.controller.inbound.request.operations.SentAsset;
|
||||
import ru.spcex.clearing.gatewayapi.controller.outbound.request.OutboundRequest;
|
||||
|
|
@ -60,6 +61,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
private final UserRoleVerification userRoleVerification;
|
||||
private final RestTemplate restTemplate;
|
||||
private final InboundServerSettings inboundServerSettings;
|
||||
private final InboundExternalServerSettings inboundExternalServerSettings;
|
||||
private final Map<Long, List<SentAsset>> sentAssets;
|
||||
private final Map<UUID, OutboundRequest> outboundRequestByUuid;
|
||||
protected final Imdg<GatewayResult> gatewayResultImdg;
|
||||
|
|
@ -77,6 +79,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
this.restTemplate = restTemplate;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.inboundServerSettings = gatewayApiSettings.getInboundServer();
|
||||
this.inboundExternalServerSettings = gatewayApiSettings.getInboundExternalServer();
|
||||
this.sentAssets = sentAssets;
|
||||
this.outboundRequestByUuid = outboundRequestByUuid;
|
||||
this.gatewayResultImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_GatewayResult, GatewayResult.class);
|
||||
|
|
@ -112,26 +115,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
if (requestInfoUpdate != null) return;
|
||||
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
|
||||
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||
.type(OutboundRequestType.MEMBER_ON_DEMAND.getKey())
|
||||
.build();
|
||||
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||
|
||||
outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, request, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("LOCM task complete, success response : {}", bodyResponse);
|
||||
}
|
||||
sendRequest(outboundFondRequest);
|
||||
}
|
||||
|
||||
public void requestOnLimit(BaseRequest<LimExportedRequest> userRequest) {
|
||||
LimExportedRequest exportedRequest = userRequest.getRequestPayload();
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
|
||||
Map<String, Object> content = Map.of("file", exportedRequest.getLimFileName());
|
||||
|
||||
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||
|
|
@ -140,14 +133,9 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
.content(content)
|
||||
.build();
|
||||
|
||||
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||
outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest);
|
||||
gatewayResultImdg.insert(GatewayResultBuilder.builder().outboundRequest(outboundFondRequest).build());
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, request, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Limit request complete, success response: {}", bodyResponse);
|
||||
}
|
||||
sendRequest(outboundFondRequest);
|
||||
}
|
||||
|
||||
public void requestOnDemandSecurity(BaseRequest<GatewayTaskRequest> userRequest) {
|
||||
|
|
@ -158,8 +146,6 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
|
||||
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||
.section(Section.FOND.getKey())
|
||||
.type(OutboundRequestType.ON_DEMAND.getKey())
|
||||
|
|
@ -175,28 +161,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
.type(OutboundRequestType.ON_DEMAND.getKey())
|
||||
.build();
|
||||
|
||||
HttpEntity<OutboundRequest> requestFond = makeDefaultRequest(outboundFondRequest);
|
||||
HttpEntity<OutboundRequest> requestMKR = makeDefaultRequest(outboundMkrRequest);
|
||||
HttpEntity<OutboundRequest> requestCURR = makeDefaultRequest(outboundCurrRequest);
|
||||
|
||||
outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest);
|
||||
outboundRequestByUuid.put(outboundMkrRequest.getId(), outboundMkrRequest);
|
||||
outboundRequestByUuid.put(outboundCurrRequest.getId(), outboundCurrRequest);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, requestFond, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("LOSC task 1/3 complete (FOND section), success response: {}", bodyResponse);
|
||||
}
|
||||
response = restTemplate.exchange(url, HttpMethod.POST, requestMKR, SuccessResponse.class);
|
||||
bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("LOSC task 2/3 complete (MKR section), success response: {}", bodyResponse);
|
||||
}
|
||||
response = restTemplate.exchange(url, HttpMethod.POST, requestCURR, SuccessResponse.class);
|
||||
bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("LOSC task 3/3 complete (CURR section), success response: {}", bodyResponse);
|
||||
}
|
||||
|
||||
sendRequest(outboundFondRequest);
|
||||
log.debug("LOSC task 1/3 complete (FOND section)");
|
||||
sendRequest(outboundMkrRequest);
|
||||
log.debug("LOSC task 2/3 complete (MKR section)");
|
||||
sendRequest(outboundCurrRequest);
|
||||
log.debug("LOSC task 3/3 complete (CURR section)");
|
||||
}
|
||||
|
||||
public void requestOnAsset(BaseRequest<AssetOperationListRequest> request) {
|
||||
|
|
@ -224,16 +198,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
.content(content).build();
|
||||
|
||||
gatewayBuilder.outboundRequest(outboundRequest);
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||
try {
|
||||
outboundRequestByUuid.put(outboundRequest.getId(), outboundRequest);
|
||||
gatewayResultImdg.insert(gatewayBuilder.build());
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
sendRequest(outboundRequest);
|
||||
} catch (Throwable err) {
|
||||
log.error("Exchange error: {}", ExceptionUtils.getStackTrace(err));
|
||||
} finally {
|
||||
|
|
@ -262,13 +230,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
.type(reportType.getKey())
|
||||
.content(content).build();
|
||||
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
sendRequest(outboundRequest);
|
||||
}
|
||||
|
||||
public void requestOnTkr(BaseRequest<SendTkrRequest> request) {
|
||||
|
|
@ -286,13 +248,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
.outboundRequest(outboundRequest)
|
||||
.build();
|
||||
gatewayResultImdg.insert(gatewayResult);
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
sendRequest(outboundRequest);
|
||||
}
|
||||
|
||||
protected void makeContentByReportRequest(Map<String, Object> content, ReportPart reportPart) {
|
||||
|
|
@ -324,6 +280,35 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendRequest(OutboundRequest request) {
|
||||
if (inboundServerSettings.getAllowedTypes().isEmpty() ||
|
||||
inboundServerSettings.getAllowedTypes().contains(request.getType())) {
|
||||
String url = formingInboundUrl(inboundServerSettings.getEnableSsl(),
|
||||
inboundServerSettings.getHost(),
|
||||
inboundServerSettings.getPort(),
|
||||
inboundServerSettings.getPathLOCM());
|
||||
exchange(request, url);
|
||||
}
|
||||
|
||||
if (inboundExternalServerSettings.getAllowedTypes().isEmpty() ||
|
||||
inboundExternalServerSettings.getAllowedTypes().contains(request.getType())) {
|
||||
String url = formingInboundUrl(inboundExternalServerSettings.getEnableSsl(),
|
||||
inboundExternalServerSettings.getHost(),
|
||||
inboundExternalServerSettings.getPort(),
|
||||
inboundExternalServerSettings.getPathLOCM());
|
||||
exchange(request, url);
|
||||
}
|
||||
}
|
||||
|
||||
private void exchange(OutboundRequest request, String url){
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(request);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
}
|
||||
|
||||
public String formingInboundUrl(String path) {
|
||||
return "%s://%s:%s/%s".formatted(
|
||||
inboundServerSettings.getEnableSsl() ? "https" : "http",
|
||||
|
|
@ -333,6 +318,15 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
);
|
||||
}
|
||||
|
||||
public String formingInboundUrl(Boolean enableSsl, String host, Integer port, String path) {
|
||||
return "%s://%s:%s/%s".formatted(
|
||||
enableSsl ? "https" : "http",
|
||||
host,
|
||||
port,
|
||||
path
|
||||
);
|
||||
}
|
||||
|
||||
private void logUnknownProperties(BaseRequest<GatewayTaskRequest> request) {
|
||||
Map<String, Object> unknownProperties = request.getUnknownProperties();
|
||||
for (Map.Entry<String, Object> unknownProperty : unknownProperties.entrySet()) {
|
||||
|
|
|
|||
|
|
@ -29,4 +29,11 @@ gateway-api.inbound-server.enable-ssl=false
|
|||
gateway-api.inbound-server.host=10.200.200.183
|
||||
gateway-api.inbound-server.port=8084
|
||||
gateway-api.inbound-server.pathLOCM=test_rest/inbound_request
|
||||
gateway-api.inbound-server.pathLOSC=test_rest/inbound_request
|
||||
gateway-api.inbound-server.pathLOSC=test_rest/inbound_request
|
||||
gateway-api.inbound-server.allowed-types=ASSET_OPERATION,ON_DEMAND
|
||||
|
||||
gateway-api.inbound-external-server.enable-ssl=false
|
||||
gateway-api.inbound-external-server.host=10.200.200.183
|
||||
gateway-api.inbound-external-server.port=8084
|
||||
gateway-api.inbound-external-server.pathLOCM=test_rest/inbound_request
|
||||
gateway-api.inbound-external-server.allowed-types=FILL_LIMITS,MEMBER_ON_DEMAND
|
||||
Loading…
Add table
Reference in a new issue