I’ve got some crazy task, that sounds like mission impossible. I need to pass some data through stack of methods, which I can’t modify (can modify only the last one). Example:
SomeData someData; //not passed in method1
obj1.method1(...);
here is obj1 class code
obj1 {
someReturnClass method1(...) {
...
obj2.method2(...);
...
}
}
obj2 and method2 call some more methods, before they get to objN.methodM(). It can even be run in separate thread (so, ThreadLocal won’t help). I need to access someData inside methodM, which is not passed through this stack as parameter.
I’ve got some concepts to get it through exception and double running methodM, but it looks ugly.
Do you have any ideas, how to pass someData to methodM()?
Finally, I found solution:
Create JAAS Subject
Put data somewhere in subject’s principals or credentials:
Get this subject and it’s data anywhere you need (works even in another thread):
It won’t work only in one case: thread started before subject was created.