parsed = parsePostBody(exchange);
+
+ String fullCLass = parsed.get("field0");
+ String qName = parsed.get("field1");
+ String msg = parsed.get("field2");
+ writeLine(os, "Sending message to" + qName + "
");
+ try {
+ Long n = kafkaService.putMessage(fullCLass, qName, msg);
+ writeLine(os, "Message #" + n + " success send: ");
+ } catch (Exception er) {
+ writeLine(os, "Message error:" + ExceptionUtils.getStackTrace(er) + "
");
+ }
+ writeLine(os, "" + msg + "
");
+ } else {
+ writeLine(os, "HTTP method " + exchange.getRequestMethod() + ". Use POST method.
");
}
- port = Integer.parseInt(settings.getPort().trim());
- String url = settings.getContextPath().trim();
- log.info("Controller for debug reload star at port {} with url \"{}\"", port, url);
- this.server = HttpServer.create(new InetSocketAddress(port), 0);
- IndexHandler index=new IndexHandler();
- server.createContext(url, index);
- server.createContext(url+"/index.html", index);
- server.createContext(url+"/imdg", new ImdgHandler());
- server.createContext(url+"/kafka", new KafkaHandler());
- server.setExecutor(null); // default
- server.start();
- } catch (Throwable t) {
- log.error("Can not start debug HTTP server in port {}: {}", port, ExceptionUtils.getStackTrace(t));
}
}
- @Override
- public void destroy() throws Exception {
- if (server != null) {
- server.stop(100);
- log.info("Controller for reload stop.");
- }
- }
-
-
- class IndexHandler extends HtmlHandler {
- @Override
- public void makePage(HttpExchange t, OutputStream os) throws IOException {
- writeLine(os, "Welcome!");
- writeLine(os, " Reload IMDG. ");
- writeLine(os, " Send to kafka. ");
- }
- }
- class KafkaHandler extends HtmlHandler {
- @Override
- public void makePage(HttpExchange t, OutputStream os) throws IOException {
- writeLine(os, "Welcome kafka send!");
- byte[] jsonB = t.getRequestBody().readAllBytes();
- //t.getRequestHeaders().getFirst()
- String json=new String(jsonB, "windows-1251");
- //todo ...
- writeLine(os, " Reload IMDG. ");
- writeLine(os, " Send to kafka. ");
- }
- }
-
- class ImdgHandler extends HtmlHandler {
+ class ImdgHandler extends CustomHtmlHandler {
@Override
public void makePage(HttpExchange t, OutputStream os) throws IOException {
writeLine(os, "Wait, reload all maps from DB... ");
@@ -110,30 +91,4 @@ public class Controller implements InitializingBean, DisposableBean {
}
}
-
- abstract class HtmlHandler implements HttpHandler {
- public abstract void makePage(HttpExchange t, OutputStream os) throws IOException;
-
- @Override
- public void handle(HttpExchange t) throws IOException {
- log.info("{} request by user \"{}\"", getClass().getSimpleName(), t.getRemoteAddress().getAddress());
- t.sendResponseHeaders(200, 0);
- t.setAttribute("Content-Type", "text/html; charset=windows-1251"); // or "text/plain или text/html; charset=windows-1251"
- try (OutputStream os = t.getResponseBody()) {
- writeLine(os, "\n\n");
- writeLine(os, "");
- makePage(t, os);
- writeLine(os, "
");
- writeLine(os, "");
- }
- log.trace("HTTP Request done.");
- }
-
- void writeLine(OutputStream os, String text) throws IOException {
- if (text != null)
- os.write(text.getBytes("windows-1251"));
- os.write("\n".getBytes("windows-1251"));
- }
-
- }
-}
+}
\ No newline at end of file
diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java
new file mode 100644
index 000000000..bd7401817
--- /dev/null
+++ b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java
@@ -0,0 +1,185 @@
+package ru.spcex.clearing.test.controller;
+
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+import java.io.*;
+import java.net.InetSocketAddress;
+import java.net.URLDecoder;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * Простой HTTP server и фреимворк для HTML5 страниц.
+ * Только для отладки.
+ */
+public abstract class HttpServerSimpleFramework implements InitializingBean, DisposableBean {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+ protected HttpServer server;
+ protected Integer port;
+ protected String baseUrl;
+
+
+ public HttpServerSimpleFramework(Integer port, String baseUrl) {
+ this.port = port;
+ this.baseUrl = baseUrl;
+ }
+
+ protected void createContextPages(HttpServer server, String baseUrl) throws IOException {
+ server.createContext(baseUrl, new RedirectPage(baseUrl + "index.html"));
+ server.createContext(baseUrl + "index.html", staticPageFromResource("pages/index.html", null));
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ Integer port = null; // 8080
+ try {
+ log.info("Server star at port {} with url \"{}\"", port, baseUrl);
+ this.server = HttpServer.create(new InetSocketAddress(port), 0);
+ server.setExecutor(null); // default
+ createContextPages(server, baseUrl);
+ server.start();
+ } catch (Throwable t) {
+ log.error("Can not start HTTP server in port {}: {}", port, ExceptionUtils.getStackTrace(t));
+ throw t;
+ }
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ if (server != null) {
+ server.stop(100);
+ log.info("HTTP test controller stop.");
+ }
+ }
+
+ public static Map parsePostBody(HttpExchange exchange) throws IOException {
+ try (InputStreamReader isr = new InputStreamReader(exchange.getRequestBody(), "utf-8");
+ BufferedReader br = new BufferedReader(isr)) {
+ String query = br.readLine();
+ return parsePostBody(query);
+ }
+ }
+
+ public static Map parsePostBody(String data) {
+ String[] elems = data.split("&");
+ Map param = new LinkedHashMap<>();
+ for (String token : elems) {
+ int separator = token.indexOf("=");
+ if (separator == -1) throw new IllegalArgumentException("Separator '=' not found in: " + token);
+ String key = token.substring(0, separator);
+ String value = token.substring(separator + 1, token.length());
+ key = URLDecoder.decode(key);
+ value = URLDecoder.decode(value);
+ param.put(key, value);
+ }
+ return param;
+ }
+
+ public abstract class CustomHtmlHandler implements HttpHandler {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+ protected final Charset encodung = Charset.forName("windows-1251");
+
+ public abstract void makePage(HttpExchange he, OutputStream os) throws IOException;
+
+ @Override
+ public void handle(HttpExchange he) throws IOException {
+ log.info("{} request by user \"{}\" {} url {}", getClass().getSimpleName(),
+ he.getRemoteAddress().getAddress(), he.getRequestMethod(), he.getRequestURI());
+ he.sendResponseHeaders(200, 0);
+ he.setAttribute("Content-Type", "text/html; charset=windows-1251"); // or "text/plain или text/html; charset=windows-1251"
+ try (OutputStream os = he.getResponseBody()) {
+ writeLine(os, "\n\n");
+ writeLine(os, "");
+ makePage(he, os);
+ writeLine(os, "
");
+ writeLine(os, "");
+ } catch (Exception e) {
+ log.error("Content build error at page \"{}\": {}",
+ he.getRequestURI(), ExceptionUtils.getStackTrace(e));
+ throw e;
+ }
+ log.trace("HTTP Request done.");
+ }
+
+ protected void writeLine(OutputStream os, String text) throws IOException {
+ if (text != null)
+ os.write(text.getBytes(encodung));
+ os.write("\n".getBytes(encodung));
+ }
+ }
+
+ public static class RedirectPage implements HttpHandler {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+ protected String toUrl;
+
+ public RedirectPage(String toUrl) {
+ this.toUrl = Objects.requireNonNull(toUrl);
+ }
+
+ @Override
+ public void handle(HttpExchange he) throws IOException {
+ log.info("Access {} url \"{}\" IP {}; redirect to \"{}\"", he.getRequestMethod(),
+ he.getRequestURI(), he.getRemoteAddress().getAddress().getHostAddress(), toUrl);
+ Headers responseHeaders = he.getResponseHeaders();
+ responseHeaders.set("Location", toUrl);
+ he.sendResponseHeaders(301, 0); // https://developer.mozilla.org/ru/docs/Web/HTTP/Redirections
+ he.close();
+ }
+ }
+
+ public static StaticPage staticPageFromFile(File fromFile, String encoding) throws IOException {
+ if (encoding == null) encoding = "windows-1251";
+ String str = Files.readString(fromFile.toPath(), Charset.forName(encoding));
+ StaticPage page = new StaticPage(str);
+ page.encoding = Charset.forName(encoding);
+ page.contentType = "text/html; charset=" + page.encoding.name();
+ return page;
+ }
+
+ public static StaticPage staticPageFromResource(String inRes, String encoding) throws IOException {
+ if (encoding == null) encoding = "windows-1251";
+ String str = new String(StaticPage.class.getClassLoader().getResourceAsStream(inRes).readAllBytes(), encoding);
+ StaticPage page = new StaticPage(str);
+ page.encoding = Charset.forName(encoding);
+ page.contentType = "text/html; charset=" + page.encoding.name();
+ return page;
+ }
+
+ public static class StaticPage implements HttpHandler {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+ protected Charset encoding = Charset.forName("windows-1251");
+ protected String contentType = "text/html; charset=" + encoding.name();
+ protected String content;
+
+ public StaticPage(String content) {
+ this.content = Objects.requireNonNull(content);
+ }
+
+ @Override
+ public void handle(HttpExchange he) throws IOException {
+ log.info("Access {} url \"{}\" IP {}", he.getRequestMethod(), he.getRequestURI(),
+ he.getRemoteAddress().getAddress().getHostAddress());
+ he.sendResponseHeaders(200, 0);
+ if (contentType != null)
+ he.setAttribute("Content-Type", contentType);
+ try (OutputStream os = he.getResponseBody()) {
+ os.write(content.getBytes(encoding));
+ } catch (Exception err) {
+ he.sendResponseHeaders(500, 0); // too late
+ log.error("StaticPage error {}", ExceptionUtils.getStackTrace(err));
+ }
+ }
+ }
+}
diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/ImdgController.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/ImdgController.java
deleted file mode 100644
index 50d142a38..000000000
--- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/ImdgController.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package ru.spcex.clearing.test.controller;
-
-
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import ru.spcex.clearing.test.ImdgService;
-import ru.spcex.clearing.test.config.settings.ControllerSettings;
-import ru.spcex.clearing.test.config.settings.TestServiceSettings;
-import ru.spcex.platform.utils.log.ExceptionUtils;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-import java.time.LocalDateTime;
-
-@Service
-public class ImdgController implements InitializingBean, DisposableBean {
- protected final Logger log = LoggerFactory.getLogger(getClass());
- protected HttpServer server;
-
- protected final ControllerSettings settings;
- protected final ImdgService imdgService;
-
- @Autowired
- public ImdgController(ImdgService imdgService, TestServiceSettings settings) {
- this.imdgService = imdgService;
- this.settings = settings.getControllerSettings();
- }
-
- @Override
- public void afterPropertiesSet() throws Exception {
- Integer port = null; // 8701
- try {
- if (settings == null || StringUtils.isEmpty(settings.getPort())) {
- log.debug("Debug HTTP port not set, do not init HTTP controller service.");
- return;
- }
- port = Integer.parseInt(settings.getPort().trim());
- String url = StringUtils.isBlank(settings.getContextPath()) ? "/imdg" : settings.getContextPath().trim();
- log.info("Controller for debug reload star at port {} with url \"{}\"", port, url);
- this.server = HttpServer.create(new InetSocketAddress(port), 0);
- server.createContext(url, new MyHandler());
- server.setExecutor(null); // default
- server.start();
- } catch (Throwable t) {
- log.error("Can not start debug HTTP server in port {}: {}", port, ExceptionUtils.getStackTrace(t));
- }
- }
-
- @Override
- public void destroy() throws Exception {
- if (server != null) {
- server.stop(100);
- log.info("Controller for reload stop.");
- }
- }
-
- class MyHandler implements HttpHandler {
- @Override
- public void handle(HttpExchange t) throws IOException {
- log.info("Reload request by user \"{}\"", t.getRemoteAddress().getAddress());
- t.sendResponseHeaders(200, 0);
- t.setAttribute("Content-Type", "text/html; charset=windows-1251"); // or "text/plain или text/html; charset=windows-1251"
- try (OutputStream os = t.getResponseBody()) {
- writeHead(os);
- writeLine(os, "Wait, reload all maps from DB... ");
- synchronized (ImdgController.this) {
- os.flush();
- try {
- long clock = System.currentTimeMillis();
- int count = imdgService.reloadMapFromDB();
- clock = System.currentTimeMillis() - clock;
- writeLine(os, count + " map per " + clock + " ms");
- } catch (Throwable e) {
- String msg = "Error reload: " + ExceptionUtils.getStackTrace(e);
- log.error(msg);
- writeLine(os, msg);
- }
- }
- writeLine(os, "Done. " + LocalDateTime.now() + "");
- writeLine(os, " Reload again. ");
- writeEnd(os);
- } //os.close();
- log.trace("HTTP Request done.");
- }
-
- void writeHead(OutputStream os) throws IOException {
- writeLine(os, "\n\n");
- writeLine(os, "");
- }
-
- void writeLine(OutputStream os, String text) throws IOException {
- if (text != null)
- os.write(text.getBytes("windows-1251"));
- os.write("\n".getBytes("windows-1251"));
- }
-
- void writeEnd(OutputStream os) throws IOException {
- writeLine(os, "
");
- writeLine(os, "");
- }
- }
-}
diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java
index d3c2af435..146cc7246 100644
--- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java
+++ b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java
@@ -1,59 +1,59 @@
-package ru.spcex.clearing.test.controller.kafka;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonRawValue;
-import com.fasterxml.jackson.databind.JsonNode;
-import io.swagger.annotations.ApiModelProperty;
-import ru.spcex.clearing.platform.messaging.domain.ActionType;
-import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
-
-public class AnyKafkaMessageAction /*implements IAction*/ {
- @ApiModelProperty(value = "полное имя класса payload для BaseRequest", example = "ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest")
- @JsonProperty
- private String fullClassName;
- @JsonProperty
- private String topicName;
- @JsonRawValue
- public String json;
-
- @JsonProperty("json")
- private void unpackRawJson(JsonNode json) {
- this.json = json.toString();
- }
-
-// @Override
- public TradingClearingRegistryNewRequest toRequest() {
- var req = new TradingClearingRegistryNewRequest();
- return req;
- }
-
- @ApiModelProperty(hidden = true)
-// @Override
- public ActionType getActionType() {
- return ActionType.SYSTEM;
- }
-
- public String getFullClassName() {
- return fullClassName;
- }
-
- public void setFullClassName(String fullClassName) {
- this.fullClassName = fullClassName;
- }
-
- public String getTopicName() {
- return topicName;
- }
-
- public void setTopicName(String topicName) {
- this.topicName = topicName;
- }
-
- public String getJson() {
- return json;
- }
-
- public void setJson(String json) {
- this.json = json;
- }
-}
+//package ru.spcex.clearing.test.controller.kafka;
+//
+//import com.fasterxml.jackson.annotation.JsonProperty;
+//import com.fasterxml.jackson.annotation.JsonRawValue;
+//import com.fasterxml.jackson.databind.JsonNode;
+//import io.swagger.annotations.ApiModelProperty;
+//import ru.spcex.clearing.platform.messaging.domain.ActionType;
+//import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
+//
+//public class AnyKafkaMessageAction /*implements IAction*/ {
+// @ApiModelProperty(value = "полное имя класса payload для BaseRequest", example = "ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest")
+// @JsonProperty
+// private String fullClassName;
+// @JsonProperty
+// private String topicName;
+// @JsonRawValue
+// public String json;
+//
+// @JsonProperty("json")
+// private void unpackRawJson(JsonNode json) {
+// this.json = json.toString();
+// }
+//
+//// @Override
+// public TradingClearingRegistryNewRequest toRequest() {
+// var req = new TradingClearingRegistryNewRequest();
+// return req;
+// }
+//
+// @ApiModelProperty(hidden = true)
+//// @Override
+// public ActionType getActionType() {
+// return ActionType.SYSTEM;
+// }
+//
+// public String getFullClassName() {
+// return fullClassName;
+// }
+//
+// public void setFullClassName(String fullClassName) {
+// this.fullClassName = fullClassName;
+// }
+//
+// public String getTopicName() {
+// return topicName;
+// }
+//
+// public void setTopicName(String topicName) {
+// this.topicName = topicName;
+// }
+//
+// public String getJson() {
+// return json;
+// }
+//
+// public void setJson(String json) {
+// this.json = json;
+// }
+//}
diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java
index fa035d507..3d930fd85 100644
--- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java
+++ b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java
@@ -1,88 +1,88 @@
-package ru.spcex.clearing.test.controller.kafka;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
-import org.springframework.util.ClassUtils;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
-import ru.spcex.platform.utils.enumeration.EnumMessage;
-import ru.spcex.platform.utils.enumeration.IErrorEnumId;
-import ru.spcex.platform.utils.error.ValidationException;
-import ru.spcex.platform.utils.text.TextUtil;
-
-@Controller
-@RequestMapping("/anonymous/kafka-api")
-public class KafkaApiController {
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final KafkaSender kafkaSender;
- private static final ObjectMapper json = new ObjectMapper();
- static {
- }
-
- enum BackEndError implements IErrorEnumId {
- ValidationError(9000L),
- UnknownJsonProperty(9001L),
- FailedToReadHttpMessage(9002L),
- KeycloakRepeatedRoles(9003L),
- DictionaryNotFound(9004L),
- ResourceNotFound(9005L)
- ;
- private final Long id;
-
- BackEndError(Long id) {
- this.id = id;
- }
-
- @Override
- public Long getId() {
- return id;
- }
- }
-
- @Autowired
- public KafkaApiController(KafkaSender kafkaSender) {
- this.kafkaSender = kafkaSender;
- }
-
- @ApiOperation(value = "Test backend-api availability.")
- @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = String.class)})
- @RequestMapping(method = RequestMethod.POST, path = "/any/message", produces = MediaType.TEXT_PLAIN_VALUE)
- @ResponseBody
- public String processGet(@ApiParam(value = "Параметры команды в JSON формате.", required = true)
- @RequestBody AnyKafkaMessageAction bankAccountNewAction) throws ClassNotFoundException, ValidationException, JsonProcessingException {
- log.info("Call test method for backend-api controller");
- validate(bankAccountNewAction);
- Class> parameterType = ClassUtils.forName(bankAccountNewAction.getFullClassName(), ClassUtils.getDefaultClassLoader());
- JavaType requestType = json.getTypeFactory().constructSimpleType(parameterType, null);
- Object obj = json.readValue(bankAccountNewAction.getJson(), requestType);
- Long idOfBaseRequestMessage = kafkaSender.sendRequestToQueue(bankAccountNewAction.getTopicName(), obj);
- log.debug("Test message to topic {} with request id={}", bankAccountNewAction.getTopicName(), idOfBaseRequestMessage);
- return "success: baseRequest.id = " + idOfBaseRequestMessage;
- }
-
- private void validate(AnyKafkaMessageAction bankAccountNewAction) throws ValidationException {
- if (TextUtil.isEmpty(bankAccountNewAction.getTopicName())) {
- throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "topicName"));
- }
- if (TextUtil.isEmpty(bankAccountNewAction.getFullClassName())) {
- throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "fullClassName"));
- }
- if (TextUtil.isEmpty(bankAccountNewAction.getJson())) {
- throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "json"));
- }
- }
-
-}
+//package ru.spcex.clearing.test.controller.kafka;
+//
+//import com.fasterxml.jackson.core.JsonProcessingException;
+//import com.fasterxml.jackson.databind.JavaType;
+//import com.fasterxml.jackson.databind.ObjectMapper;
+//import io.swagger.annotations.ApiOperation;
+//import io.swagger.annotations.ApiParam;
+//import io.swagger.annotations.ApiResponse;
+//import io.swagger.annotations.ApiResponses;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.http.MediaType;
+//import org.springframework.stereotype.Controller;
+//import org.springframework.util.ClassUtils;
+//import org.springframework.web.bind.annotation.RequestBody;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RequestMethod;
+//import org.springframework.web.bind.annotation.ResponseBody;
+//import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
+//import ru.spcex.platform.utils.enumeration.EnumMessage;
+//import ru.spcex.platform.utils.enumeration.IErrorEnumId;
+//import ru.spcex.platform.utils.error.ValidationException;
+//import ru.spcex.platform.utils.text.TextUtil;
+//
+//@Controller
+//@RequestMapping("/anonymous/kafka-api")
+//public class KafkaApiController {
+// private final Logger log = LoggerFactory.getLogger(getClass());
+// private final KafkaSender kafkaSender;
+// private static final ObjectMapper json = new ObjectMapper();
+// static {
+// }
+//
+// enum BackEndError implements IErrorEnumId {
+// ValidationError(9000L),
+// UnknownJsonProperty(9001L),
+// FailedToReadHttpMessage(9002L),
+// KeycloakRepeatedRoles(9003L),
+// DictionaryNotFound(9004L),
+// ResourceNotFound(9005L)
+// ;
+// private final Long id;
+//
+// BackEndError(Long id) {
+// this.id = id;
+// }
+//
+// @Override
+// public Long getId() {
+// return id;
+// }
+// }
+//
+// @Autowired
+// public KafkaApiController(KafkaSender kafkaSender) {
+// this.kafkaSender = kafkaSender;
+// }
+//
+// @ApiOperation(value = "Test backend-api availability.")
+// @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = String.class)})
+// @RequestMapping(method = RequestMethod.POST, path = "/any/message", produces = MediaType.TEXT_PLAIN_VALUE)
+// @ResponseBody
+// public String processGet(@ApiParam(value = "Параметры команды в JSON формате.", required = true)
+// @RequestBody AnyKafkaMessageAction bankAccountNewAction) throws ClassNotFoundException, ValidationException, JsonProcessingException {
+// log.info("Call test method for backend-api controller");
+// validate(bankAccountNewAction);
+// Class> parameterType = ClassUtils.forName(bankAccountNewAction.getFullClassName(), ClassUtils.getDefaultClassLoader());
+// JavaType requestType = json.getTypeFactory().constructSimpleType(parameterType, null);
+// Object obj = json.readValue(bankAccountNewAction.getJson(), requestType);
+// Long idOfBaseRequestMessage = kafkaSender.sendRequestToQueue(bankAccountNewAction.getTopicName(), obj);
+// log.debug("Test message to topic {} with request id={}", bankAccountNewAction.getTopicName(), idOfBaseRequestMessage);
+// return "success: baseRequest.id = " + idOfBaseRequestMessage;
+// }
+//
+// private void validate(AnyKafkaMessageAction bankAccountNewAction) throws ValidationException {
+// if (TextUtil.isEmpty(bankAccountNewAction.getTopicName())) {
+// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "topicName"));
+// }
+// if (TextUtil.isEmpty(bankAccountNewAction.getFullClassName())) {
+// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "fullClassName"));
+// }
+// if (TextUtil.isEmpty(bankAccountNewAction.getJson())) {
+// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "json"));
+// }
+// }
+//
+//}
diff --git a/clearing-parent/test-api-clearing/src/main/resources/application.properties b/clearing-parent/test-api-clearing/src/main/resources/application.properties
index 074aaeb9f..6eda6ea43 100644
--- a/clearing-parent/test-api-clearing/src/main/resources/application.properties
+++ b/clearing-parent/test-api-clearing/src/main/resources/application.properties
@@ -1,14 +1,13 @@
#spring.main.web-application-type=none
-test-service.port=8701
-test-service.url=/clearing/test/
-
#debug tester mode:
-test-service.debug-server.port=8701
-test-service.debug-server.context-path=/imdg/reload
+test-service.controller-settings.port=8701
+test-service.controller-settings.context-path=/
-server.port=8070
-server.servlet.context-path=/backend-api-test
+# /clearing/test/ /imdg/reload
+
+#server.port=8701
+#server.servlet.context-path=/
test-service.hazelcast.cluster-members=127.0.0.1:5701
diff --git a/clearing-parent/test-api-clearing/src/main/resources/logback.xml b/clearing-parent/test-api-clearing/src/main/resources/logback.xml
index e3e8a4454..c4c3640d0 100644
--- a/clearing-parent/test-api-clearing/src/main/resources/logback.xml
+++ b/clearing-parent/test-api-clearing/src/main/resources/logback.xml
@@ -8,7 +8,7 @@
- ./logs/utility-service.log
+ ./logs/test-api-clearing.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n
@@ -16,7 +16,7 @@
- ./logs/utility-service.%i.log
+ ./logs/test-api-clearing.%i.log
1
10
diff --git a/clearing-parent/test-api-clearing/src/main/resources/pages/index.html b/clearing-parent/test-api-clearing/src/main/resources/pages/index.html
new file mode 100644
index 000000000..3e506c67b
--- /dev/null
+++ b/clearing-parent/test-api-clearing/src/main/resources/pages/index.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
Debug control panel
+
Action:
+
+
+
Sending message dialog
+
+ Send
Message to queue
+
+
+
+
+
+
+
+
+
diff --git a/clearing-parent/test-api-clearing/src/main/resources/pages/message.html b/clearing-parent/test-api-clearing/src/main/resources/pages/message.html
new file mode 100644
index 000000000..656b9a85d
--- /dev/null
+++ b/clearing-parent/test-api-clearing/src/main/resources/pages/message.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
Sending message dialog
+
+
+
+
+ Enter Kafka debug message...
+
+ \message>
CD ..
+
+
+
+
diff --git a/clearing-parent/test-api-clearing/test-api-clearing.sh b/clearing-parent/test-api-clearing/test-api-clearing.sh
new file mode 100644
index 000000000..e5db2091a
--- /dev/null
+++ b/clearing-parent/test-api-clearing/test-api-clearing.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+CLEARING_HOME=/opt/mfd/clearing/
+cd $CLEARING_HOME/bin
+
+echo Warinig: start test module "test-api-clearing.jar". Do not use this on real system, please.
+CMD="java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:7702 -jar test-api-clearing.jar --spring.config.location=$CLEARING_HOME/settings/test-api-clearing/"
+
+$CMD >/dev/null 2>&1 &
+