Produced by Araxis Merge on 10/2/2017 7:00:17 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | cds.zip\cds\product\production\cdsutils\src\main\java\com\cognitive\cds\utils\log\filter | CDSDashboardRequestIdFilter.java | Fri Apr 28 17:27:00 2017 UTC |
| 2 | cds.zip\cds\product\production\cdsutils\src\main\java\com\cognitive\cds\utils\log\filter | CDSDashboardRequestIdFilter.java | Wed Sep 27 16:03:25 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 262 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package co m.cognitiv e.cds.util s.log.filt er; | |
| 5 | ||
| 6 | import jav a.io.IOExc eption; | |
| 7 | import jav a.net.Inet Address; | |
| 8 | import jav a.net.Unkn ownHostExc eption; | |
| 9 | import jav a.time.Ins tant; | |
| 10 | import jav a.time.for mat.DateTi meFormatte r; | |
| 11 | import jav a.util.Has hSet; | |
| 12 | import jav a.util.Set ; | |
| 13 | import jav a.util.UUI D; | |
| 14 | import jav a.util.reg ex.Matcher ; | |
| 15 | import jav a.util.reg ex.Pattern ; | |
| 16 | ||
| 17 | import jav ax.servlet .Filter; | |
| 18 | import jav ax.servlet .FilterCha in; | |
| 19 | import jav ax.servlet .FilterCon fig; | |
| 20 | import jav ax.servlet .ServletEx ception; | |
| 21 | import jav ax.servlet .ServletRe quest; | |
| 22 | import jav ax.servlet .ServletRe sponse; | |
| 23 | import jav ax.servlet .http.Http ServletReq uest; | |
| 24 | import jav ax.servlet .http.Http ServletRes ponse; | |
| 25 | import jav ax.servlet .http.Http ServletRes ponseWrapp er; | |
| 26 | ||
| 27 | import org .apache.co mmons.lang 3.StringUt ils; | |
| 28 | import org .slf4j.Log ger; | |
| 29 | import org .slf4j.Log gerFactory ; | |
| 30 | import org .slf4j.MDC ; | |
| 31 | ||
| 32 | /** | |
| 33 | * Set MDC X-Reques t-ID and S essionID | |
| 34 | * Nov 22, 2016 | |
| 35 | * | |
| 36 | */ | |
| 37 | public cla ss CDSDash boardReque stIdFilter implement s Filter { | |
| 38 | ||
| 39 | pr ivate stat ic final L ogger LOG = LoggerFa ctory.getL ogger(CDSD ashboardRe questIdFil ter.class) ; | |
| 40 | // "2016-10-1 9T17:38:29 .089Z" | |
| 41 | pu blic stati c final Da teTimeForm atter DATE FORMATTER = DateTime Formatter. ISO_INSTAN T; | |
| 42 | pr ivate stat ic String hostname; | |
| 43 | ||
| 44 | @O verride | |
| 45 | pu blic void init(Filte rConfig fi lterConfig ) throws S ervletExce ption { | |
| 46 | if(h ostname==n ull) { | |
| 47 | try { | |
| 48 | InetAddr ess localH ost = Inet Address.ge tLocalHost (); | |
| 49 | hostname = localHo st.getHost Name(); | |
| 50 | } catc h (Unknown HostExcept ion e) { | |
| 51 | LOG.erro r("LocalHo st could n ot be reso lved to an address." ,e ); | |
| 52 | } | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | @O verride | |
| 57 | pu blic void doFilter(S ervletRequ est reques t, Servlet Response r esponse, F ilterChain chain) | |
| 58 | throws IOExcepti on, Servle tException | |
| 59 | { | |
| 60 | Http ServletRes ponseWrapp er wrapper = new Htt pServletRe sponseWrap per((HttpS ervletResp onse)respo nse); | |
| 61 | try{ | |
| 62 | HttpSe rvletReque st httpReq uest = (Ht tpServletR equest) re quest; | |
| 63 | String requestId = httpReq uest.getHe ader("X-Re quest-ID") ; | |
| 64 | String msg = "IN COMING REQ UEST:"; | |
| 65 | if(Str ingUtils.i sEmpty(req uestId)) { | |
| 66 | requestI d = genera teRequestI d(); | |
| 67 | wrapper. addHeader( "X-Request -ID", requ estId); | |
| 68 | msg = "S ERVICE REQ UEST:"; | |
| 69 | } | |
| 70 | ||
| 71 | Set< String> ke ys = new H ashSet<Str ing>(); | |
| 72 | put(ke ys, "dateT ime", DATE FORMATTER. format(Ins tant.now() ), true); | |
| 73 | put(keys, "address", httpReque st.getRequ estURL().t oString(), true); | |
| 74 | put(keys, "httpMetho d", httpRe quest.getM ethod(), t rue); | |
| 75 | put(keys, "path", ge tPathAndQu eryInfo(ht tpRequest. getRequest URL().toSt ring()), t rue); | |
| 76 | put(keys, "requestId ", StringU tils.defau ltIfEmpty( requestId, ""), fals e); | |
| 77 | put(keys, "sid", Str ingUtils.d efaultIfEm pty(httpRe quest.getS ession().g etId(), "" ), false); | |
| 78 | put(keys, "hostname" , StringUt ils.defaul tIfEmpty(h ostname, " cdsdashboa rd"), fals e); | |
| 79 | put(keys, "context", StringUti ls.default IfEmpty(ht tpRequest. getContext Path(), " ").substri ng(1), fal se); | |
| 80 | ||
| 81 | LOG.in fo(msg); | |
| 82 | for (Str ing key : keys) { | |
| 83 | MDC. remove(key ); | |
| 84 | } | |
| 85 | ||
| 86 | } | |
| 87 | catc h(Exceptio n e) { | |
| 88 | LOG.er ror(e.getM essage(), e); | |
| 89 | } | |
| 90 | fina lly { | |
| 91 | chain. doFilter(r equest, wr apper); | |
| 92 | } | |
| 93 | } | |
| 94 | ||
| 95 | @O verride | |
| 96 | pu blic void destroy() { | |
| 97 | } | |
| 98 | ||
| 99 | ||
| 100 | pr ivate stat ic Pattern pathMatch = Pattern .compile(" http://.*? /.*?(/.*)" ); | |
| 101 | /* * | |
| 102 | * Takes a String wit h a format of http:/ / IP /cds-resul ts-service /cds/invok eRules?que ry=default ¶m=0 | |
| 103 | * and retur ns the pat h and quer y - /cds/i nvokeRules ?query=def ault¶m =0 | |
| 104 | * @param ad dress | |
| 105 | * @return | |
| 106 | * / | |
| 107 | pr ivate Stri ng getPath AndQueryIn fo(String url) { | |
| 108 | try { | |
| 109 | Matche r match = pathMatch. matcher(ur l); | |
| 110 | if(mat ch.find()) { | |
| 111 | return S tringUtils .defaultIf Empty(matc h.group(1) ,""); | |
| 112 | } | |
| 113 | } | |
| 114 | catc h(Exceptio n e) { | |
| 115 | LOG.er ror(e.getM essage(), e); | |
| 116 | } | |
| 117 | retu rn ""; | |
| 118 | } | |
| 119 | ||
| 120 | privat e void put (Set<Strin g> keys, S tring key, String va lue, boole an addToKe ys) { | |
| 121 | if (value != null) { | |
| 122 | MDC.put( key, value ); | |
| 123 | if( addT oKeys) { | |
| 124 | keys .add(key); | |
| 125 | } | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | privat e String g enerateReq uestId() { | |
| 130 | re turn UUID. randomUUID ().toStrin g(); | |
| 131 | } | |
| 132 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.