It is an Oak application and yes, it does manipulate the documents directly 
without making REST calls to Sling. Much of it taken from 
http://jackrabbit.apache.org/oak/docs/construct.html , here is what the code 
may look like:

// REST service createChildFolder running on localhost:8040
public void createChildFolder(String parentPath, String childName) {
            DB database = new MongoClient("127.0.0.1", 27017).getDB("sling");
            DocumentNodeStore store = new 
DocumentMK.Builder().setMongoDB(database).getNodeStore();
            Repository repo = new Jcr(new Oak(store)).createRepository();
            SimpleCredentials creds = new SimpleCredentials("admin", 
"admin".toCharArray());
            Session session = (javax.jcr.Session) repository.login(creds);
            Node parent = session.getRootNode().getNode(parentPath);
            Node child = parent.addNode(childName, "sling:Folder");
            session.save();
            session.logout();
            store.dispose();
}

// Test case
public void test1() {
            //Make POST request to createChildFolder using HttpURLConnection
            //Get back JSON response by making GET request to Sling at 
localhost:8080 (which is persisted by MongoDB at 127.0.0.1:27017) using 
HttpURLConnection
            //Compare resulting JSON from GET request with one that has child 
node at parent
}

Thanks,
H

> From: jus...@justinedelson.com
> Date: Tue, 1 Dec 2015 19:43:10 +0000
> Subject: Re: Sling retrieving out-of-date data
> To: users@sling.apache.org
> 
> Are you saying that you have a non-Oak application which connects directly
> to MongoDB and manipulates the documents?
> 
> On Tue, Dec 1, 2015 at 2:22 PM H K <redflagba...@hotmail.com> wrote:
> 
> > Hi,
> >
> > Sure. In pseudocode, here it is:
> >
> > 1. Have Sling standalone running and have application that provides REST
> > service createChildFolder (for example sake). Application connects to
> > repository by using DocumentMK, as in the link from the OP post.
> >
> > 2. Call createChildFolder("pathToParent", "childName").
> >
> > 3. Make GET request to http://localhost:8080/pathToParent.infinity.json
> >
> > 4. Inspecting the JSON Object, expect there to be a child node in parent
> > node but none are there. Test failed.
> >
> > However, if I let the thread sleep for 2 seconds after step 2, child
> > exists in the JSON as wanted.
> >
> > Thanks,
> > H
> >
> > > From: apa...@oliverlietz.de
> > > To: users@sling.apache.org
> > > Subject: Re: Sling retrieving out-of-date data
> > > Date: Tue, 1 Dec 2015 19:49:20 +0100
> > >
> > > On Tuesday 01 December 2015 11:37:42 H K wrote:
> > > > Hi,
> > >
> > > Hi,
> > >
> > > > I'm currently using the Sling 8 standalone and it's connected to a
> > MongoDB
> > > > database. I've got an application which also connects to the same
> > MongoDB
> > > > database and writes/reads from it. The connection is done using
> > DocumentMK,
> > > > following the instructions at
> > > > https://jackrabbit.apache.org/oak/docs/construct.html
> > > >
> > > > My problem is that when I write data to the repository through my
> > > > application, Sling does not seem to get it fast enough, which may be
> > > > because it is caching or because it only periodically checks to see if
> > the
> > > > data it has is up-to-date or not. For instance in my unit tests that
> > test
> > > > some of my REST services, I'm creating a child node somewhere and then
> > > > doing a GET request to Sling to get back a JSON representing the
> > updated
> > > > parent. However, the returned result does not have the child in it. I
> > know
> > > > the changes are made because if I delay for two seconds before
> > submitting
> > > > the GET request, all works fine.
> > > >
> > > > This was not a problem using Sling 7 with Jackrabbit (instead of Oak)
> > and
> > > > connecting over RMI.
> > > >
> > > > Can someone provide some insight and/or a solution? Thanks!
> > >
> > > can you provide a minimal test case which resembles what you are doing?
> > >
> > > Regards,
> > > O.
> > >
> >
                                          

Reply via email to