Hi all.
Short version of my question: Can anyone point me to an example of
adding object of a custom class to a page via the ReSTful API?
And now for the long version of my question:
I can successfully create a page using REST, but can't add an object.
Here is the problem step by step.
1) Using this XML definition in a file called AlinaPage.xml:
<?xml version="1.0" encoding="UTF-8"?>
<xwiki:page xmlns:xwiki="http://www.xwiki.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xwiki.org C:\Users\mwallace\
Desktop\xwiki_rest_model.xsd">
<xwiki:link
href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Alina+Frey/objects/XWiki.PersonClass/0"
rel="http://www.xwiki.org/rel/o
bject"></xwiki:link>
<xwiki:id/>
<xwiki:fullName/>
<xwiki:wiki/>
<xwiki:space>Main</xwiki:space>
<xwiki:name>Alina Frey</xwiki:name>
<xwiki:title/>
<xwiki:parent/>
<xwiki:parentId/>
<xwiki:xwikiRelativeUrl/>
<xwiki:xwikiAbsoluteUrl/>
<xwiki:translations/>
<xwiki:syntax/>
<xwiki:language/>
<xwiki:version/>
<xwiki:majorVersion>1</xwiki:majorVersion>
<xwiki:minorVersion>0</xwiki:minorVersion>
<xwiki:created>2011-07-02T12:32:00-04:00</xwiki:created>
<xwiki:creator>XWiki.mwallace</xwiki:creator>
<xwiki:modified>2011-07-02T12:32:00-04:00</xwiki:modified>
<xwiki:modifier/>
<xwiki:content>{{include
document="XWiki.PersonSheet"/}}</xwiki:content>
</xwiki:page>
2) I do the following command, which adds the page successfully:
C> curl -u mwallace:password -X PUT --data-binary "(a)AlinaPage.xml" -H
"Content-Type: application/xml"
http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Alina+Frey
3) The resulting page from a HTTP GET is:
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://www.xwiki.org">
<link href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"
rel="http://www.xwiki.org/rel/space"/>
<link
href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Alina%20Frey/history"
rel="http://www.xwiki.org/rel/history"/>
<link href="http://localhost:8080/xwiki/rest/syntaxes"
rel="http://www.xwiki.org/rel/syntaxes"/>
<link
href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Alina+Frey"
rel="self"/>
<link
href="http://localhost:8080/xwiki/rest/wikis/xwiki/classes/Main.Alina%20Frey"
rel="http://www.xwiki.org/rel/class"/>
<id>xwiki:Main.Alina Frey</id>
<fullName>Main.Alina Frey</fullName>
<wiki>xwiki</wiki>
<space>Main</space>
<name>Alina Frey</name>
<title>Alina Frey</title>
<parent/>
<parentId/>
<xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/Alina+Frey</xwikiRelativeUrl>
<xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/Alina+Frey</xwikiAbsoluteUrl>
<translations/>
<syntax>xwiki/2.0</syntax>
<language/>
<version>4.1</version>
<majorVersion>4</majorVersion>
<minorVersion>1</minorVersion>
<created>2011-07-02T12:45:12-04:00</created>
<creator>XWiki.mwallace</creator>
<modified>2011-07-02T21:33:48-04:00</modified>
<modifier>XWiki.mwallace</modifier>
<content>{{include document="XWiki.PersonSheet"/}}</content>
</page>
4) But then, using this definition of an object in file AlenaObject.xml:
<?xml version="1.0" encoding="UTF-8"?>
<xwiki:object xmlns:xwiki="http://www.xwiki.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xwiki.org C:\Users\mwallac
e\Desktop\xwiki_rest_model.xsd">
<xwiki:id/>
<xwiki:guid/>
<xwiki:pageId>Main.Alina Frey</xwiki:pageId>
<xwiki:wiki/>
<xwiki:space>Main</xwiki:space>
<xwiki:pageName>Alina Frey</xwiki:pageName>
<xwiki:className>XWiki.PersonClass</xwiki:className>
<xwiki:number>0</xwiki:number>
<xwiki:headline/>
<xwiki:property name="_knows">
<xwiki:value>Main.Alena</xwiki:value>
</xwiki:property>
<xwiki:property name="_knows">
<xwiki:value>Main.Judi Wallace</xwiki:value>
</xwiki:property>
<xwiki:property name="name">
<xwiki:value>Alina Frey</xwiki:value>
</xwiki:property>
</xwiki:object>
5) I try the following command, which does NOT insert the object properly:
C> curl -u mwallace:password -X PUT --data-binary "(a)AlinaObject.xml" -H
"Content-Type: application/xml"
http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Alina+Frey/o…
6) Rather, I get this error message:
<html>
<head>
<title>Status page</title>
</head>
<body>
<h3>The server has not found anything matching the request
URI</h3><p>You can get technical details <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5…
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>
What am I doing wrong?
--
Mark Wallace
Principal Engineer, Semantic Applications
Modus Operandi, Melbourne, FL, USA