is it possible to get the http request information from a thread (not the current thread)?
I want to be able to enumerate all the live threads and get the request uri for each of them.
any ideas?
thanks
Try this:
- Create a servlet Filter.
- Make it implement DynamicMBean. Register the bean in the Filter's init method (and unregister it in the destroy method)
- Define a synchronized WeakHashMap field.
- In the filter's doFilter method, capture the URI of the request before the FilterChain's doFilter method is called. Insert the thread and the request URI into the WeakHashMap.
- Call the chain.
- In a finally block, insert the current thread and some arbitrary constant like NO REQUEST into the WeakHashMap.
- Implement the DynamicMBean so that the MBeanInfo presents one MBeanAttributeInfo per thread in the WeakHashMap. Make the attribute names the names of the threads and the type a URI (or a String).
- Implement the DynamicMBean so that the getAttribute method returns the URI of the thread that corresponds to the requested attribute name.
- Configure the filter so that it is called for all URI ranges you want to track.
When you view the attributes of the MBean, you will see the URI (or NO REQUEST) for each thread that is still active in the JVM that has processed at least one request. When a thread terminates (and perhaps after a few GC cycles), the WeakHashMap entry will be removed.
It looks a bit arduous now that I read it, but it should be pretty straightforward.
//Nicholas