-
15. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
rhauch Aug 23, 2012 11:48 AM (in response to asilchenko)Take a look at our older documentation, which may give you a bit more background. Obviously our new documentation isn't clear enough.
Assuming you want to work with the "default" workspace of the "sample" repository, and your server is running locally on port 8080, then you can start creating nodes very easily as follows. There is always a root node (at the path "/"), you can get this by issuing a GET request using the "items" resources:
POST http://localhost:8080/modeshape-rest/sample/default/items
Content-Type: application/json
This will return something like the following:
{
"properties" : {
"jcr:primaryType" : "mode:root",
"jcr:uuid" : "97d7e2ef-996e-4d99-8ec2-dc623e6c2239"
},
"children" [
"jcr:system"
]
}
Note that unless you created anything alreayd, there will be only one child (the "jcr:system" node). You can get that node by issuing a GET to http://localhost:8080/modeshape-rest/sample/default/items/jcr:system (notice how just the end of the URL changed?)
You can only create a new node under an existing node, so you can create a node named "foo" under the root node with a primary type of "nt:unstructured", a property named "testProperty" with value "testValue", and a property named "multiValueProperty" with values "value1" and "value2" by issuing a POST request as follows:
POST http://localhost:8080/modeshape-rest/sample/default/items/newNode
Content-Type: application/json
"properties"
:{
"jcr:primaryType"
:
"nt:unstructured"
,
"testProperty"
:
"testValue"
,
"multiValuedProperty"
:[
"value1"
,
"value2"
]
}
This should return a representation of the newly-created node. You can even descendant nodes at the same time as you create a parent node. Here we issue a POST to create a node under the root with a different name:
POST http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Content-Type: application/json
"properties"
:{
"jcr:primaryType"
:
"nt:unstructured"
,
"otherProperty"
:
"otherValue"
,
},
"children"
:{
"childNode"
:{
"properties"
:{
"nestedProperty"
:
"nestedValue"
}
}
}
}
Again, this should return a representation of the newly-created node.
You can also update a node by issuing a PUT request with a JSON representation containing the properties that are to be changed. Here's one simple example:
PUT http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Content-Type: application/json
{
"otherProperty" : "newValue"
}
Of course, there are other possibilities, including updating properties on multiple nodes in a subgraph. See the documentation for help.
To delete a node, simply issue a DELETE request:
DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Hope this gets you started.
-
16. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
asilchenko Aug 23, 2012 11:43 AM (in response to rhauch)Thank you so much for your response and examples. First two exaples worked just fine and returned expcted response as you can see pasted below (I am using curl)
curl -u id:password http://localhost:8080/modeshape-rest/sample/default/items/jcr:system
{
"properties": {"jcr:primaryType": "mode:system"},
"children": [
"jcr:nodeTypes",
"jcr:versionStorage",
"mode:namespaces",
"mode:locks"
]
}
But I am getting error on the third example in your posting:
No repository named 'modeshape:repository' could be found in the ModeShape engine in JNDI at 'jcr'
Here is my curl command:
curl -u id:password -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{ "properties":{"jcr:primaryType":"nt:unstructured", "testProperty":"testValue", "multiValuedProperty":["value1", "value2"]}}' http://localhost:8080/modeshape-rest/modeshape%3arepository/default/items/newNode
Maybe I am missing things in my ModeShape setup? Thank you so much for all your time and help!
Best Regards,
Anna
-
17. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
rhauch Aug 23, 2012 11:48 AM (in response to asilchenko)Sorry, I used the wrong URLs for the example. Replace "modeshape%3arepository" with "sample" in the URLs. (I'll fix my previous post in a minute.)
In any case, look at the patterns of these operations. You'll have to adapt them to reflect your application and environment, so it's important to understand what each is doing.
-
18. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
asilchenko Aug 23, 2012 2:32 PM (in response to rhauch)Thank you for fixing the typo, I should have figured. Got all but delete examples working. Woohoo! Here are my curl commands and responses based on your post.
1.
Request:
curl -u id:password -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{ "properties":{"jcr:primaryType":"nt:unstructured", "testProperty":"testValue", "multiValuedProperty":["value1", "value2"]}}' http://localhost:8080/modeshape-rest/sample/default/items/newNode
Response:
{"properties":{"jcr:primaryType":"nt:unstructured","multiValuedProperty":["value1","value2"],"testProperty":"testValue"}}
2.
Request:
curl -u id:password -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{ "properties":{"jcr:primaryType":"nt:unstructured","otherProperty":"otherValue",},"children":{"childNode":{"properties":{"nestedProperty":"nestedValue"}}}}' http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Response:
{"properties":{"jcr:primaryType":"nt:unstructured","otherProperty":"otherValue"},"children":{"childNode":{"properties":{"jcr:primaryType":"nt:unstructured","nestedProperty":"nestedValue"}}}}
3.
Request:
curl -u id:password -H "Content-Type: application/json; charset=UTF-8" -X PUT -d '{"otherProperty" : "newValue"}' http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Response:
{"properties":{"jcr:primaryType":"nt:unstructured","otherProperty":"newValue"},"children":["childNode"]}
4.
Request:
curl -u id:password -H DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Response:
{
"properties": {
"jcr:primaryType": "nt:unstructured",
"otherProperty": "newValue"
},
"children": ["childNode"]
}
The last delete node command has executed and returned valid response but the node is still there. Hmmm... Not sure if I am missing anything in the command or somethign else is wrong? Thank you so much!
-
19. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
rhauch Aug 23, 2012 6:22 PM (in response to asilchenko)4.
Request:
curl -u id:password -H DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
I think that command is not correct - the "-H" flag reads the next token (e.g., "DELETE") as a header to pass to the server, which makes the command meaningless.
Try the following (without the "-H"):
curl -u id:password DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
-
20. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
asilchenko Aug 24, 2012 9:27 AM (in response to rhauch)1 of 1 people found this helpfulI got delete working after changing "-H" to "-X". So both curls pasted below worked for delete.
curl -u id:password -X DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
curl -u id:password -H "Content-Type: application/json; charset=UTF-8" -X DELETE http://localhost:8080/modeshape-rest/sample/default/items/secondNode
Thank you for all your time and help!