This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi all! Please help me resolve the problem: When I make JNDI lookup to get reference to some server object : SomeClass mbs = (SomeClass) initCtx.lookup("some"); I receive ClassCastException, I know my server use different class loader to load this object. Somebody knows how to make casting when classes loaded by different class loaders?
So you are finding that the following code reports the same Class but different ClassLoaders?
If this is the problem you are having, there is a very nasty fix where you get a PipedStream with ObjectStreams at either end. You get your instance as an Object, pass it through the piped Stream and then do the cast at the other end. I don't have sample code available, but I can go look if you want. Dave.
Joined: Sep 18, 2003
Please!!! Give me example!!! Please!!!
Joined: Sep 18, 2003
I tried to do somthing, but have a new problem: lookupED object does not Serializable, then ObjectOutputStream oos = new ObjectOutputStream(obj); does not work, can you send me another example?
If we passed through streams, the reference to remote object still avaiable?
OK, I found it. I really do have to say 'Use this at your own risk'. We should probably start to look at your setuo and find out why you are having ClassLoader problems. I consider the following piece of code a horrible hack that is designed to hide problems, not fix them.
If we passed through streams, the reference to remote object still avaiable? Yes and No. The new object loses the reference, but you still have access to the old object. You'll need to decide what to do about that if you need call-backs. You might need to create a proxy that wraps the problem class and passes method calls via reflection... I hope this gets you started though. Dave