[xwiki-users] XWiki RESTful API: TAGS and unicode
Hello Fabio & friends, i tried to use curl and the RESTful API to 1) create a page: ok 2) upload a file/image: ok 3) create some TAGS to the page: ???? 1) and 2) is working, but 3 is not working. What is wrong in 3)? What about unicode/Umlaut in page-name, tag-name and upload-filename. I have some problems with öäü-German and øæå-Norwegian. I use Autohotkey and cURL in WindowsXP. Thank you folks... 1) curl.exe -v -S -u Admin:admin -X PUT -d @C:\1.xml -H Content-Type:application/xml %Server %/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page% 1.xml: --- <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <page xmlns="http://www.xwiki.org"> <title>Hello world</title> <content>This is a new page</content> </page> --- 2) curl.exe -v -S -u Admin:admin -T C:\%file% %Server %/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/attachments/% file% 3) curl.exe -v -S -u Admin:admin -X PUT -d @C:\2.xml -H Content-Type:application/xml %Server %/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/tags 2.xml: --- <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <tags xmlns="http://www.xwiki.org"> <tag>TestTag</tag> </tags> --- -- Volker Lapczynski [email protected] Rosendalsveien 3-B +47 - 92 62 02 48 N-1166 Oslo www.legeinfo.net - Norway - N59°51.573 E10°47.843
On 09/16/2010 10:24 PM, volker wrote:
Hello Fabio& friends,
i tried to use curl and the RESTful API to
1) create a page: ok 2) upload a file/image: ok 3) create some TAGS to the page: ????
1) and 2) is working, but 3 is not working. What is wrong in 3)?
What about unicode/Umlaut in page-name, tag-name and upload-filename. I have some problems with öäü-German and øæå-Norwegian.
Hi Volker, 3) doesn't work because the .../tags resource doesn't support PUT. At the beginning this resource was just meant to be a shortcut to list tags, not to modify them. But indeed it would be nice to allow the user to modify tags through this resource. You can open an improvement request on the JIRA for that. As a workaround you can manipulate the TagClass object to modify tags: curl -u "Admin:admin" -X PUT -H "Content-type: text/plain" --data-ascii "foo,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/objec... If the reply is a 404, this means that the TagClass object doesn't exist on the page. In this case you need to send an additional request to create the object: curl -u "Admin:admin" -X POST -H "Content-type: application/x-www-form-urlencoded" --data-ascii "className=TagClass&property#tags=foo,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/objec... Concerning the unicode/Umlaut problem what's exactly the issue? Hope this helps, Fabio
Hi Fabio! Thanks for reply. I am still working with the "creating TAG" problem. I am able to create a page and upload a file. I am not able to make a TAG with your code. I am editing the files with notepad in windows with UTF-8. Working with norwegian Windows XP, Autohotkey with unicode support and curl for windows. I tried: page = test-page222 ; ; ---make a page--- working with umlaut ;) curl.exe -u "Admin:admin" -X PUT -d "@C:\file.xml" -H "Content-Type: application/xml" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page% ; ; --- upload a file --- working with umlaut ;) curl.exe -u "Admin:admin" -T "C:\image.jpg" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/attach... ; ; --- create a TAG--- NOT WORKING ! curl.exe -u "Admin:admin" -X POST -H "Content-type: application/x-www-form-urlencoded" --data-ascii "className=TagClass&property#tags=foo,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... ; ; --- create a TAG--- WORKING but only without UMLAUT/Unicode/UTF-8 ;RunWait ..\bin\curl\curl.exe --trace-ascii "trace-tagggg.txt" -u "Admin:admin" -X POST --d "className=XWiki.TagClass&property#tags=%page%|test1|test2" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... What is wrong with my code? Regards Volker -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-RESTful-API-TAGS-and-unicode-tp55402... Sent from the XWiki- Users mailing list archive at Nabble.com.
On 10/01/2010 12:33 PM, Volker Lapczynski wrote:
Hi Fabio! Thanks for reply.
I am still working with the "creating TAG" problem. I am able to create a page and upload a file. I am not able to make a TAG with your code. I am editing the files with notepad in windows with UTF-8. Working with norwegian Windows XP, Autohotkey with unicode support and curl for windows.
I tried: page = test-page222 ;
; ---make a page--- working with umlaut ;) curl.exe -u "Admin:admin" -X PUT -d "@C:\file.xml" -H "Content-Type: application/xml" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page% ;
; --- upload a file --- working with umlaut ;) curl.exe -u "Admin:admin" -T "C:\image.jpg" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/attach... ;
; --- create a TAG--- NOT WORKING ! curl.exe -u "Admin:admin" -X POST -H "Content-type: application/x-www-form-urlencoded" --data-ascii "className=TagClass&property#tags=foo,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... ;
; --- create a TAG--- WORKING but only without UMLAUT/Unicode/UTF-8 ;RunWait ..\bin\curl\curl.exe --trace-ascii "trace-tagggg.txt" -u "Admin:admin" -X POST --d "className=XWiki.TagClass&property#tags=%page%|test1|test2" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object...
What is wrong with my code? Regards Volker
Apparently nothing. When you see "NOT WORKING" what is exactly not working? A "500 - Server rerror" reply? Tags not created correctly (i.e., with invalid characters) ? The second call to curl is functionally equivalent to the first (finally the -d parameter sends data as "application/x-www-form-urlencoded") so I really don't understand why the first is not working and the second one is. If you provide more information (e.g., the trace-tagggg.txt file) maybe I can help you better. -Fabio
Hello Fabio! I solved the TAG problem, but still fighting with Umlauts. TAGs solved: In Autohotkey environment i have to "escape" commas, they must be escaped as shown here: tags=foo`,bar ; --- create a TAG--- Working ;) curl.exe -u "Admin:admin" -X POST -H "Content-type: application/x-www-form-urlencoded" --data-ascii "className=TagClass&property#tags=foo`,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... Umlaut: My code works without umlauts, but with umlaut i get a "0000: HTTP/1.1 405 Method Not Allowed" page = test page = øæåØÆÅ ;-make- Runwait curl -u "Admin:admin" -X PUT -d "@1.xml" -H "Content-type: application/xml; charset=UTF-8" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page% ;-upload- RunWait curl -u "Admin:admin" -T "wordlist.txt" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/attach... ;-make tag- RunWait curl -u "Admin:admin" -X POST -H "Content-type:application/x-www-form-urlencoded;charset=UTF-8" --data-binary "className=TagClass&property#tags=test" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... ;-write tag- RunWait curl -u "Admin:admin" -X PUT -H "Content-type: text/plain;charset=UTF-8" --data-binary "%page%`,%page%" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object... When %page% with Umlauts i get: http://xwiki.475771.n2.nabble.com/file/n5638047/trace-make.txt trace-make.txt I tried a DOS-batch with curl UTF-8 encodet getting the same results. Is there a mismatch with codepages? Yours Volker -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-RESTful-API-TAGS-and-unicode-tp55402... Sent from the XWiki- Users mailing list archive at Nabble.com.
http://xwiki.475771.n2.nabble.com/file/n5638051/trace-make.txt trace-make.txt -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-RESTful-API-TAGS-and-unicode-tp55402... Sent from the XWiki- Users mailing list archive at Nabble.com.
On 10/15/2010 10:27 AM, Volker Lapczynski wrote:
Hello Fabio!
I solved the TAG problem, but still fighting with Umlauts.
TAGs solved: In Autohotkey environment i have to "escape" commas, they must be escaped as shown here:
tags=foo`,bar
; --- create a TAG--- Working ;) curl.exe -u "Admin:admin" -X POST -H "Content-type: application/x-www-form-urlencoded" --data-ascii "className=TagClass&property#tags=foo`,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object...
I don't really know what a "Autohotkey environment" is, but I retested it and it works perfectly without any escaping at all (though I am under Ubuntu)
Umlaut:
My code works without umlauts, but with umlaut i get a "0000: HTTP/1.1 405 Method Not Allowed"
page = test page = øæåØÆÅ
Again, tried with a BASH terminal under Ubuntu:
;-make- Runwait curl -u "Admin:admin" -X PUT -d "@1.xml" -H "Content-type: application/xml; charset=UTF-8" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%
What I did: curl -u "Admin:admin" -X PUT -H "Content-type: text/plain" --data-ascii " Hello world" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/øæåØÆÅ (Which is equivalent to send an XML with the content information) Result: page created.
;-upload- RunWait curl -u "Admin:admin" -T "wordlist.txt" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/attach...
What I did: curl -u "Admin:admin" -T tagcloud3.png http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/øæåØÆÅ/attachments/øæåØÆÅ Result: attachment created (though the name is: oaeaOAEA)
;-make tag- RunWait curl -u "Admin:admin" -X POST -H "Content-type:application/x-www-form-urlencoded;charset=UTF-8" --data-binary "className=TagClass&property#tags=test" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object...
What I did: curl -u "Admin:admin" -X POST -d "className=TagClass&property#tags=foo,bar" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/øæåØÆÅ/objects Result: Object tags created and with foo,bar tags
;-write tag- RunWait curl -u "Admin:admin" -X PUT -H "Content-type: text/plain;charset=UTF-8" --data-binary "%page%`,%page%" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/%page%/object...
What I did: curl -u "Admin:admin" -X PUT -H "Content-type: text/plain" --data-ascii "øæåØÆÅ,øæåØÆÅ" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/øæåØÆÅ/objects/TagClass/0/properties/tags Result: tags modified to øæåØÆÅ,øæåØÆÅ Bonus: I also tried with --data-binary as you did and I get the correct result. So, finally, I cannot reproduce your errors :( I don't have a Windows box to make tests with it, but I think that a possible cause is the configuration of your Windows terminal that makes curl.exe send some extra stuff that confuses the REST subsystem. For your information my BASH shell has LANG=en_US.utf8 and gnome-terminal is configured with Unicode (UTF-8) Maybe somebody else with a Window system can help you better. -Fabio
Fabio, thanks for reply! There is something rotten with my Windows codepages. When creating a new page on your sandbox I get the umlauts in the address like: http://127.0.0.1:8080/xwiki/bin/view/Main/øætestøæå But in my systems I get: http://127.0.0.1:8080/xwiki/bin/view/Main/%C3%B8%C3%A6test%C3%B8%C3%A6%C3%A5 http://xwiki.475771.n2.nabble.com/file/n5653682/xwiki-encode.jpg The wrong encoding is stopping curl on Restful interface. But what to do? I am not able to change the Windows environment here. yours Volker -- View this message in context: http://xwiki.475771.n2.nabble.com/XWiki-RESTful-API-TAGS-and-unicode-tp55402... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (3)
-
Fabio Mancinelli -
volker -
Volker Lapczynski