-
1. Re: problems with modeshape-rest
rhauch Nov 14, 2011 12:16 PM (in response to jonathandfields)You posted the two GET requests to read nodes, but can you share the POST request you used to create the node?
-
2. Re: problems with modeshape-rest
jonathandfields Nov 14, 2011 12:51 PM (in response to rhauch)The second wget command is the POST. The --post-file=node.json option causes the file node.json to be POSTed to http://localhost:8080/modeshape-rest/repository/default/items/newNode.
Here is a transcript using the curl command, which shows the HTTP request/response:
$ curl --user admin:admin -v -d @node.json http://localhost:8080/modeshape-rest/repository/default/items/newNode * About to connect() to localhost port 8080 * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 8080 * Server auth using Basic with user 'admin' > POST /modeshape-rest/repository/default/items/newNode HTTP/1.1 > Authorization: Basic YWRtaW46YWRtaW4= > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 > Host: localhost:8080 > Accept: */* > Content-Length: 216 > Content-Type: application/x-www-form-urlencoded > > { "properties": { "jcr:primaryType": "nt:unstructured", "jcr:mixinTypes": "mix:referenceable", "someProperty": "foo" }, "children": { "newChildNode": { "properties": {"jcr:primaryType": "nt:unstructured"} } }}HTTP/1.1 404 Not Found < Server: Apache-Coyote/1.1 < Content-Length: 156 < Date: Mon, 14 Nov 2011 17:48:32 GMT Connection #0 to host localhost left intact * Closing connection #0 Could not find resource for relative : /repository/default/items/newNode of full path: http://localhost:8080/modeshape-rest/repository/default/items/newNode
Again, this is POSTing the contents of the file node.json
{ "properties": { "jcr:primaryType": "nt:unstructured", "jcr:mixinTypes": "mix:referenceable", "someProperty": "foo" }, "children": { "newChildNode": { "properties": {"jcr:primaryType": "nt:unstructured"} } } }
I cannot figure out what I am doing wrong.
-
3. Re: problems with modeshape-rest
rhauch Nov 14, 2011 1:55 PM (in response to jonathandfields)The log seems to say that your POST request contains this content type:
Jonathan Fields wrote:
> Content-Type: application/x-www-form-urlencoded
Our REST handler is expecting a content type "application/json". IIRC, with curl you'd need to supply another command-line argument:
--header "Content-Type: application/json"
Hope that helps.
-
4. Re: problems with modeshape-rest
jonathandfields Nov 15, 2011 9:59 AM (in response to rhauch)That fixed it. Kind of a misleading error, but regardless, works as expected now. Thanks for the help.
-
5. Re: problems with modeshape-rest
rhauch Nov 15, 2011 10:08 AM (in response to jonathandfields)Would you want to create a JIRA to check the mime type and have a better error message? Basically, we'd have to have another method to handle posts with other mime types.
-
6. Re: problems with modeshape-rest
jonathandfields Nov 15, 2011 10:30 AM (in response to rhauch)I think it would be sufficient, if not better, to emphasize the need for the Content-type header in the ref guide. That would help avoid the error in the first place. It is stated that the content must be JSON, but the need for the header is somewhat implicit.
For example, maybe this:
POST http://www.example.com/resources/modeshape%3arepository/default/items/newNode Content-Type: application/json { "properties": { "jcr:primaryType": "nt:unstructured", "jcr:mixinTypes": "mix:referenceable", "someProperty": "foo" }, "children": { "newChildNode": { "properties": {"jcr:primaryType": "nt:unstructured"} } } }
and/or including an actual wget/curl command:
curl --user admin:admin --header "Content-Type: application/json" -d @node.json -v http://localhost:8080/modeshape-rest/repository/default/items/newNode
I'll be quite happy with this. Let me know if you want me to file a JIRA.
-
7. Re: problems with modeshape-rest
rhauch Nov 15, 2011 10:34 AM (in response to jonathandfields)Yes, it'd be great to have a JIRA for your suggestion. Thanks.
-
8. Re: problems with modeshape-rest
jonathandfields Nov 15, 2011 10:51 AM (in response to rhauch)MODE-1307 created. Thanks.