changing index.html and adding Etrack

This commit is contained in:
Szakalakamaka
2020-09-04 16:07:27 +02:00
parent 42db7344f7
commit 2ccd960fd8
33 changed files with 468 additions and 329 deletions

View File

@@ -12,11 +12,11 @@ public class KlausApplication {
}
}
//TODO Jenkins
//TODO history logs
//TODO
//TODO history logs; for log indexing - create custom log appender for Redis - in case etrack would be too slow
//TODO JedisPool jedisPool = new JedisPool(jedisPoolConfig, redisHost, redisPort, timeout, redisPassword)
//TODO JedisPool optimalization https://partners-intl.aliyun.com/help/doc-detail/98726.htm
// loging and security
// tracking clients activity
// use a centralized logging collection tool like logstash
// logging, security, account creation
// tracking clients activity, admin panel
// use a centralized logging collection tool like logstash for admin panel
//TODO split into separate microservices

View File

@@ -10,6 +10,7 @@ import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import redis.clients.jedis.JedisPool;
import java.util.Objects;
@@ -21,6 +22,15 @@ public class RedisConfig {
@Autowired
private Environment environment;
@Bean
JedisPool jedisPool(){
//TODO JedisPool jedisPool = new JedisPool(jedisPoolConfig, redisHost, redisPort, timeout, redisPassword)
//TODO JedisPool optimalization https://partners-intl.aliyun.com/help/doc-detail/98726.htm
final JedisPool pool = new JedisPool(environment.getProperty("redis.host"),
Integer.parseInt(environment.getProperty("redis.port")));
return pool;
}
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration =

View File

@@ -1,5 +1,6 @@
package com.release11.klaus.controller;
import com.release11.klaus.model.EventRequestDto;
import com.release11.klaus.utilis.BusinessKey;
import com.release11.klaus.utilis.TrackingClient;
import com.release11.klaus.model.MockedResponseDto;
@@ -13,6 +14,9 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -25,8 +29,7 @@ public class KlausMvcController {
private final KlausService klausService;
@GetMapping("/login")
public String login(Model model) {
model.addAttribute("clientUUID", UUID.randomUUID());
public String login() {
return "login";
}
@@ -78,5 +81,17 @@ public class KlausMvcController {
}
@ModelAttribute("clientUUID")
public UUID clientUUID(){
return UUID.randomUUID();
}
@ModelAttribute("eventsDto")
public EventRequestDto eventsDto(){
return EventRequestDto.builder()
.localDateTimeFrom(LocalDateTime.of(LocalDate.now(), LocalTime.MIN))
.localDateTimeTo(LocalDateTime.of(LocalDate.now().plusDays(1), LocalTime.MIDNIGHT))
.build();
}
}

View File

@@ -3,9 +3,11 @@ package com.release11.klaus.repository;
import com.release11.klaus.model.MockedResponseDto;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
@Repository
@Transactional
public interface MockedResponseRepository extends CrudRepository<MockedResponseDto, String>{
}

View File

@@ -4,9 +4,11 @@ import com.release11.klaus.model.MockedResponseDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.UUID;
@Service
public interface KlausService {
ResponseEntity<String> getMockedResponse(UUID clientUUID, int mockedResponseId);
ResponseEntity<String> setMockedResponse(MockedResponseDto mockedResponseDto);

View File

@@ -36,6 +36,7 @@ public class KlausServiceImpl implements KlausService {
@Override
public ResponseEntity<String> setMockedResponse(MockedResponseDto mockedResponseDto) {
mockedResponseRepository.save(mockedResponseDto);
log.info("KlausServiceImpl, operation setMockedResponse, mockedResponseDto {} ", mockedResponseDto.toString());
return new ResponseEntity<>("MockedResponse has been setup successfully!", new HttpHeaders(),
HttpStatus.ACCEPTED);

View File

@@ -10,7 +10,7 @@ public final class TrackingClient {
public static void setBusinessKeys(Map<BusinessKey, String> businessKeysMap){
for (Map.Entry<BusinessKey, String> entry : businessKeysMap.entrySet()) {
MDC.put(entry.getKey().getReasonPhrase(), entry.getValue());
MDC.put(entry.getKey().toString(), entry.getValue());
}
}

View File

@@ -2,14 +2,14 @@
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!--https://github.com/kmtong/logback-redis-appender-->
<appender name="LOGSTASH" class="com.cwbase.logback.RedisAppender">
<appender name="LOGSTASH" class="com.release11.klaus.utilis.RedisAppender">
<host>localhost</host>
<port>6379</port>
<key>logstash</key>
<layout class="ch.qos.logback.classic.PatternLayout">
<!--https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html-->
<Pattern>
{"date" : "%d{yyyy-MM-dd}", "timestamp":"%d{HH:mm:ss}", "businessKeys": ["interfaceName": "%X{interfaceName}", "clientUUID": "%X{clientUUID}", "messageId": "%X{messageId}"],"thread":"%t","level":"%-5level", "message":"%msg"}%n
{"dateTimeStamp" : "%d{yyyy-MM-dd}T%d{HH:mm:ss}", "businessKeys":["INTERFACE_NAME:%X{INTERFACE_NAME}", "CLIENT_UUID:%X{CLIENT_UUID}", "MESSAGE_ID:%X{MESSAGE_ID}"],"thread":"%t","level":"%-5level", "message":"%msg"}%n
</Pattern>
</layout>
</appender>

View File

@@ -1,4 +1,3 @@
function httpGet()
{
var clientUUID = document.getElementById("getClientUUID").value;

View File

@@ -3,76 +3,115 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/js/main.js"></script>
<script src="/js/main.js">
document.getElementById('localDateTimeFrom').valueAsDate = new Date();
</script>
<link href="css/styles.css" rel="stylesheet" />
</head>
<body>
<hr>
<div><br>In order to set mockup response. Please send the response, that you want to receive, on:
<br>http://localhost:8097/klaus/v1/set/ <a th:text="${mockedResponseDto.clientUUID}">clientUUID should be here</a>/{mockedResponseId}?httpStatus=200
<br>or simply fill and submit the below form:</div>
<div class="col-lg-4 form-max">
sayHi('John');
<form action="#" th:action="@{/home}" th:object="${mockedResponseDto}" method="post">
<table>
<input type="text" th:field="*{clientUUID}" th:placeholder="*{clientUUID}" hidden/>
<tr>
<td>Mocked response id:</td>
<td><input type="text" th:field="*{mockedResponseId}" th:value=1/></td>
<td th:if="${#fields.hasErrors('mockedResponseId')}" th:errors="*{mockedResponseId}">Id Error</td>
</tr>
<tr>
<td>Mocked response body:</td>
<td><textarea rows="4" cols="50" th:field="*{messageBody}" th:placeholder='messageBody'></textarea></td>
<td th:if="${#fields.hasErrors('messageBody')}" th:errors="*{messageBody}">Body Error</td>
</tr>
<tr>
<td>Mocked response http code status:</td>
<td><input type="text" th:field="*{httpStatus}" th:value='200'></td>
<td th:if="${#fields.hasErrors('httpStatus')}" th:errors="*{httpStatus}">HttpStatus Error</td>
</tr>
<tr>
<td>Provide mocked response headers:</td>
<td><a href="#" id="addHeader" onclick="addFields()">Add a new header</a>
<div><br>In order to set mockup response. Please send the response, that you want to receive, on:
<br>http://localhost:8097/klaus/v1/set/ <a th:text="${mockedResponseDto.clientUUID}">clientUUID should be here</a>/{mockedResponseId}?httpStatus=200
</div>
<section class="page-section" id="main-section">
<div class="container">
<div class="row">
<div class="column">
<br>You can also simply fill and submit the below form:
<form action="#" th:action="@{/home}" th:object="${mockedResponseDto}" method="post">
<table>
<input type="text" th:field="*{clientUUID}" th:placeholder="*{clientUUID}" hidden/>
<tr>
<td><div id="headers"></div></td>
<td>Mocked response id:</td>
<td><input type="text" th:field="*{mockedResponseId}"/></td>
<td th:if="${#fields.hasErrors('mockedResponseId')}" th:errors="*{mockedResponseId}">Id Error</td>
</tr>
<tr>
<td>Mocked response body:</td>
<td><textarea rows="4" cols="50" th:field="*{messageBody}"></textarea></td>
<td th:if="${#fields.hasErrors('messageBody')}" th:errors="*{messageBody}">Body Error</td>
</tr>
<tr>
<td>Mocked response http code status:</td>
<td><input type="text" th:field="*{httpStatus}"></td>
<td th:if="${#fields.hasErrors('httpStatus')}" th:errors="*{httpStatus}">HttpStatus Error</td>
</tr>
<tr>
<td>Provide mocked response headers:</td>
<td><a href="#" id="addHeader" onclick="addFields()">Add a new header</a>
<table>
<tr>
<td><div id="headers"></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Media type:</td>
<td><select th:field="*{mediaType}">
<option value="application/xml">application/xml</option>
<option value="application/json">application/json</option>
<option value="text/xml">text/xml</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Save mocked response"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Media type:</td>
<td><select th:field="*{mediaType}">
<option value="application/xml">application/xml</option>
<option value="application/json">application/json</option>
<option value="text/xml">text/xml</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Save mocked response"/></td>
</tr>
</table>
</form>
<p th:if="${mockSaved}">Mock has been saved</p>
</form>
<table>
<tr>
<td>
<p th:if="${mockSaved}">Mock has been saved</p>
</td>
<td>
<form action="#" th:action="@{/home/getMockedResponse}" th:object="${mockedResponseDto}" method="get">
<input type="text" th:field="*{clientUUID}" hidden/>
<input type="text" th:field="*{mockedResponseId}" hidden/>
<p th:if="${mockSaved}"><input type="submit" value="Test your mock"/></p>
</form>
</td>
</tr>
</table>
</div>
<div class="column">
Your mocked requests:
<br>
larum ispum srutum tutum
</div>
</div>
</div>
</section>
<hr>
<div><br>In order to use the mocked response in your integration tests or simply
<div>
<br>In order to use the mocked response in your integration tests or simply
get your mocked response please send a request to
<br>http://localhost:8097/klaus/v1/get/<a th:text="${mockedResponseDto.clientUUID}">clientUUID should be here</a>/{mockedResponseId}
<br>You will receive the same body and headers as you sent them in the step 1.
</div>
<div><br>You will receive the same body and headers as you sent them in the step 1.</div>
<div><br>You can also use the form below:</div>
<form action="#" th:action="@{/home/getMockedResponse}" th:object="${mockedResponseDto}" method="get">
<input type="text" th:field="*{clientUUID}" th:placeholder="*{clientUUID}" hidden/>
<br><label >Mocked response id:</label><br/>
<input type="text" th:field="*{mockedResponseId}" th:placeholder="12345"/>
<input type="submit" value="Get mocked response"/>
</form>
<hr>
<div>
<br>To see your activity history use the form below
<form action="#" th:action="@{/eventsForm}" th:object="${eventsDto}" method="post">
<input type="text" th:name="clientUUID" th:value="${mockedResponseDto.clientUUID}" hidden/>
<br><label>Date from:</label><br>
<input type="datetime-local" th:field="*{localDateTimeFrom}"/>
<td th:if="${#fields.hasErrors('localDateTimeFrom')}" th:errors="*{localDateTimeFrom}">localDateTimeFrom Error</td>
<br><label>Date to:</label><br>
<input type="datetime-local" th:field="*{localDateTimeTo}"/>
<td th:if="${#fields.hasErrors('localDateTimeTo')}" th:errors="*{localDateTimeTo}">localDateTimeTo Error</td>
<div th:if="${#fields.hasAnyErrors()}">
<p th:each="err : ${#fields.allErrors()}" th:text="${err}">...</p>
</div>
<input type="submit" value="See my history"/>
</form>
</div>
<hr>
</div>
</div>

View File

@@ -4,6 +4,7 @@
<meta charset="UTF-8">
<title>Login</title>
<script src="/js/main.js"></script>
<link href="css/styles.css" rel="stylesheet" />
</head>
<body>
<div><br>Please move to the next step with your own client UUID: </div>
@@ -12,7 +13,6 @@
<input type="text" name="clientUUID" value="436c4774-038f-4540-9c18-2691ca9b53d4" />
<input type="submit" value="Proceed"/>
</form>
<div><br>You can also register new UUID. *some logic to register UUID*:
<br><a th:text="${clientUUID}">clientUUID should be here</a>
</div>