Hi Sanjay

Hi,
>
> Using Nuxeo 5.2 M4 with JBoss 4.2.3 GA.
>
> I am trying to connect to Nuxeo repository using code similar to
> http://svn.nuxeo.org/nuxeo/sandbox/nuxeo-remoting-sample/ but from a war
> file (JAX-RS resource). However, I get ClassCastException while trying to
> cast jndi retrieved object (proxy) in the following code.
>
>    private static CoreSession getSession()
>            throws NamingException {
>        String beanRemoteLocation = "nuxeo/DocumentManagerBean/remote";
>        javax.naming.Context ctx = getInitialContext();
>        Object proxy = ctx.lookup(beanRemoteLocation);
>        CoreSession session = (CoreSession) proxy; //classcastexception
>        return session;
>    }
>
> My war (a JAX-RS resource) also packages nuxeo-core-apis.jar (snapshot
> 1.5). Nuxeo.ear (which also happens to package the same core apis jar) is
> deployed on the same server (successfully). Please provide pointer to a
> working sample code and packaging directions that uses Java (local or
> remote) APIs to connect to the Nuxeo Repository. Note that my war will
> always be colocated with Nuxeo.ear in the same JVM.
>

Your code is failing because the CoreSession in your war in not the same as
the CoreSession in nuxeo.ear (same bytecode but loaded by different class
loader)

The code of nuxeo-remoting works because the returned value is deserialized
by the classloader of the user of the nuxeo-remoting client.

To avoid the class cast exception, you could force your war to use the same
loader repository as nuxeo.ear. This way only 1 CoreSession would be loaded.
You could add this to the jboss-web.xml of your war file.

<jboss-web>
 <class-loading java2ClassLoadingCompliance="false">
             <loader-repository>
             org.nuxeo:loader=nuxeo.ear
             
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
         </loader-repository>
 </class-loading>

I haven't check it, so please don't hesitate to share your result :-)

alex
_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm

Reply via email to