Interceptor for Transaction Table
parent
94c88cbf64
commit
022024219e
|
|
@ -1,27 +1,33 @@
|
|||
package com.nttdata.calender;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import com.nttdata.calender.api.RequestInterceptor;
|
||||
import com.nttdata.calender.api.rsso.RssoInterceptor;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
private final RssoInterceptor sessionInterceptor;
|
||||
private final RequestInterceptor requestInterceptor;
|
||||
|
||||
public WebMvcConfig(RssoInterceptor sessionInterceptor) {
|
||||
@Autowired
|
||||
public WebMvcConfig(RssoInterceptor sessionInterceptor, RequestInterceptor requestInterceptor) {
|
||||
this.sessionInterceptor = sessionInterceptor;
|
||||
this.requestInterceptor = requestInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the session interceptor to the interceptor registry.
|
||||
* Adds the session interceptor and request interceptor to the interceptor registry.
|
||||
*
|
||||
* @param registry the interceptor registry.
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(sessionInterceptor);
|
||||
registry.addInterceptor(sessionInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requestInterceptor).addPathPatterns("/**");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -254,6 +254,7 @@ public class KalenderRestController {
|
|||
@ResponseBody
|
||||
public ChangeResponse getChanges(@RequestBody ChangeRequest request)
|
||||
throws ARException, NotFoundError, ValidationError {
|
||||
|
||||
return change.get(request);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
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.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
public class RequestInterceptor implements HandlerInterceptor {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("application");
|
||||
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 {
|
||||
// Print current datetime before handling the request
|
||||
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
||||
String out = currentDateTime + " - handling request: " + request.getRequestURI();
|
||||
logger.info(out);
|
||||
System.out.println(out);
|
||||
return true; // Continue with the request
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
if (ex == null)
|
||||
System.out.println("Success in handling request: " + request.getRequestURI());
|
||||
else
|
||||
System.out.println("Error in handling request: " + request.getRequestURI());
|
||||
}
|
||||
}
|
||||
|
|
@ -87,7 +87,6 @@ public class Change {
|
|||
* @throws ValidationError if there is an invalid filter or qualification
|
||||
*/
|
||||
public ChangeResponse get(ChangeRequest request) throws ARException, NotFoundError, ValidationError {
|
||||
|
||||
LoggerTemplates log = new LoggerTemplates(api);
|
||||
|
||||
var peopleFullName = processPeopleInfo(request);
|
||||
|
|
@ -165,9 +164,7 @@ public class Change {
|
|||
.map(Value::getIntValue)
|
||||
.orElse(-1));
|
||||
}
|
||||
|
||||
|
||||
System.out.println("\nStatus: "+change.getState());
|
||||
|
||||
change.setPackageInstanceId(getValueStringByID(entry, "PackageInstanceId"));
|
||||
|
||||
change.setResourceName(getValueStringByID(entry, "ResourceName"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue