You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Paulo Sergio <pa...@gmail.com> on 2008/06/20 20:31:22 UTC

Jackrabit and webdav

Hi everyone,
i'm new to Jackrabit and jcr in general, and i'm playing a bit with it and
i'm already amazed about what it can do :).
Anyway,  currently i'm able to mount the repository as a webdav folder and
copy/paste files from/to it, now i would like to build  a simpe software to
upload files to it, using this code :
 Node root = session.getRootNode();
            File file = new File("/home/sergio/teste.log");
            Node hello = root.addNode("hello");
            Node world = hello.addNode("world");
            world.setProperty("file", new FileInputStream(file));
            session.save();
            // Retrieve content
            Node node = root.getNode("hello/world");
            System.out.println(node.getPath());
            System.out.println(node.getProperty("file").getString());

i was able to store and retreive the file but i can't see it in the webdav
folder...
am i doing something wrong? or the repositories are in fact diferent due to
content ? (i just create one repository named teste but in order to mount it
i use: "http://localhost:8080/jackrabbit-webapp-1.4/repository/default" )

thanks in advance,
paulo f.

Re: Jackrabit and webdav

Posted by Alexander Klimetschek <ak...@day.com>.
On Sat, Jun 21, 2008 at 6:31 PM, Paulo Sergio <pa...@gmail.com> wrote:
> now i have one extra question: what is the advantage of using jackrabbit in
> tomcat? (apart from integration with a webapplication) does it have better
> performance?

No, there is no performance difference. The integration into
webapplications is the major use case for Jackrabbit, because it frees
you from having to maintain a database and the hierarchical data model
fits very well into webapps with hierarchical URLs (CMS for example).

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Jackrabit and webdav

Posted by Paulo Sergio <pa...@gmail.com>.
Hi,
Thanks a lot guys!
yes it's really easy indeed, it's now working with tomcat, saving files
remotely :)
now i have one extra question: what is the advantage of using jackrabbit in
tomcat? (apart from integration with a webapplication) does it have better
performance?

cheers,
paulo f.
On Sat, Jun 21, 2008 at 1:59 PM, Markus <ca...@gmx.net> wrote:

> Sorry, I forgot the probably most obvious possibility:
>
> 3. Accessing the repository with RMI (needs jackrabbit-jcr-rmi in client
> classpath):
>
> With running tomcat try the following code in your application (running on
> the same machine as the tomcat server):
>
> package test;
>
> import org.apache.jackrabbit.rmi.repository.RMIRemoteRepository;
>
> import javax.jcr.*;
>
> public class RMITest {
>    public static void main(String[] args) throws RepositoryException {
>        Repository repository = new
> RMIRemoteRepository("//localhost/jackrabbit.repository");
>        Session session = repository.login(new SimpleCredentials("admin",
> "admin".toCharArray()));
>
>        NodeIterator nodeIterator = session.getRootNode().getNodes();
>        while(nodeIterator.hasNext()) {
>            System.out.println(nodeIterator.nextNode().getName());
>        }
>
>        session.logout();
>    }
> }
>
> Regards,
> Markus
>
> -----Original Message-----
> From: Markus [mailto:caleb7@gmx.net]
> Sent: Saturday, June 21, 2008 2:44 PM
> To: users@jackrabbit.apache.org
> Subject: RE: Jackrabit and webdav
>
> Hi Paulo,
>
> I think there are two approaches for a simple access to the repository
> running in your default Jackrabbit-Tomcat installation:
>
> 1. Access the repository over the TransientRepository class from your
> client
> application:
> - String configLocation = <Path to config - usually
> [tomcat]\bin\jackrabbit\repository.xml>;
> - String repositoryLocation = <Path to config - usually
> [tomcat]\bin\jackrabbit>;
> - Repository repository = new TransientRepository(configLocation,
> repositoryLocation);
> - Session session = repository.login("admin", "admin");
>
> Please note, that with this approach you can access the repository only
> with
> either your client OR the web application. Which means, tomcat must not be
> running while you access it with your application.
>
> 2. Access the repository over JNDI within another webapplication:
> - This needs a little extra Tomcat configuration and is briefly described
> in
> http://localhost:8080/jackrabbit-webapp-1.4/local.jsp
>
> Regards,
> Markus
>
>
> -----Original Message-----
> From: Paulo Sergio [mailto:pauloslf@gmail.com]
> Sent: Saturday, June 21, 2008 2:13 PM
> To: users@jackrabbit.apache.org
> Subject: Re: Jackrabit and webdav
>
> Hi guys,
> thanks for all the answers,
> i gues i have a problem i have to fix before these one, as i said i pretty
> new to jcr and i seem to have missed a point.
> when i run the client it creates a new repository and does not use the one
> running on tomcat (i assumes it was using localhost as default)
>
> so first problem is making the client program "talk " with the repository
> in
> tomcat..  any directions in order to achive this?
>
>
> thanks for helping..
>
> paulo f.
> On Sat, Jun 21, 2008 at 10:09 AM, Bertrand Delacretaz <
> bdelacretaz@apache.org> wrote:
>
> > Hi Paulo,
> >
> > On Sat, Jun 21, 2008 at 9:49 AM, Paulo Sergio <pa...@gmail.com>
> wrote:
> > > ...is there any place where i can get examples of that code?...
> >
> > There's an example in Sling's Loader class [1], look at the createFile()
> > method.
> >
> > (there are also examples in Jackrabbit but I'm less familiar with that
> > code).
> >
> > -Bertrand
> >
> > [1]
> >
>
> http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/s
> rc/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java<http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java>
> >
>
>

RE: Jackrabit and webdav

Posted by Markus <ca...@gmx.net>.
Sorry, I forgot the probably most obvious possibility:

3. Accessing the repository with RMI (needs jackrabbit-jcr-rmi in client
classpath):

With running tomcat try the following code in your application (running on
the same machine as the tomcat server):

package test;

import org.apache.jackrabbit.rmi.repository.RMIRemoteRepository;

import javax.jcr.*;

public class RMITest {
    public static void main(String[] args) throws RepositoryException {
        Repository repository = new
RMIRemoteRepository("//localhost/jackrabbit.repository");
        Session session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));

        NodeIterator nodeIterator = session.getRootNode().getNodes();
        while(nodeIterator.hasNext()) {
            System.out.println(nodeIterator.nextNode().getName());
        }
        
        session.logout();
    }
}

Regards,
Markus

-----Original Message-----
From: Markus [mailto:caleb7@gmx.net] 
Sent: Saturday, June 21, 2008 2:44 PM
To: users@jackrabbit.apache.org
Subject: RE: Jackrabit and webdav

Hi Paulo,

I think there are two approaches for a simple access to the repository
running in your default Jackrabbit-Tomcat installation:

1. Access the repository over the TransientRepository class from your client
application:
- String configLocation = <Path to config - usually
[tomcat]\bin\jackrabbit\repository.xml>;
- String repositoryLocation = <Path to config - usually
[tomcat]\bin\jackrabbit>;
- Repository repository = new TransientRepository(configLocation,
repositoryLocation);
- Session session = repository.login("admin", "admin");

Please note, that with this approach you can access the repository only with
either your client OR the web application. Which means, tomcat must not be
running while you access it with your application.

2. Access the repository over JNDI within another webapplication:
- This needs a little extra Tomcat configuration and is briefly described in
http://localhost:8080/jackrabbit-webapp-1.4/local.jsp

Regards,
Markus


-----Original Message-----
From: Paulo Sergio [mailto:pauloslf@gmail.com] 
Sent: Saturday, June 21, 2008 2:13 PM
To: users@jackrabbit.apache.org
Subject: Re: Jackrabit and webdav

Hi guys,
thanks for all the answers,
i gues i have a problem i have to fix before these one, as i said i pretty
new to jcr and i seem to have missed a point.
when i run the client it creates a new repository and does not use the one
running on tomcat (i assumes it was using localhost as default)

so first problem is making the client program "talk " with the repository in
tomcat..  any directions in order to achive this?


thanks for helping..

paulo f.
On Sat, Jun 21, 2008 at 10:09 AM, Bertrand Delacretaz <
bdelacretaz@apache.org> wrote:

> Hi Paulo,
>
> On Sat, Jun 21, 2008 at 9:49 AM, Paulo Sergio <pa...@gmail.com> wrote:
> > ...is there any place where i can get examples of that code?...
>
> There's an example in Sling's Loader class [1], look at the createFile()
> method.
>
> (there are also examples in Jackrabbit but I'm less familiar with that
> code).
>
> -Bertrand
>
> [1]
>
http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/s
rc/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
>


RE: Jackrabit and webdav

Posted by Markus <ca...@gmx.net>.
Hi Paulo,

I think there are two approaches for a simple access to the repository
running in your default Jackrabbit-Tomcat installation:

1. Access the repository over the TransientRepository class from your client
application:
- String configLocation = <Path to config - usually
[tomcat]\bin\jackrabbit\repository.xml>;
- String repositoryLocation = <Path to config - usually
[tomcat]\bin\jackrabbit>;
- Repository repository = new TransientRepository(configLocation,
repositoryLocation);
- Session session = repository.login("admin", "admin");

Please note, that with this approach you can access the repository only with
either your client OR the web application. Which means, tomcat must not be
running while you access it with your application.

2. Access the repository over JNDI within another webapplication:
- This needs a little extra Tomcat configuration and is briefly described in
http://localhost:8080/jackrabbit-webapp-1.4/local.jsp

Regards,
Markus


-----Original Message-----
From: Paulo Sergio [mailto:pauloslf@gmail.com] 
Sent: Saturday, June 21, 2008 2:13 PM
To: users@jackrabbit.apache.org
Subject: Re: Jackrabit and webdav

Hi guys,
thanks for all the answers,
i gues i have a problem i have to fix before these one, as i said i pretty
new to jcr and i seem to have missed a point.
when i run the client it creates a new repository and does not use the one
running on tomcat (i assumes it was using localhost as default)

so first problem is making the client program "talk " with the repository in
tomcat..  any directions in order to achive this?


thanks for helping..

paulo f.
On Sat, Jun 21, 2008 at 10:09 AM, Bertrand Delacretaz <
bdelacretaz@apache.org> wrote:

> Hi Paulo,
>
> On Sat, Jun 21, 2008 at 9:49 AM, Paulo Sergio <pa...@gmail.com> wrote:
> > ...is there any place where i can get examples of that code?...
>
> There's an example in Sling's Loader class [1], look at the createFile()
> method.
>
> (there are also examples in Jackrabbit but I'm less familiar with that
> code).
>
> -Bertrand
>
> [1]
>
http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/s
rc/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
>


Re: Jackrabit and webdav

Posted by Paulo Sergio <pa...@gmail.com>.
Hi guys,
thanks for all the answers,
i gues i have a problem i have to fix before these one, as i said i pretty
new to jcr and i seem to have missed a point.
when i run the client it creates a new repository and does not use the one
running on tomcat (i assumes it was using localhost as default)

so first problem is making the client program "talk " with the repository in
tomcat..  any directions in order to achive this?


thanks for helping..

paulo f.
On Sat, Jun 21, 2008 at 10:09 AM, Bertrand Delacretaz <
bdelacretaz@apache.org> wrote:

> Hi Paulo,
>
> On Sat, Jun 21, 2008 at 9:49 AM, Paulo Sergio <pa...@gmail.com> wrote:
> > ...is there any place where i can get examples of that code?...
>
> There's an example in Sling's Loader class [1], look at the createFile()
> method.
>
> (there are also examples in Jackrabbit but I'm less familiar with that
> code).
>
> -Bertrand
>
> [1]
> http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
>

Re: Jackrabit and webdav

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Paulo,

On Sat, Jun 21, 2008 at 9:49 AM, Paulo Sergio <pa...@gmail.com> wrote:
> ...is there any place where i can get examples of that code?...

There's an example in Sling's Loader class [1], look at the createFile() method.

(there are also examples in Jackrabbit but I'm less familiar with that code).

-Bertrand

[1] http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java

Re: Jackrabit and webdav

Posted by Florian Holeczek <fl...@holeczek.de>.
Hi Paulo,

it's easy... just assign the primary node types as follows:
* nt:folder to nodes in your hierarchy, which would correspond to
  folders if you stored the data in your file system
* nt:file to nodes in your hierarchy, which would correspond to files
  in your file system

Regards,
 Florian

Ursprüngliche Nachricht vom 21.06.2008 um 09:49:
> Hi Alexander,
> is there any place where i can get examples of that code? i'm  reading the
> specs now, but i think we lack some good examples of the client side, or i'm
> probably looking in the wrong place.

> thanks a lot for helping,
> paulo f.


Re: Jackrabit and webdav

Posted by Paulo Sergio <pa...@gmail.com>.
Hi Alexander,
is there any place where i can get examples of that code? i'm  reading the
specs now, but i think we lack some good examples of the client side, or i'm
probably looking in the wrong place.

thanks a lot for helping,
paulo f.

On Fri, Jun 20, 2008 at 9:13 PM, Alexander Klimetschek <ak...@day.com>
wrote:

> Hi Sergio,
>
> you have to use a specific node structure and node types for storing
> files in the repository. The JCR specification [1] defines the
> standard types "nt:folder" and "nt:file" for this use case (see
> section 6.7.22.5 nt:hierarchyNode and ff.). The jackrabbit WebDAV
> server uses those to map files and folders naturally.
>
> Regards,
> Alex
>
> [1] http://jcp.org/en/jsr/detail?id=170
>
> On Fri, Jun 20, 2008 at 8:31 PM, Paulo Sergio <pa...@gmail.com> wrote:
> > Hi everyone,
> > i'm new to Jackrabit and jcr in general, and i'm playing a bit with it
> and
> > i'm already amazed about what it can do :).
> > Anyway,  currently i'm able to mount the repository as a webdav folder
> and
> > copy/paste files from/to it, now i would like to build  a simpe software
> to
> > upload files to it, using this code :
> >  Node root = session.getRootNode();
> >            File file = new File("/home/sergio/teste.log");
> >            Node hello = root.addNode("hello");
> >            Node world = hello.addNode("world");
> >            world.setProperty("file", new FileInputStream(file));
> >            session.save();
> >            // Retrieve content
> >            Node node = root.getNode("hello/world");
> >            System.out.println(node.getPath());
> >            System.out.println(node.getProperty("file").getString());
> >
> > i was able to store and retreive the file but i can't see it in the
> webdav
> > folder...
> > am i doing something wrong? or the repositories are in fact diferent due
> to
> > content ? (i just create one repository named teste but in order to mount
> it
> > i use: "http://localhost:8080/jackrabbit-webapp-1.4/repository/default"
> )
> >
> > thanks in advance,
> > paulo f.
> >
>
>
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Re: Jackrabit and webdav

Posted by Alexander Klimetschek <ak...@day.com>.
Hi Sergio,

you have to use a specific node structure and node types for storing
files in the repository. The JCR specification [1] defines the
standard types "nt:folder" and "nt:file" for this use case (see
section 6.7.22.5 nt:hierarchyNode and ff.). The jackrabbit WebDAV
server uses those to map files and folders naturally.

Regards,
Alex

[1] http://jcp.org/en/jsr/detail?id=170

On Fri, Jun 20, 2008 at 8:31 PM, Paulo Sergio <pa...@gmail.com> wrote:
> Hi everyone,
> i'm new to Jackrabit and jcr in general, and i'm playing a bit with it and
> i'm already amazed about what it can do :).
> Anyway,  currently i'm able to mount the repository as a webdav folder and
> copy/paste files from/to it, now i would like to build  a simpe software to
> upload files to it, using this code :
>  Node root = session.getRootNode();
>            File file = new File("/home/sergio/teste.log");
>            Node hello = root.addNode("hello");
>            Node world = hello.addNode("world");
>            world.setProperty("file", new FileInputStream(file));
>            session.save();
>            // Retrieve content
>            Node node = root.getNode("hello/world");
>            System.out.println(node.getPath());
>            System.out.println(node.getProperty("file").getString());
>
> i was able to store and retreive the file but i can't see it in the webdav
> folder...
> am i doing something wrong? or the repositories are in fact diferent due to
> content ? (i just create one repository named teste but in order to mount it
> i use: "http://localhost:8080/jackrabbit-webapp-1.4/repository/default" )
>
> thanks in advance,
> paulo f.
>



-- 
Alexander Klimetschek
alexander.klimetschek@day.com