AnsweredAssumed Answered

JCR-RMI with multi-valued property

Question asked by vijayreddy on Nov 23, 2008
Latest reply on Oct 22, 2009 by baromojm
I have followed the instructions here: http://wiki.alfresco.com/wiki/Install_Extension_without_a_Compile_-_Plugin

I also have the extension-thread-bound-jcr applied as described here http://forge.alfresco.com/frs/shownotes.php?release_id=298

For a multi-valued property, property.getValues() results in "java.lang.ClassCastException: $Proxy89 cannot be cast to [Ljavax.jcr.Value;"
For a single-valued property, property.getValue() works fine.

Here is the code snippet from my jcrRmiTest.jsp:


<%@page import="java.rmi.Naming" %>
<%@page import="java.util.Properties" %>

<%@page import="javax.jcr.*" %>

<%@page import="org.apache.commons.logging.Log" %>
<%@page import="org.apache.commons.logging.LogFactory" %>

<%@page import="org.apache.jackrabbit.rmi.client.ClientAdapterFactory" %>
<%@page import="org.apache.jackrabbit.rmi.client.LocalAdapterFactory" %>
<%@page import="org.apache.jackrabbit.rmi.remote.RemoteRepository" %>

<%
     /* define locals */
      String vRmiRegistryLocation = null;
      Object vRemoteObjectReference = null;
      Repository vJcrRepository = null;
      LocalAdapterFactory vLocalAdapterFactory = null;
      Session vJcrSession = null;
      Node vJcrNode = null;
      String vRmiServerName = null;
      String vRmiServerPort = null;
      String vRmiBindingName = null;
      Properties vJcrRmiProperties = null;
     
      try
      {

         /* intitalize */
         vJcrRmiProperties = new Properties();
         vLocalAdapterFactory = new ClientAdapterFactory();
         vJcrRmiProperties.load(this.getClass().getClassLoader().getResourceAsStream("/alfresco/extension/jcr-rmi.properties"));
     
         /* get command line argments for connection parameters */
         vRmiServerName = vJcrRmiProperties.getProperty("rmi.jcr.binding.servername");
         vRmiServerPort = vJcrRmiProperties.getProperty("rmi.jcr.binding.port");
         vRmiBindingName = vJcrRmiProperties.getProperty("rmi.jcr.binding.name");

         vRmiRegistryLocation  = "//"+vRmiServerName;
         vRmiRegistryLocation += ":"+vRmiServerPort;
         vRmiRegistryLocation += "/"+vRmiBindingName;
%>
<h1>JCR RMI Test</H1></br>
<b>RMI Registery Server Name        :</b><%=vRmiServerName%></br>
<b>RMI Registery Server Name        :</b><%=vRmiServerName%></br>
<b>Remote JCR reference binding name:</b><%=vRmiBindingName%></br>
</p>
<b>Connection String:</b><%=vRmiRegistryLocation%></br>
<p>
<h2>Testing…</h2></br>
<%
         out.write("looking up remote reference at ["+vRmiRegistryLocation+"]</br>");


         vRemoteObjectReference = Naming.lookup(vRmiRegistryLocation);
        
         out.write("creating local adapter for remotereference ["+vRemoteObjectReference+"]</br>");
         vJcrRepository = vLocalAdapterFactory.getRepository((RemoteRepository)vRemoteObjectReference);
        
         out.write("logging in as admin admin to default workspace</br>");
         vJcrSession = vJcrRepository.login(new SimpleCredentials("admin", "admin".toCharArray()));

         out.write("looking up workspace root node</br>");
         vJcrNode = vJcrSession.getRootNode();
        
         Node cHome = vJcrNode.getNode("app:company_home");
         NodeIterator iter = vJcrSession.getRootNode().getNode("app:company_home").getNode("cm:TestDocs").getNodes();
         Node node = iter.nextNode();
         node = iter.nextNode();
   
         Property property = node.getProperty("mydm:sampleMultiValuedProp");
         Value[] values = property.getValues();
         out.write("node UUID ["+node.getUUID() +"]</br>");

         out.write("root node UUID ["+vJcrNode.getUUID() +"]</br>");
        
         out.write("logging out</br>");
         vJcrSession.logout();
      }
      catch(Exception eTestFailure)
      {
        
         out.write("unexpected exception encountered ["+eTestFailure+"]</br>");
      }
%>

Any pointers?

Outcomes