Skip to content

Commit

Permalink
✨ feat: upgrade base libs and codebase #4 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 7, 2024
1 parent 86c97e7 commit 76c4579
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 46 deletions.
2 changes: 1 addition & 1 deletion gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ng:
name: suit4j
version: v1.0.0
jars:
- source: "libs/unify4j-v1.0.0.jar" # lib Jar
- source: "libs/unify4j-v1.0.0.jar"
- source: "libs/force4j-v1.0.0.jar"
- source: "libs/botwrap4j-v1.0.0.jar"
Binary file modified libs/botwrap4j-v1.0.0.jar
Binary file not shown.
Binary file modified libs/unify4j-v1.0.0.jar
Binary file not shown.
55 changes: 55 additions & 0 deletions src/main/java/com/suit4j/app/configs/HttpConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.suit4j.app.configs;

import org.bot4j.telegram.message.MessageFactory;
import org.botwrap4j.common.BotWrap4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.unify4j.common.Json4j;
import org.unify4j.common.Request4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings({"NullableProblems"})
@Component
public class HttpConfig implements HandlerInterceptor {
protected static final Logger logger = LoggerFactory.getLogger(HttpConfig.class);

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.info("Incoming request, {} URI: {}, params: {}", request.getMethod(), request.getRequestURI(), Json4j.toJson(request.getParameterMap()));
return true;
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception {
logger.info("Outgoing response, status: {} ({}), {} URI: {} and params: {}",
response.getStatus(), HttpStatus.valueOf(response.getStatus()).getReasonPhrase(),
request.getMethod(), request.getRequestURI(), Json4j.toJson(request.getParameterMap()));
if (e != null) {
logger.error("afterCompletion, outgoing response raised an exception: {}", e.getMessage(), e);
}
BotWrap4j.telegramProvider().sendMessageSilent("worker_logging",
MessageFactory.http()
.status(response.getStatus())
.method(request.getMethod())
.baseUrl(Request4j.getBaseUrl(request))
.path(request.getRequestURI())
.query(request.getParameterMap())
.apiDesc(HttpConfig.class.getName())
.cause(e)
.requestId(Request4j.getSessionId(request))
.header(Request4j.getHeaders(request))
.startTime()
.endTime()
);
}
}
39 changes: 0 additions & 39 deletions src/main/java/com/suit4j/app/configs/HttpInterceptorConfig.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/suit4j/app/configs/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Autowired
protected HttpInterceptorConfig httpInterceptor;
protected HttpConfig httpInterceptor;

@Override
public void addInterceptors(InterceptorRegistry registry) {
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/suit4j/app/controllers/CommonController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import org.force4j.common.Force4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.unify4j.model.builder.HttpStatusBuilder;
import org.unify4j.model.builder.HttpWrapBuilder;
import org.unify4j.model.response.WrapResponse;
Expand All @@ -17,7 +14,16 @@ public class CommonController extends BaseController {

@GetMapping("/health")
public @ResponseBody ResponseEntity<?> inform() {
logger.info("Checking health...");
WrapResponse<?> response = new HttpWrapBuilder<>()
.statusCode(HttpStatusBuilder.OK)
.message("HealthCheck")
.requestId(Force4j.getCurrentSessionId())
.build();
return new ResponseEntity<>(response, HttpStatus.valueOf(response.getStatusCode()));
}

@PostMapping("/health")
public @ResponseBody ResponseEntity<?> inform(@RequestBody Object request) {
WrapResponse<?> response = new HttpWrapBuilder<>()
.statusCode(HttpStatusBuilder.OK)
.message("HealthCheck")
Expand Down

0 comments on commit 76c4579

Please sign in to comment.