output method + changeNR
parent
2408fdba63
commit
8813ed9f7d
|
|
@ -3,6 +3,8 @@ package com.nttdata.calender.api;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.common.util.report.qual.ReportCall;
|
||||
|
|
@ -278,8 +280,9 @@ public class KalenderRestController {
|
|||
@CrossOrigin("*")
|
||||
@PostMapping("/api/updateChange")
|
||||
@ResponseBody
|
||||
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request)
|
||||
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request, HttpServletRequest httpRequest)
|
||||
throws ARException, ValidationError {
|
||||
httpRequest.setAttribute("changeUpdateRequest", request);
|
||||
change.modifyTimestamp(request);
|
||||
return request;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package com.nttdata.calender.api;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import com.nttdata.calender.changes.ChangeUpdateRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
|
@ -18,32 +21,59 @@ public class RequestInterceptor implements HandlerInterceptor {
|
|||
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
// Print current datetime before handling the request
|
||||
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
||||
long transactionId = System.currentTimeMillis();
|
||||
String out = "Transaction ID = " + transactionId + " " + currentDateTime + " - handling request: " + request.getRequestURI();
|
||||
String out = "Transaction ID = " + transactionId + " " + currentDateTime + " - handling request: "
|
||||
+ request.getRequestURI();
|
||||
logger.info(out);
|
||||
return true; // Continue with the request
|
||||
}
|
||||
|
||||
private static String output(String time, long id, String user, String status, String action, String ticket,
|
||||
String result) {
|
||||
return String.format("Time: %s\nTransaction ID: %d\nUser: %s\nStatus: %s\nAction: %s\nTicket: %s\nResult: %s",
|
||||
time, id, user, status, action, ticket, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
|
||||
// Only react for POST requests
|
||||
if ("POST".equalsIgnoreCase(request.getMethod())) {
|
||||
// Print current datetime after handling the request
|
||||
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
||||
long transactionId = System.currentTimeMillis();
|
||||
String changeNr = "";
|
||||
|
||||
if (ex == null) {
|
||||
String out = "Transaction ID = " + transactionId + " " + currentDateTime + " [SUCCESS] handling request: " + request.getRequestURI() + "\n";
|
||||
logger.info(out);
|
||||
System.out.println(out);
|
||||
} else {
|
||||
String out = "Transaction ID = " + transactionId + " " + currentDateTime + " [ERROR] handling request: " + request.getRequestURI() + "\n" + ex.getMessage() + "\n";
|
||||
logger.error(out);
|
||||
System.err.println(out);
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
if (handlerMethod.getMethod().getName().equals("updateChange")) {
|
||||
ChangeUpdateRequest changeUpdateRequest = (ChangeUpdateRequest) request
|
||||
.getAttribute("changeUpdateRequest");
|
||||
if (changeUpdateRequest != null) {
|
||||
changeNr = changeUpdateRequest.getChangeNr();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\n" + output(currentDateTime, transactionId, "User", "Success", request.getRequestURI(),
|
||||
changeNr, "Successful"));
|
||||
}
|
||||
|
||||
// if (ex == null) {
|
||||
// String out = currentDateTime + "Transaction ID = " + transactionId
|
||||
// + "\nDone / Success\nHandling Request: " + request.getRequestURI() + "\n";
|
||||
// logger.info(out);
|
||||
// System.out.println(out);
|
||||
// } else {
|
||||
// String out = "Transaction ID = " + transactionId + " " + currentDateTime + " [ERROR] handling request: "
|
||||
// + request.getRequestURI() + "\n" + ex.getMessage() + "\n";
|
||||
// logger.error(out);
|
||||
// System.err.println(out);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue