You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Mikolaj Rydzewski <mi...@ceti.pl> on 2006/09/15 12:40:51 UTC

Exporting repositories with RMI

Hello,

I want to export a Repository with RMI. So I gathered bot 
jackrabbit-core and jackrabbit-jcr-rmi stuff and (of course) have some 
problems. Could you please point me to the right direction?

When I run the sample code it throws the following exception:
Exception in thread "main" java.rmi.server.ExportException: object 
already exported
        at sun.rmi.transport.ObjectTable.putTarget(ObjectTable.java:172)
        at sun.rmi.transport.Transport.exportObject(Transport.java:75)
        at 
sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:190)
        at 
sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:382)
        at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:116)
        at 
sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:180)
        at 
java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:293)
        at 
java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:235)
        at jackrabbit.rmiserver.Server.main(Server.java:27)


My server code:

public class Server {

    public static void main(String[] args) throws Exception {
       
        Repository repository = getRepository();
        RemoteRepository remoteRepository = getRemoteRepository(repository);
       
        RemoteRepository stub = 
(RemoteRepository)UnicastRemoteObject.exportObject(remoteRepository, 0);
        Registry registry = LocateRegistry.getRegistry();
        registry.bind("rmi_repo", stub);
       
        System.out.println("Server ready");
       
    }

    private static RemoteRepository getRemoteRepository(Repository 
repository) throws RemoteException {
        RemoteAdapterFactory factory = new ServerAdapterFactory();
        RemoteRepository remote = factory.getRemoteRepository(repository);
        return remote;
    }

    private static Repository getRepository() throws NamingException, 
RepositoryException {
        String configFile = "repotest/repository.xml";
        String repHomeDir = "repotest";

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
        env.put(Context.PROVIDER_URL, "localhost");
        InitialContext ctx = new InitialContext(env);
        RegistryHelper.registerRepository(ctx,
               "repo",
                configFile,
                repHomeDir,
                true);
        Repository r = (Repository)ctx.lookup("repo");
        return r;
    }

}


-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re: Exporting repositories with RMI

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Jukka Zitting wrote:
> The RemoteRepository class already inherits UnicastRemoteObject, so
> there's no need to export it. You should be able to directly use
> registry.bind("rmi_repo", remoteRepository).
The interesting thing is, that when I run my sample code:

 java -cp <long classpath>  jackrabbit.rmiserver.Server

and the exception is thrown, the java process doesn't exit, I have to 
hit ^C to stop it.

-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re: Exporting repositories with RMI

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Jukka Zitting wrote:
> Have you set your codebase correctly? The RMI registry needs to be
> able to load the stub class from the codebase.
Thanks a lot. After starting rmiregistry with jcr.jar and 
jackrabbit-jcr-rmi.jar on the classpath everything works.

-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re: Exporting repositories with RMI

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 9/15/06, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
> Jukka Zitting wrote:
> > The RemoteRepository class already inherits UnicastRemoteObject, so
> > there's no need to export it. You should be able to directly use
> > registry.bind("rmi_repo", remoteRepository).
> Nope. The following exception is thrown:
>
> Exception in thread "main" java.rmi.UnexpectedException: undeclared
> checked exception; nested exception is:
>         java.lang.ClassNotFoundException: Could not find class
> (org.apache.jackrabbit.rmi.server.ServerRepository_Stub) at codebase ()

Have you set your codebase correctly? The RMI registry needs to be
able to load the stub class from the codebase.

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development

Re: Exporting repositories with RMI

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Jukka Zitting wrote:
> The RemoteRepository class already inherits UnicastRemoteObject, so
> there's no need to export it. You should be able to directly use
> registry.bind("rmi_repo", remoteRepository).
Nope. The following exception is thrown:


Exception in thread "main" java.rmi.UnexpectedException: undeclared 
checked exception; nested exception is:
        java.lang.ClassNotFoundException: Could not find class 
(org.apache.jackrabbit.rmi.server.ServerRepository_Stub) at codebase ()
        at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
        at jackrabbit.rmiserver.Server.main(Server.java:29)
Caused by: java.lang.ClassNotFoundException: Could not find class 
(org.apache.jackrabbit.rmi.server.ServerRepository_Stub) at codebase ()
        at 
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
        at 
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)
        ... 2 more


I use JDK1.5, I have even recompiled jcr-rmi with Java1.5, still the 
same effect.


-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re: Exporting repositories with RMI

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 9/15/06, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
> I want to export a Repository with RMI. So I gathered bot
> jackrabbit-core and jackrabbit-jcr-rmi stuff and (of course) have some
> problems. Could you please point me to the right direction?
> [...]
>         RemoteRepository stub =
> (RemoteRepository)UnicastRemoteObject.exportObject(remoteRepository, 0);
>         Registry registry = LocateRegistry.getRegistry();
>         registry.bind("rmi_repo", stub);

The RemoteRepository class already inherits UnicastRemoteObject, so
there's no need to export it. You should be able to directly use
registry.bind("rmi_repo", remoteRepository).

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development