jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qcfireball <qcfireb...@yahoo.com>
Subject Re: Reregistering Node Types in RMI
Date Sun, 12 Aug 2007 15:04:03 GMT

This is not entirely true.  I have recently set this up on oyur servers to be
able to do this.  For Jackrabbit 1.3, the RMI classes use the "generic" RMI
classes.  There are, however, Jackrabbit specific classes that can be used
to enable this type of functionality.  

What I did was create a JSP that registers a new RMI server on port 1099. 
This JSP was then deployed to the Jackrabbit web apps "root" directory. 
Here is what the JSP basically did:

1 - obtain a JNDI reference to the Repository.
2 - create the Jackrabbit specific RMI server, and register it in the RMI
namespace:
I have listed the imports here, so there is no question about what classes
are used:

<%@page import="javax.jcr.Repository" %>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="org.apache.jackrabbit.rmi.client.ClientRepositoryFactory" %>
<%@page
import="org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory"%>
<%@page
import="org.apache.jackrabbit.rmi.jackrabbit.JackrabbitServerAdapterFactory"%>
<%@page import="org.apache.jackrabbit.rmi.remote.RemoteRepository" %>
<%@page import="java.rmi.registry.Registry" %>
<%@page import="java.rmi.registry.LocateRegistry" %>

private final boolean addServer(final javax.servlet.jsp.JspWriter out) {
    try {
        final Repository r = getRepository();
        if (factory == null) {
            factory = new JackrabbitServerAdapterFactory();
        }
        if (remoteRepo == null) {
            remoteRepo = factory.getRemoteRepository(r);
        }
        final Registry reg = getRegistry();
        reg.rebind(REPO, remoteRepo);
        return true;
    } catch (Exception e) {
        final java.io.ByteArrayOutputStream ops = new
java.io.ByteArrayOutputStream(1024);
        e.printStackTrace(new java.io.PrintStream(ops));
        try {
            out.println("Error binding server " + RMI_URL + "<BR />" +
ops.toString() + "<BR />");
        } catch (Exception exp) { }
    }
    return false;
}

3 - now the client side, you create a connection to the RMI server such as
with these two methods:

    public final Session connect(final LocalAdapterFactory laf, 
                                 final javax.jcr.Credentials cred, 
                                 final String sWorkspace) throws
ConnectionException {
        try {
            final ClientRepositoryFactory factory = 
                    (laf == null ? new ClientRepositoryFactory() : new
ClientRepositoryFactory(laf));
            final Repository reposit = factory.getRepository(getRmiUrl());
            final Session               sess = reposit.login(cred,
sWorkspace);
            return sess;
        } catch (Exception e) {
            throw new ConnectionException("Error connecting to the
repository.", e);
        }
    }
    public final Session connect(final LocalAdapterFactory laf) throws
ConnectionException {
        return connect(laf, getCredentials(), workspace);
    }

and the instance of a LocalAdapterFactory to use is:

org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory

similar to:

    private Session connect2() {
        Properties p = null;
        try {
            p = PropertiesLoader.load(LoadXML.class.getName(), false);
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }
        final ConnectionFactory factory = (p != null ? new
ConnectionFactory(p) : null);
        factory.setRepository("jr.repository");
        try {
            return factory.connect(new JackrabbitClientAdapterFactory());
        } catch (ConnectionException ex) {
            ex.printStackTrace();
        }
        return null;
    }

Then, to get the NodeTypeManager to be able to create a new NodeType:

        final JackrabbitNodeTypeManager jrntm = (JackrabbitNodeTypeManager)
s.getWorkspace().getNodeTypeManager();
        //** nodeTypeExists("tnc:resource")
        if (false) {
            System.out.println("Already registered.");
        } else {
            final InputStream ips = getNodeTypeStream();
            final NodeType[] nta = jrntm.registerNodeTypes(ips,
Jcr.MimeType.CND.toString());
            if (nta != null && nta.length > 0) {
                System.out.println("Successfully registered.");
            }
        }

I used the CND style language.  The class also supports the XMl style as
well.  Post again if you have any more questions.  I'd be glad to help.


Christoph Kiehl wrote:
> 
> gsoap wrote:
> 
>> I am working with jackrabbit in RMI mode.
>> 
>> I want to reregister node types.
>> 
>> Is it possible to reregister node types using RMI mode?
> 
> No, unfortunately this is currently not supported. I wrote a mail[1] to 
> the developer list to check if we can integrate that feature in a future 
> version. But for now you have to reregister nodetypes directly.
> 
> Cheers,
> Christoph
> 
> 
> [1] 
> http://www.nabble.com/Nodetype-reregistration-and-JackrabbitNodeTypeManager-tf4254590.html
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Reregistering-Node-Types-in-RMI-tf4253117.html#a12114906
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message