You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ruchi Goel <Ru...@Sun.COM> on 2006/12/06 17:29:27 UTC

Error in logging in to remote repository via JNDI (using Tomcat)

Hi,

 I have RMIServer :
public class RMIServer {
   
        private static String REPOSITORY_CONFIG="repository-xml.xml";
        private static String REPOSITORY_DIR="PortalContentRepository";

    
    /**
     * The main entry point of the example application.
     *
     * @param args command line arguments (ignored)
     * @throws Exception if an error occurs
     */
    public static void main(String[] args) throws Exception {
        Repository repository = new 
TransientRepository(REPOSITORY_CONFIG,REPOSITORY_DIR);
       
        ServerAdapterFactory factory = new ServerAdapterFactory();
        RemoteRepository remote = factory.getRemoteRepository(repository);
        Registry reg = LocateRegistry.createRegistry(1101);
        reg.rebind("jackrabbit", remote);
       
       
    }


Following RMIClient  is able to conenct and write to the above repository.
public class RMIClient {

    /**
     * The main entry point of the example application.
     *
     * @param args command line arguments (ignored)
     * @throws Exception if an error occurs
     */
    public static void main(String[] args) throws Exception {
        ClientRepositoryFactory factory = new ClientRepositoryFactory();
        Repository repository = 
factory.getRepository("rmi://localhost:1101/jackrabbit");
       
        Session session = repository.login(new 
SimpleCredentials("superuser", "superuser".toCharArray()),null);
        //Session session = repository.login();
        try {
            String user = session.getUserID();
            String name = 
repository.getDescriptor(Repository.REP_NAME_DESC);
            System.out.println(
                    "Logged in as " + user + " to a " + name + " 
repository.");
           
            //Test adding and saving of node via to repository accessed 
via rmi
             Node rn = session.getRootNode();
             Node  cms = rn.addNode("cms");
      
            //---------------------------add first 
ad-----------------------------------
            Node ad = cms.addNode("ad");           
            ad.setProperty("title","IT Jobs !!");
            session.save();
            ad.save();
           
        } finally {
            session.logout();
        }
    }


Now, I am trying JNDI from web application to discover the remote 
repository. I registered under Tomcat server.xml following :
<Resource auth="Container" 
factory="org.apache.jackrabbit.rmi.client.ClientRepositoryFactory" 
name="jcr/globalRepository"  url="rmi://localhost:1101/jackrabbit" 
type="javax.jcr.Repository" />
and the web application tries to login to repository via following :
 InitialContext initial = new InitialContext();
       
        //Look up needed for Tomcat
        Context context = (Context) initial.lookup("java:comp/env");
        System.out.println("before lookup");
        repository = (Repository) context.lookup("jcr/GlobalRepository");
       repository.login(new SimpleCredentials("superuser", 
"superuser".toCharArray()));

I get following error in last line , while I am able to login as anonymous.
java.rmi.ServerException: RemoteException occurred in server thread; 
nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; 
nested exception is:
        java.net.MalformedURLException: no protocol: 
Files/netbeans-5.0/enterprise2/jakarta-tomcat-5.5.9/common/classes/
        at 
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:325)
        at sun.rmi.transport.Transport$1.run(Transport.java:153)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
        at 
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
        at 
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
        at java.lang.Thread.run(Thread.java:595)
        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:126)
        at 
org.apache.jackrabbit.rmi.server.ServerRepository_Stub.login(Unknown Source)
        at 
org.apache.jackrabbit.rmi.client.ClientRepository.login(ClientRepository.java:97)
        at 
com.sun.portal.cms.ad.service.AdModelServiceImpl.getSession(AdModelServiceImpl.java:43)
        at 
com.sun.portal.cms.ad.service.AdModelServiceImpl.getAd(AdModelServiceImpl.java:67)
        at 
com.sun.portal.cms.ad.model.TemplateFiller.getHtmlFromCMS(TemplateFiller.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

P.S .I have jcr-rmi.jar under commons as well webapp   WEB-INF//lib 
directory


Appreciate help.
Thanks,
Ruchi






Re: Error in logging in to remote repository via JNDI (using Tomcat)

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

On 12/6/06, Ruchi Goel <Ru...@sun.com> wrote:
> I get following error in last line , while I am able to login as anonymous.
> [...]
>         java.net.MalformedURLException: no protocol:
> Files/netbeans-5.0/enterprise2/jakarta-tomcat-5.5.9/common/classes/

This seems to be caused by an unencoded space in the codebase URL of a
marshalled object that the *server* is trying to unmarshal. This is a
quite tricky issue that is caused by the use of URLClassLoader based
on File.toURL() rather than File.toURI().toURL() together with the
following "will not be fixed" issue in Java:

  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4273532

You should be able to avoid this issue by adding the
-Djava.rmi.server.useCodebaseOnly=true option to the RMI server.

PS. You probably should make the "RemoteRegistry remote" variable a
static class member to avoid it being garbage-collected while no
clients are connected.

BR,

Jukka Zitting

Re: Error in logging in to remote repository via JNDI (using Tomcat)

Posted by Tobias Bocanegra <to...@day.com>.
hi,
this is probably a problem of the escaping of the classpaths in the
RMI layer of the jdk:

in the path of "c:/Program Files/..." the space is not properly
escaped, hence this error:

java.net.MalformedURLException: no protocol:
Files/netbeans-5.0/enterprise2/jakarta-tomcat-5.5.9/common/classes/

see also:
http://archives.java.sun.com/cgi-bin/wa?A2=ind0205&L=rmi-users&P=797

the simplest fix is to move your installation to a path that does not
contain spaces.

regards, toby


On 12/6/06, Ruchi Goel <Ru...@sun.com> wrote:
> Hi,
>
>  I have RMIServer :
> public class RMIServer {
>
>         private static String REPOSITORY_CONFIG="repository-xml.xml";
>         private static String REPOSITORY_DIR="PortalContentRepository";
>
>
>     /**
>      * The main entry point of the example application.
>      *
>      * @param args command line arguments (ignored)
>      * @throws Exception if an error occurs
>      */
>     public static void main(String[] args) throws Exception {
>         Repository repository = new
> TransientRepository(REPOSITORY_CONFIG,REPOSITORY_DIR);
>
>         ServerAdapterFactory factory = new ServerAdapterFactory();
>         RemoteRepository remote = factory.getRemoteRepository(repository);
>         Registry reg = LocateRegistry.createRegistry(1101);
>         reg.rebind("jackrabbit", remote);
>
>
>     }
>
>
> Following RMIClient  is able to conenct and write to the above repository.
> public class RMIClient {
>
>     /**
>      * The main entry point of the example application.
>      *
>      * @param args command line arguments (ignored)
>      * @throws Exception if an error occurs
>      */
>     public static void main(String[] args) throws Exception {
>         ClientRepositoryFactory factory = new ClientRepositoryFactory();
>         Repository repository =
> factory.getRepository("rmi://localhost:1101/jackrabbit");
>
>         Session session = repository.login(new
> SimpleCredentials("superuser", "superuser".toCharArray()),null);
>         //Session session = repository.login();
>         try {
>             String user = session.getUserID();
>             String name =
> repository.getDescriptor(Repository.REP_NAME_DESC);
>             System.out.println(
>                     "Logged in as " + user + " to a " + name + "
> repository.");
>
>             //Test adding and saving of node via to repository accessed
> via rmi
>              Node rn = session.getRootNode();
>              Node  cms = rn.addNode("cms");
>
>             //---------------------------add first
> ad-----------------------------------
>             Node ad = cms.addNode("ad");
>             ad.setProperty("title","IT Jobs !!");
>             session.save();
>             ad.save();
>
>         } finally {
>             session.logout();
>         }
>     }
>
>
> Now, I am trying JNDI from web application to discover the remote
> repository. I registered under Tomcat server.xml following :
> <Resource auth="Container"
> factory="org.apache.jackrabbit.rmi.client.ClientRepositoryFactory"
> name="jcr/globalRepository"  url="rmi://localhost:1101/jackrabbit"
> type="javax.jcr.Repository" />
> and the web application tries to login to repository via following :
>  InitialContext initial = new InitialContext();
>
>         //Look up needed for Tomcat
>         Context context = (Context) initial.lookup("java:comp/env");
>         System.out.println("before lookup");
>         repository = (Repository) context.lookup("jcr/GlobalRepository");
>        repository.login(new SimpleCredentials("superuser",
> "superuser".toCharArray()));
>
> I get following error in last line , while I am able to login as anonymous.
> java.rmi.ServerException: RemoteException occurred in server thread;
> nested exception is:
>         java.rmi.UnmarshalException: error unmarshalling arguments;
> nested exception is:
>         java.net.MalformedURLException: no protocol:
> Files/netbeans-5.0/enterprise2/jakarta-tomcat-5.5.9/common/classes/
>         at
> sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:325)
>         at sun.rmi.transport.Transport$1.run(Transport.java:153)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
>         at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
>         at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
>         at java.lang.Thread.run(Thread.java:595)
>         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:126)
>         at
> org.apache.jackrabbit.rmi.server.ServerRepository_Stub.login(Unknown Source)
>         at
> org.apache.jackrabbit.rmi.client.ClientRepository.login(ClientRepository.java:97)
>         at
> com.sun.portal.cms.ad.service.AdModelServiceImpl.getSession(AdModelServiceImpl.java:43)
>         at
> com.sun.portal.cms.ad.service.AdModelServiceImpl.getAd(AdModelServiceImpl.java:67)
>         at
> com.sun.portal.cms.ad.model.TemplateFiller.getHtmlFromCMS(TemplateFiller.java:69)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> P.S .I have jcr-rmi.jar under commons as well webapp   WEB-INF//lib
> directory
>
>
> Appreciate help.
> Thanks,
> Ruchi
>
>
>
>
>
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---