Skip navigation

CQ5

VFinet
Currently Being Moderated

Connection to CRX via RMI and getting WeakReference value..... with an exception!

Mar 15, 2012 4:05 AM

Tags: #cq5 #crx #rmi #day

Hi there,

 

 

I have the following problem.

 

 

I opened a ticket in Day Care Support system, about CRX users/group membership that got lost while synchronization with our LDAP server.

Although when the user and the group had been created (and therefore taken from that same LDAP server), the membership was good.... but after some time the membership got lost......

 

 

So what i am trying to do now is a Java program that connects to CRX via RMI.

And gets the list of all the users from a group (aka membership).

The idea is to monitor the membership each seconds.

 

 

But when trying to get the property "rep:members" of the group, I have the following exception :

javax.jcr.ValueFormatException: Unknown value type 10

          at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException( ServerObject.java:139)

          at org.apache.jackrabbit.rmi.server.ServerProperty.getValues(ServerPrope rty.java:71)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:60)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:37)

          at java.lang.reflect.Method.invoke(Method.java:611)

          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)"

          ....

 

 

I searched a little bit and found that "10" is the number for type WeakReference.

That's normal to me because memberships are stored in the group as a list reference to users linked to that group....

 

 

Anyways, what's not normal to me is that when the type is "10" the API does not let me get the Value (cf. ServerProperty.getValues() method)

 

 

Here is the program:

import java.util.HashMap;

 

 

import java.util.Iterator;

import java.util.Map;

 

 

import javax.imageio.spi.ServiceRegistry;

import javax.jcr.Node;

import javax.jcr.NodeIterator;

import javax.jcr.Property;

import javax.jcr.PropertyIterator;

import javax.jcr.Repository;

import javax.jcr.RepositoryException;

import javax.jcr.RepositoryFactory;

import javax.jcr.Session;

import javax.jcr.SimpleCredentials;

import javax.jcr.Value;

 

 

public class Test {

 

 

          public static void main(String[] args) {

 

                    String uri = "rmi://sma11c02.............:1234/crx";

                    String username = "admin";

                    char[] password = {....................};

                    String workspace = "crx.default";

                    String nodePath = "/home/groups/a";

 

                    Repository repository = null;

                    Session session = null;

                    try {

 

 

                              // ---------------------------------------------------

                              // Connection to repository via RMI

                              // ---------------------------------------------------

                              {

                                        Map<String, String> jcrParameters = new HashMap<String, String>();

                                        jcrParameters.put("org.apache.jackrabbit.reposito ry.uri", uri);

                                        Iterator<RepositoryFactory> iterator = ServiceRegistry.lookupProviders(RepositoryFactory.class);

                                        while (null == repository && iterator.hasNext()) {

                                                  repository = iterator.next().getRepository(jcrParameters);

                                        }

                              }

                              if (repository == null) {

                                        throw new IllegalStateException("Problem with connection to the repository...");

                              }

 

 

                              // ---------------------------------------------------

                              // Creation of a session to the workspace

                              // ---------------------------------------------------

                              session = repository.login(new SimpleCredentials(username, password), workspace);

                              if (session == null) {

                                        throw new IllegalStateException("Problem with creation of session to the workspace...");

                              }

 

                              // ---------------------------------------------------

                              // Get the targetted node

                              // ---------------------------------------------------

                              Node node = session.getNode(nodePath);

                              System.out.println("Node : " + node.getName());

                              System.out.println();

 

                              PropertyIterator properties = node.getProperties();

                              System.out.println("List of properties for this node :");

                              while (properties.hasNext()) {

                                        Property property = properties.nextProperty();

                                        System.out.print("\t"+property.getName() + " : ");

                                        if (property.isMultiple()) {

                                                  Value[] values = property.getValues();

                                                  for (int i = 0; i < values.length; i++) {

                                                            System.out.print(values[i]);

                                                            if (i+1 != values.length) {

                                                                      System.out.print(", ");

                                                            }

                                                  }

                                                  System.out.println();

                                        } else {

                                                  Value value = property.getValue();

                                                  System.out.println(value);

                                        }

                              }

                              System.out.println();

 

                              NodeIterator kids = node.getNodes();

                              System.out.println("List of children nodes for this node :");

                              while (kids.hasNext()) {

                                        Node kid = kids.nextNode();

                                        System.out.println("\tChild node : "+kid.getName());

 

 

                                        PropertyIterator kidProperties = kid.getProperties();

                                        System.out.println("List of properties for this child :");

                                        while (kidProperties.hasNext()) {

                                                  Property property = kidProperties.nextProperty();

                                                  System.out.print("\t"+property.getName() + " : ");

                                                  if (property.isMultiple()) {

                                                            Value[] values = property.getValues();

                                                            for (int i = 0; i < values.length; i++) {

                                                                      System.out.print(values[i]);

                                                                      if (i+1 != values.length) {

                                                                                System.out.print(", ");

                                                                      }

                                                            }

                                                            System.out.println();

                                                  } else {

                                                            Value value = property.getValue();

                                                            System.out.println(value);

                                                  }

                                        }

                                        System.out.println();

                              }

                    } catch (RepositoryException e) {

                              e.printStackTrace();

                    } finally {

                              if (session != null) {

                                        session.logout();

                              }

                    }

          }

}

 

 

Here is the output of the below program:

 

 

Node : a

 

 

List of properties for this node :

          jcr:createdBy : admin

          jcr:mixinTypes : mix:lockable

          jcr:created : 2011-10-25T16:58:48.140+02:00

          jcr:primaryType : rep:AuthorizableFolder

 

 

List of children nodes for this node :

          Child node : administrators

List of properties for this child :

          jcr:createdBy : admin

          rep:principalName : administrators

          rep:members : javax.jcr.ValueFormatException: Unknown value type 10

          at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException( ServerObject.java:139)

          at org.apache.jackrabbit.rmi.server.ServerProperty.getValues(ServerPrope rty.java:71)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:60)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:37)

          at java.lang.reflect.Method.invoke(Method.java:611)

          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)

          at sun.rmi.transport.Transport$1.run(Transport.java:171)

          at java.security.AccessController.doPrivileged(AccessController.java:284 )

          at sun.rmi.transport.Transport.serviceCall(Transport.java:167)

          at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5 47)

          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor t.java:802)

          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport .java:661)

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec utor.java:897)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:919)

          at java.lang.Thread.run(Thread.java:736)

          at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow n Source)

          at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)

          at sun.rmi.server.UnicastRef.invoke(Unknown Source)

          at org.apache.jackrabbit.rmi.server.ServerProperty_Stub.getValues(Unknow n Source)

          at org.apache.jackrabbit.rmi.client.ClientProperty.getValues(ClientPrope rty.java:173)

          at Test.main(Test.java:96)

 

 

Here is the list of jar files i'm using with this program:

          2862818581          61388           crx-rmi-2.2.0.jar

          732434195           335603           jackrabbit-jcr-commons-2.4.0.jar

          1107929681           411330           jackrabbit-jcr-rmi-2.4.0.jar

          3096295771           69246           jcr-2.0.jar

          1206850944           367444           log4j-1.2.14.jar

          685167282           25962           slf4j-api-1.6.4.jar

          2025068856           9748           slf4j-log4j12-1.6.4.jar

 

 

Finally, we are using CQ 5.4 (CRX 2.2) with the latest hotfix and under Websphere 7.0

 

 

Best regards,

Vincent FINET

 
Replies
  • Currently Being Moderated
    Mar 15, 2012 5:24 AM   in reply to VFinet

    is the same error produced if you execute your code directly on the instance and not via RMI? use CRXDE lite (/crxde) to create a simple node with resource type and associated JSP to test.

     

    also you might try to work with the jackrabbit user mangager (http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/securit y/user/UserManager.html) which you obtain by casting the jcr session to  a JackrabbitSession (http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/Jackrab bitSession.html).

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 12, 2012 3:31 PM   in reply to VFinet

    Hey Vincent,

     

    I have been trying to connect to CRX via rmi and it works when CRX and client runs on the same server.  But when they are on different servers with a firewall between, I am getting rmi connection exception.  You seem to have overcome that problem.

     

    Can you please share some information on how you got it to work?

     

    Thanks!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points