Announcement Announcement Module
No announcement yet.
Save intercepted request for later use Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save intercepted request for later use

    I want to log the useage of a web service, so I have a UsageLogger class which takes some data from the request and some data from the response and saves it to a database.

    To get the data I've made a LoggingInterceptor class which implements EndpointInterceptor. Since I need both the request and the response to use the UsageLogger, the response has to be avaliable in the handleResponse and handleFault methods. Is there a handy way to do that? Simply saving the request to an instance variable in the interceptor will lead to concurrency problems, right?

  • #2
    Since you are updating database, do so during the handleRequest
    and update gain during handleResponse. To keep track of the right handleRequest, handleResponse pair, use ThreadLocal variable to keep request Id. So you can use the Id to store in the database during handleRequest and update during handleResponse or handleFault phase.

    Or have a ConcurrentHashMap that would store Threadlocal Id as Key and Request Response as value, and take your own time to persist them to DB whenever you feel it is convenient.


    • #3
      Will try that. Thanks!


      • #4
        You can also store whatever you like in the MessageContext.