jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duke Fong" <df...@idc-global.com>
Subject RE: [jira] Erledigt: (JCR-291) jcr-server-webapp: RMI Registration unstable
Date Thu, 15 Dec 2005 19:28:19 GMT
Felix.

Hello.  It is code that is copied form the /contrib/examples.  Here is the
class I am using as the RMI JCR Client.



FSImport
----------------------------------------------


package com.idc.util;

import org.apache.jackrabbit.core.jndi.RegistryHelper;
import sun.net.www.MimeTable;

import javax.jcr.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Hashtable;

/**
 * The First Steps example class.
 */
public class FSImport {


    private static org.apache.log4j.Logger logger =
            org.apache.log4j.Logger.getLogger(FSImport.class);

    /**
     * Run the Filesystem Import example.
     *
     * @param args command line arguments
     */
    public static void main(String[] args) {
        try {
            Repository repository = getRepository();
            SimpleCredentials creds = new SimpleCredentials("username",
"password".toCharArray());
            Session session = repository.login(creds);
            Node root = session.getRootNode();

            if (args.length>0) {
                File startingpoint=new File(args[0]);
                importFolder (root.addNode(startingpoint.getName(),
"nt:folder"), startingpoint);
                session.save();
                dump(root.getNode(startingpoint.getName()));
            } else {
                System.err.println("Please specify a starting point for the
file system import into the repository.");
            }


        } catch (Exception e) {
            System.err.println(e);
        }
    }

    /**
     * Creates a Repository instance to be used by the example class.
     *
     * @return repository instance
     * @throws Exception on errors
     */
    private static Repository getRepository() throws Exception {
        String configFile = com.idc.RepositoryConst.configFile;
        String repHomeDir = com.idc.RepositoryConst.repHomeDir;

        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);
        return (Repository) ctx.lookup("repo");
    }

    /**
     * Imports a File.
     *
     * @param parentnode Parent Repository Node
     * @param file File to be imported
     * @throws RepositoryException on repository errors, IOException on io
errors
     */

    public static void importFile(Node parentnode, File file) throws
RepositoryException, IOException {

        MimeTable mt = MimeTable.getDefaultTable();
        String mimeType = mt.getContentTypeFor(file.getName());
        if (mimeType==null) mimeType="application/octet-stream";
        logger.debug("[FOUND CONTENT TYPE]:" + mimeType);

        Node fileNode = parentnode.addNode(file.getName(), "nt:file");
        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
        resNode.setProperty("jcr:mimeType", mimeType);
        resNode.setProperty("jcr:encoding", "");
        resNode.setProperty("jcr:data", new FileInputStream(file));
        Calendar lastModified = Calendar.getInstance();
        lastModified.setTimeInMillis(file.lastModified());
        resNode.setProperty("jcr:lastModified", lastModified);
        logger.debug("[IMPORTING]: "+fileNode.getPath());
   }


    /**
     * Import a Folder.
     *
     * @param parentnode Parent Repository Node
     * @param directory Directory to be traversed
     * @throws RepositoryException on repository errors, IOException on io
errors
     */

    private static void importFolder(Node parentnode, File directory) throws
RepositoryException, IOException  {
        File[] direntries = directory.listFiles();
        System.out.println(parentnode.getPath());
        for (int i=0; i<direntries.length; i++) {
            File direntry = direntries[i];
            if (direntry.isDirectory()) {
                Node childnode =
parentnode.addNode(direntry.getName(),"nt:folder");
                importFolder(childnode, direntry);
            } else {
                importFile(parentnode, direntry);
            }
        }
    }

    /**
     * Dumps the contents of the given node to standard output.
     *
     * @param node the node to be dumped
     * @throws RepositoryException on repository errors
     */
    public static void dump(Node node) throws RepositoryException {
        System.out.println(node.getPath());

        PropertyIterator properties = node.getProperties();
        while (properties.hasNext()) {
            Property property = properties.nextProperty();
            System.out.print(property.getPath() + "=");
            if (property.getDefinition().isMultiple()) {
                Value[] values = property.getValues();
                for (int i = 0; i < values.length; i++) {
                    if (i > 0) {
                        System.out.println(",");
                    }
                    System.out.println(values[i].getString());
                }
            } else {
                if (property.getType()==PropertyType.BINARY) {
                    System.out.print("<binary>");
                }  else {
                    System.out.print(property.getString());
                }

            }
            System.out.println();
        }

        NodeIterator nodes = node.getNodes();
        while (nodes.hasNext()) {
            Node child = nodes.nextNode();
            dump(child);
        }
    }
}
---------------------------------------------- 


Duke K. Fong
Integrated Data Corporation
dfong@idc-global.com
310-367-8412
310-815-2800 ext. 215
http://www.idc-global.com
 

-----Original Message-----
From: Felix Meschberger [mailto:Felix.Meschberger@day.com] 
Sent: Wednesday, December 14, 2005 11:34 PM
To: jackrabbit-dev@incubator.apache.org
Subject: Re: [jira] Erledigt: (JCR-291) jcr-server-webapp: RMI Registration
unstable

Hi Duke,

This sounds really strange, I cannot remember ever having had such issues -
except of course if there was no connection at all. So I am a bit out of
advices ....

Would you mind sharing the com.idc.util.FSImport.importFile(Node, File)
method ?

Regards
Felix

Duke Fong schrieb:
> Hello Felix.
>
> Thanks for the reply.
>
> I believe it is the latest, we checked it out last week, both the 
> jackrabbit trunk and contrib trunk.
>
> The file is relatively small, less than 200K.  I ran it through the 
> debugger on the JCR (Client) side.  It seems to connect fine, and am able
to "read"
> from the repository, but when I set the File object to the Node 
> Property, is when the exception comes up.
>
> On the server side, it is the standard JCR Servlet embedded within 
> Tomcat, which creates the RMI Registry.
>
> Do I have to do any special configuration or workarounds to get it to
work?
>
> -Duke
>
>
>
> Duke K. Fong
> Integrated Data Corporation
> dfong@idc-global.com
> 310-367-8412
> 310-815-2800 ext. 215
> http://www.idc-global.com
>  
>
> -----Original Message-----
> From: Felix Meschberger [mailto:Felix.Meschberger@day.com]
> Sent: Wednesday, December 14, 2005 2:02 AM
> To: jackrabbit-dev@incubator.apache.org
> Subject: Re: [jira] Erledigt: (JCR-291) jcr-server-webapp: RMI 
> Registration unstable
>
> Hi Doug,
>
> Thanks for the additional info.
>
> Given the name of the file your are trying to upload - 
> mp3/u2-jesus.nzb
> - I assume you are trying to upload a big file, right ? Could this be 
> the result of an issue with outdated jcr-rmi stream transmission from 
> client to server ? Are you testing with the most recent checkout of 
> the jcr-rmi project on both (client and server) sides ?
>
> FYI: The last change to transmission of binary streams from client to 
> server included reducing the memory footprint - formerly the whole 
> stream was read into memory and then send to the client, while now the 
> stream is sent in segments of at most 4K.
>
> Regards
> Felix
>
> Duke Fong schrieb:
>   
>> Felix.
>>
>> Here is my configuration:
>>
>> Server (embedded within Tomcat, via the JCR-RMI from the contrib).
>>
>> I am attaching my sample client code and the exception.
>>
>>
>> -Duke
>>
>> ------
>>
>>
>>
>> package com.idc;
>>
>> import javax.jcr.*;
>>
>> public class RepoClient {
>>
>>     private static org.apache.log4j.Logger logger =
>>             org.apache.log4j.Logger.getLogger(RepoClient.class);
>>
>>     public static final String rmiURI =
>>             "//IDC19:1099/jackrabbit.repository";
>>
>>     protected static javax.jcr.Repository r =         null;
>>     protected static Session s  = null;
>>
>>     static{
>>         try{
>>
>>             System.setProperty("java.rmi.server.useCodebaseOnly",
"true");
>>         } catch(Exception e){
>>             e.printStackTrace();
>>             logger.error(e);
>>         }
>>
>>     }
>>     /**
>>      *
>>      */
>>     private RepoClient(){}
>>
>>     /**
>>      *
>>      */
>>     public static void connectRMI() {
>>
>>
>>         try {
>>
>>             r =
>>                     new
>> org.apache.jackrabbit.rmi.client.ClientRepositoryFactory().getRepository(
>>                             rmiURI);
>>             if ( null!=r ){
>>
>>                 s = r.login(new javax.jcr.SimpleCredentials(
>>                         "username", "password".toCharArray()));
>>
>>                 logger.info("JCR SESSION BOUNDED:   " +
>> s.getRootNode().toString());
>>                 //RepoTest.dump(s.getRootNode());
>>
>>             }
>>
>>
>>         } catch (NoClassDefFoundError e) {
>>             logger.error(e);
>>         } catch (Exception e) {
>>             logger.error(e);
>>         }
>>    }
>>
>>
>>     /**
>>      *
>>      */
>>     public static final void shutdownTest(){
>>
>>  
>> ((org.apache.jackrabbit.core.RepositoryImpl)s.getRepository()).shutdo
>> w
>> n();
>>
>>
>>     }
>>
>>
>>     /**
>>      *
>>      */
>>     public static final void addBinaryTest(){
>>         java.io.File f =
>>                 new java.io.File("C:/mp3/u2-jesus.nzb");
>>         try {
>>
>>             com.idc.util.FSImport.importFile(s.getRootNode(), f);
>>
>>             s.save();
>>             logger.debug("ADDED CONTENT.");
>>         } catch (javax.jcr.RepositoryException e) {
>>             e.printStackTrace();
>>             logger.error(e);
>>         } catch (java.io.IOException e) {
>>             e.printStackTrace();
>>             logger.error(e);
>>         }
>>     }
>>
>>
>>
>>     /**
>>      *
>>      * @param args
>>      */
>>     public static final void main(String args[]){
>>
>>         RepoClient.connectRMI();
>>         RepoClient.addNodeTest();
>>
>>     }
>>
>> }
>>
>> EXCEPTION:
>> ---------------------------------------------------------------------
>>
>> org.apache.jackrabbit.rmi.client.RemoteRepositoryException: error 
>> marshalling arguments; nested exception is:
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error: error marshalling arguments; nested exception is:
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error
>> 	at
>>
>>     
> org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.jav
> a:127)
>   
>> 	at
>>
>>     
> org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.jav
> a:162)
>   
>> 	at com.idc.util.FSImport.importFile(FSImport.java:90)
>> 	at com.idc.RepoClient.addBinaryTest(RepoClient.java:152)
>> 	at com.idc.RepoClient.main(RepoClient.java:174)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
>> j
>> ava:39
>> )
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
>> s
>> orImpl
>> .java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:585)
>> 	at
>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
>> Caused by: java.rmi.MarshalException: error marshalling arguments; 
>> nested exception is:
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error
>> 	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
>> 	at
>> org.apache.jackrabbit.rmi.server.ServerNode_Stub.setProperty(Unknown
>>     
> Source)
>   
>> 	at
>>
>>     
> org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.jav
> a:123)
>   
>> 	... 9 more
>> Caused by: java.net.SocketException: Software caused connection abort:
>> socket write error
>> 	at java.net.SocketOutputStream.socketWrite0(Native Method)
>> 	at
>> java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
>> 	at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
>> 	at
>> java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
>> 	at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
>> 	at
>> java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputSt
>> r
>> eam.ja
>> va:1676)
>> 	at
>> java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Obj
>> e
>> ctOutp
>> utStream.java:1585)
>> 	at
>>
>>     
> java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java
> :1395)
>   
>> 	at
>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:294)
>> 	at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:258)
>> 	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:117)
>> 	... 11 more
>> java.rmi.MarshalException: error marshalling arguments; nested 
>> exception
>>     
> is:
>   
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error
>> 	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
>> 	at
>> org.apache.jackrabbit.rmi.server.ServerNode_Stub.setProperty(Unknown
>>     
> Source)
>   
>> 	at
>>
>>     
> org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.jav
> a:123)
>   
>> 	at
>>
>>     
> org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.jav
> a:162)
>   
>> 	at com.idc.util.FSImport.importFile(FSImport.java:90)
>> 	at com.idc.RepoClient.addBinaryTest(RepoClient.java:152)
>> 	at com.idc.RepoClient.main(RepoClient.java:174)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
>> j
>> ava:39
>> )
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
>> s
>> orImpl
>> .java:25)
>> 	at java.lang.reflect.Method.invoke(Method.java:585)
>> 	at
>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
>> Caused by: java.net.SocketException: Software caused connection abort:
>> socket write error
>> 	at java.net.SocketOutputStream.socketWrite0(Native Method)
>> 	at
>> java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
>> 	at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
>> 	at
>> java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
>> 	at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
>> 	at
>> java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputSt
>> r
>> eam.ja
>> va:1676)
>> 	at
>> java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Obj
>> e
>> ctOutp
>> utStream.java:1585)
>> 	at
>>
>>     
> java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java
> :1395)
>   
>> 	at
>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:294)
>> 	at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:258)
>> 	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:117)
>> 	... 11 more
>> 2005-12-13 09:57:23,622 [ERROR] [main]   (RepoClient.java:158)
>> org.apache.jackrabbit.rmi.client.RemoteRepositoryException: error 
>> marshalling arguments; nested exception is:
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error: error marshalling arguments; nested exception is:
>> 	java.net.SocketException: Software caused connection abort: socket 
>> write error
>>
>>
>>
>>
>>
>> Duke K. Fong
>> Integrated Data Corporation
>> dfong@idc-global.com
>> 310-367-8412
>> 310-815-2800 ext. 215
>> http://www.idc-global.com
>>  
>>
>> -----Original Message-----
>> From: Felix Meschberger [mailto:Felix.Meschberger@day.com]
>> Sent: Tuesday, December 13, 2005 2:09 AM
>> To: jackrabbit-dev@incubator.apache.org
>> Subject: Re: [jira] Erledigt: (JCR-291) jcr-server-webapp: RMI 
>> Registration unstable
>>
>> Hi Duke,
>>
>> Duke Fong schrieb:
>>   
>>     
>>> Hello all.
>>>
>>> I've been trying to work with the Jackrabbit JCR in Server/RMI mode.  
>>> Read only and simple Value object insertions work fine.
>>>
>>> However, when I attempt to insert a file object (InputStream) via a 
>>> JCR client to a JCR Server via RMI, I get a socket exception.
>>>   
>>>     
>>>       
>> Do you have sample code to reproduce and a stack trace at hand, so 
>> that we could find out, where the problem might be ?
>>   
>>     
>>> Has anyone successfully performed this on the JCR Server?  If so, I 
>>> would love to share the experiences and get any input on the concept.
>>>   
>>>     
>>>       
>> I do not have any problems doing read and write from and to the 
>> server over RMI.
>>
>> Regards,
>> Felix
>>
>>   
>>     
>
>   


Mime
View raw message