[jboss-user] [EJB 3.0] - JBoss 4.2.1 RemoteEJB Lookup ClassCastException

Marcus Linke do-not-reply at jboss.com
Tue Jun 22 03:07:12 EDT 2010


Marcus Linke [http://community.jboss.org/people/marcuslinke] replied to the discussion

"JBoss 4.2.1 RemoteEJB Lookup ClassCastException"

To view the discussion, visit: http://community.jboss.org/message/549052#549052

--------------------------------------------------------------
I've read this and found a simpler solution / workaround for this problem (without the need of patching). It's simple to integrate the appropriate code taken from EJBTHREE-1889 into the own JNDI lookup. Because of performance reasons this hack of course should be used only for JVM internal remote lookups (which is the case with isolated EAR's). This may be realized by using different JNDI lookup wrapper classes...

public class JBossRemoteJndiLookup<T> {
    public T lookup(String resourceName) {
        Object o = new InitialContext().lookup(resourceName);
        o = refineObjectInContextClassLoader(o);
        return (T) o;
    }

    /**
     * This is a workaround for  http://community.jboss.org/thread/111016 http://community.jboss.org/thread/111016. It is taken from
     *  https://jira.jboss.org/browse/EJBTHREE-1889 https://jira.jboss.org/browse/EJBTHREE-1889. See modifications of ProxyObjectFactory.java
     */
    private Object refineObjectInContextClassLoader(Object o) {
        // EJBTHREE-1889: if the lookup has been performed locally on a remote (business)
        // interface that's defined in the current TCL, then the proxy must implement
        // that TCL defined interface.
        // redefine in TCL
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        try {
            o = redefineObjectInClassLoader(o, tcl);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return o;
    }

    private Object redefineObjectInClassLoader(Object obj, ClassLoader target) throws ClassNotFoundException,
            IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bout);
        out.writeObject(obj);
        out.flush();
        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        ObjectInputStream in = new ObjectInputStreamWithClassLoader(bin, target);
        Object result = in.readObject();
        in.close();
        return result;
    }
}

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/549052#549052]

Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100622/ee94b1bc/attachment.html 


More information about the jboss-user mailing list