1
1
package com .phuocnguyen .app .ngxblobso2jwt .utils ;
2
2
3
3
import com .fasterxml .jackson .databind .ObjectMapper ;
4
+ import com .sivaos .Configurer .CustomFilterRequest .TypeSafeRequest ;
5
+ import com .sivaos .Model .ObjectEnumeration .Original .ComparatorType ;
4
6
import com .sivaos .Model .Response .Extend .HttpStatusCodesResponseDTO ;
5
7
import com .sivaos .Model .Response .Extend .StatusCodeResponseDTO ;
8
+ import com .sivaos .Utility .CollectionsUtility ;
6
9
import com .sivaos .Utils .DateUtils ;
10
+ import com .sivaos .Utils .ObjectUtils ;
11
+ import com .sivaos .Utils .UrlQueryUtils ;
7
12
import org .slf4j .Logger ;
8
13
import org .slf4j .LoggerFactory ;
9
14
import org .springframework .http .MediaType ;
@@ -37,15 +42,24 @@ public static void onHandlerErrors(HttpServletRequest request, HttpServletRespon
37
42
38
43
Map <String , Object > map = new HashMap <>();
39
44
40
- map .put ("code" , statuses .getCode ());
41
- map .put ("header" , statuses );
42
- map .put ("message" , exception .getMessage ());
43
- map .put ("path" , request .getServletPath ());
44
- map .put ("timestamp" , new Date ().getTime ());
45
- map .put ("publish" , DateUtils .feedStageAsString (new Date ()));
46
- map .put ("class" , clazz );
47
- map .put ("method" , request .getMethod ());
48
- map .put ("sessionId" , request .getSession ().getId ());
45
+ Map <String , String > queries = TypeSafeRequest .snapTypeSafeRequest (request );
46
+ String urlShortCompleted = UrlQueryUtils .snapQuery (request .getServletPath (), CollectionsUtility .sortByKey (queries , ComparatorType .ASCENDING ));
47
+
48
+ map .put (HandlerAttributes .CODE_ATTRIBUTE , statuses .getCode ());
49
+ map .put (HandlerAttributes .HEADER_ATTRIBUTE , statuses );
50
+ map .put (HandlerAttributes .MESSAGE_ATTRIBUTE , exception .getMessage ());
51
+ map .put (HandlerAttributes .PATH_ATTRIBUTE , urlShortCompleted );
52
+ map .put (HandlerAttributes .TIMESTAMP_ATTRIBUTE , new Date ().getTime () / 1000 );
53
+ map .put (HandlerAttributes .PUBLISH_ATTRIBUTE , DateUtils .feedStageAsString (new Date ()));
54
+ map .put (HandlerAttributes .CLASS_ATTRIBUTE , clazz );
55
+ map .put (HandlerAttributes .METHOD_ATTRIBUTE , request .getMethod ());
56
+ map .put (HandlerAttributes .DEBUG_MESSAGE_ATTRIBUTE , exception .getLocalizedMessage ());
57
+
58
+ if (ObjectUtils .allNotNull (request .getSession ())) {
59
+ map .put (HandlerAttributes .SESSION_ID_ATTRIBUTE , request .getSession ().getId ());
60
+ } else {
61
+ map .put (HandlerAttributes .SESSION_ID_ATTRIBUTE , request .getRequestedSessionId ());
62
+ }
49
63
50
64
try {
51
65
ObjectMapper mapper = new ObjectMapper ();
@@ -55,4 +69,17 @@ public static void onHandlerErrors(HttpServletRequest request, HttpServletRespon
55
69
throw new ServletException (e .getMessage (), e );
56
70
}
57
71
}
72
+
73
+ private static class HandlerAttributes {
74
+ public static final String CODE_ATTRIBUTE = "code" ;
75
+ public static final String HEADER_ATTRIBUTE = "header" ;
76
+ public static final String MESSAGE_ATTRIBUTE = "message" ;
77
+ public static final String PATH_ATTRIBUTE = "path" ;
78
+ public static final String TIMESTAMP_ATTRIBUTE = "timestamp" ;
79
+ public static final String PUBLISH_ATTRIBUTE = "publish" ;
80
+ public static final String CLASS_ATTRIBUTE = "class" ;
81
+ public static final String METHOD_ATTRIBUTE = "method" ;
82
+ public static final String DEBUG_MESSAGE_ATTRIBUTE = "debugMsg" ;
83
+ public static final String SESSION_ID_ATTRIBUTE = "sessionId" ;
84
+ }
58
85
}
0 commit comments