christianbastin / jackrabbitexplorer

Automatically exported from code.google.com/p/jackrabbitexplorer
0 stars 1 forks source link

Connect over jnp as well for JBoss users #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What is the requirement/enhancement?

Support jnp protocol along side the existing RMI over HTTP URL to connect to a 
repository

Is it needed or just nice to have?

Nice for JBoss users

Why is it needed/wanted?

JBoss (4.2.3) exposes a jnp rmi address, but not a http rmi address 

What is the approx effort?

Not sure the right JackRabbit way. I added the jackrabbit-jcr-rmi.jar to the 
deploy dir of JBoss and then changed the getNewSession() method of 
JcrServiceImpl to :

public Session getNewSession(String rmiUrl, String workSpace, String userName, 
String password) throws SerializedException {
    try {
        Repository repository;
        if (rmiUrl.toLowerCase().startsWith("jnp"))
    {
        Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

            InitialContext ctx = new InitialContext(env);
            ClientAdapterFactory adapter = new ClientAdapterFactory();

            // for JBoss the with the jcr-rmi is jnp://localhost:1099/jcrServer
            RemoteRepository rr = (RemoteRepository) ctx.lookup(rmiUrl);                    
           repository = adapter.getRepository(rr);
        }
        else
        {
            repository = new URLRemoteRepository(rmiUrl);
        }

        SimpleCredentials creds = new SimpleCredentials(userName, password.toCharArray());
        return repository.login(creds, workSpace);
    } catch (Exception e) {
        log.info("Failed Login. " + e.getMessage());
        throw new SerializedException(e.getMessage());
    }
}

Maybe there is a better way or a way to call rmi over http with JBoss 
integration.

Thanks,
Carl.

Original issue reported on code.google.com by carl.pri...@gmail.com on 6 May 2011 at 6:29

GoogleCodeExporter commented 8 years ago
I have built a war that is Java 5 compliant and can connect via RMI to 
repositories deployed inside JBoss 4.x.
If you are interested, give me an upload location and I will provide it.

To the committers:
Codes changes are minimal:

--add a dependency to jbossall-client-4.2.2.GA.jar. Do not include the jar in 
the war

--make code Java 5 compliant; all you will have to do with latest SVN head is 
to remove a dozen @Override annotations.

-in JCRServiceImpl#getNewSessionViaRMI and BinayServlet#login, replace the 
repository variable assignment with

Repository repository;

if ( rmiUrl.startsWith("jnp:") ) {

    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

    InitialContext ctx = new InitialContext(env);

    RemoteRepository rr = (RemoteRepository) ctx.lookup(rmiUrl);

    ClientAdapterFactory adapter = new ClientAdapterFactory();
    repository = adapter.getRepository(rr);
}
else {

    repository = new URLRemoteRepository(rmiUrl);
}

voilà

Original comment by bruno.gr...@gmail.com on 28 Jan 2012 at 11:14