8 Replies Latest reply: Nov 15, 2011 10:51 AM by Jonathan Fields RSS

problems with modeshape-rest

Jonathan Fields Novice

I am having problems creating a node using modeshape-rest, but do not understand what I am doing wrong. I'm using Modeshape 2.6.0 and the JBoss 6 AS kit and the disk connector. Here's the root of the repository:

 

$ wget -O - --user=admin --password=admin http://localhost:8080/modeshape-rest/repository/default/items

 

{"properties":{"jcr:primaryType":"mode:root","jcr:uuid":"fd129c12-81a8-42ed-aa4b-820dba49e6f0"},"children":["node1","jcr:system"]}

 

If I do this (copied almost verbatim from the ref guide):

 

$ wget -O - --user=admin --password=admin --post-file=node.json http://localhost:8080/modeshape-rest/repository/default/items/newNode

 

where node.json contains:

 

{

        "properties": {

                "jcr:primaryType": "nt:unstructured",

                "jcr:mixinTypes": "mix:referenceable",

                "someProperty": "foo"

        },

        "children": {

                "newChildNode": {

                        "properties": {"jcr:primaryType": "nt:unstructured"}

                }

        }

}

 

Then I get:

 

Resolving localhost... 127.0.0.1

Connecting to localhost|127.0.0.1|:8080... connected.

HTTP request sent, awaiting response... 401 Unauthorized

Reusing existing connection to localhost:8080.

HTTP request sent, awaiting response... 404 Not Found

2011-11-14 00:04:19 ERROR 404: Not Found.

 

I looked at the code and this suggests that it's not finding the parent of the new node (in this case the root).

 

Am I doing something wrong or is this a bug?

  • 1. Re: problems with modeshape-rest
    Randall Hauch Master

    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
    Jonathan Fields Novice

    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
    Randall Hauch Master

    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
    Jonathan Fields Novice

    That fixed it. Kind of a misleading error, but regardless, works as expected now. Thanks for the help.

  • 5. Re: problems with modeshape-rest
    Randall Hauch Master

    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
    Jonathan Fields Novice

    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
    Randall Hauch Master

    Yes, it'd be great to have a JIRA for your suggestion. Thanks.

  • 8. Re: problems with modeshape-rest
    Jonathan Fields Novice

    MODE-1307 created. Thanks.