I do not believe listeners can be tied to specific mappings.  You could
always filter in your listener if you wanted to.

 

________________________________

From: Ross Sargant [mailto:rsarg...@tvrc.com] 
Sent: Monday, June 01, 2009 10:35 AM
To: Stripes Users List
Subject: Re: [Stripes-users] Intercepting an entire request

 

Alex,
  Thanks. That looks like another good approach that also exists
completely outside of stripes.

Out of curiosity, in a web-app with multiple servlets do listeners get
called regardless of which servlet is triggered? Can listeners be bound
to specific servlets? 







On Mon, Jun 1, 2009 at 9:35 AM, Brown, Alex <abr...@barclaycardus.com>
wrote:

Try a web.xml entry like this:

 

    <listener>

        <listener-class>

            com.test.app.util.listener.MDCRequestListener

        </listener-class>

    </listener>

 

 

Then something like this:

 

public class MDCRequestListener implements ServletRequestListener {

    /**

     * Add session ID to MDC context

     * @param arg0

     */

    public void requestInitialized(ServletRequestEvent
servletRequestEvent) {

        String sid =
((HttpServletRequest)servletRequestEvent.getServletRequest()).getSession
().getId();

        MDC.put(LoggingConstants.CONTEXT_ID.toString(), sid);

    }

    

    /**

     * Remove session ID from MDC context

     * @param arg0

     */

    public void requestDestroyed(ServletRequestEvent arg0) {

        MDC.remove(LoggingConstants.CONTEXT_ID.toString());

    }

}

 

________________________________

From: Ross Sargant [mailto:rsarg...@tvrc.com] 
Sent: Monday, June 01, 2009 8:43 AM
To: Stripes Users List
Subject: [Stripes-users] Intercepting an entire request

 

Hi,
  I wanted to point a struggle I had recently working with stripes
interceptors to see if anybody had any suggestions.

 I was trying to generate unique transaction code for every web request
into my application and then assign it to the MDC (mapped diaganostic
context) such that the transaction code, and username (if available)
appears in every log messag associated with (all) processing for that
request.  The transaction code is something I report to users if there
is a problem and then I can use it when I go through logs later to learn
more about what happened.

 I couldn't figure out an easy with do this with stripes interceptors
that also guaranteed that the MDC is still populated during execution of
my top level exception handler (which is one of the places I report the
transaction code). I prefer not logging the same exception multiple
times, I so rely on my top level exception handler to be the single
point where I log most unrecoverable exceptions and I want the MDC
information available in that log entry.

I tried generating the transaction code and loading the MDC by
intercepting RequestInit and then clear the MDC by intercepting
RequestComplete but that clears the MDC to soon in the case of an
Exception.

I solved this problem in a very simple way by doing my own filter that
runs ahead of stripes. I'm perfectly happy with this solution and maybe
this really isn't a stripes problem at all. Still, I thought I would
ask. Interceptors are a such a powerful feature, I was suprised I just
couldn't get it to do what I wanted.






-- 
Ross Sargant
Software Engineer
p: 954-571-2017 x2108
email: rsarg...@tvrc.com

TVR Communications LLC
3275 W Hillsboro Blvd,Suite 300,Deerfield Beach, Florida,33442

http://www.tvrc.com




_______________________________________________________

Barclays
www.barclaycardus.com
_______________________________________________________

This e-mail and any files transmitted with it may contain confidential
and/or proprietary information. It is intended solely for the use of the
individual or entity who is the intended recipient. Unauthorized use of
this information is prohibited. If you have received this in error,
please contact the sender by replying to this message and delete this
material from any system it may be on. 


------------------------------------------------------------------------
------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals.
Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like
Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users




-- 
Ross Sargant
Software Engineer
p: 954-571-2017 x2108
email: rsarg...@tvrc.com

TVR Communications LLC
3275 W Hillsboro Blvd,Suite 300,Deerfield Beach, Florida,33442

http://www.tvrc.com



Barclays             www.barclaycardus.com

This e-mail and any files transmitted with it may contain confidential and/or 
proprietary information. It is intended solely for the use of the individual or 
entity who is the intended recipient. Unauthorized use of this information is 
prohibited. If you have received this in error, please contact the sender by 
replying to this message and delete this material from any system it may be on.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to