java - Where should I store a variable that I want to access thru out my tomcat REST ws? -


i have rest webservice running in tomcat version 7 using jersey 1.18. each request comes in has custom header called 'request-id'. store request id in place classes have access request id , can use logging.

the main thing is, has on per request basis. request-id request different of request b.

where can store such variable? sort of context valid on per request basis - can point me in right direction?

--su

you can store in threadlocal. have careful it. need store on receiving request , clear when returning response. want write static utility methods store , retrieve request id that:

public class requestidutil {      private static final threadlocal<string> requestidholder = new threadlocal<string>();      private requestidutil() {         // prevent initialization     }      public static void setrequestid(string requestid) {         requestidholder.set(requestid);     }      /**      *       * @return requestid      *               */     public static string getrequestid() {         return requestidholder.get();     }      public static void remove() {         requestidholder.remove();     }    } 

in example remove needs called in end of processing of every request if exception thrown.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -