Dick, sorry about the delay, I had no Internet access last week.

The problem with JSON you're experiencing is because the shell removes
quotation marks, as they are used to quote the message data so that
special characters like "&" are not interpreted by the shell. You can
try using single quotation marks around the posted string:

curl -b headers -d
'message=test70&metadata=<metadata>"meta":[{"place":{"place_type":"city","region":"CA+"}},{"song":{"artist":"Prince","songtitle":"Never+Let+Me+Down"}}]</metadata>'
http://localhost:8080/api2/user/messages

This does work, but of course everything inside the metadata is
escaped according to XML rules, so the response will be something
like:

<?xml version="1.0" encoding="UTF-8"?>
<api><message>
  <id>16</id>
  <date>Sun, 11 Jul 2010 11:15:19 UTC</date>
  <source>api2</source>
  <body>test70</body>
  
<metadata>&quot;meta&quot;:[{&quot;place&quot;:{&quot;place_type&quot;:&quot;city&quot;,&quot;region&quot;:&quot;CA
&quot;}},{&quot;song&quot;:{&quot;artist&quot;:&quot;Prince&quot;,&quot;songtitle&quot;:&quot;Never
Let Me Down&quot;}}]</metadata>
  <author><nickname>vdichev</nickname><id>1</id></author>
  <tags></tags><replyto></replyto><conversation></conversation>
</message></api>


You are correct that currently only the text elements are extracted
from the metadata XML. I think this is the correct behaviour,
otherwise one could mess with the internal XML message representation
by putting in some of the used elements like <body>, <tags>, another
<metadata>, etc. Probably a workaround could be to somehow escape the
XML contained within the metadata. The problem is that apart from
escaping XML and quoting the shell, the string must also be
URL-encoded! So something like <a/> would probably turn to
"&lt;a/&gt;" and then urlencoded would become "%26lt;a/%26gt;".

Cheers,
Vassil


On Wed, Jul 7, 2010 at 11:02 AM, Richard Hirsch <[email protected]> wrote:
> I'm been working on the use of metadata in api2 and have got it
> working but the problem is that 1) all "s are removed when using JSON
> (see below) or 2) all XML tags are removed when posting with XML.
>
> I assume that this problem is linked to the following code in Message.scala
>
>  lazy val metadata: String = originalXml \ "metadata" text
>
>  lazy val metaData: String = {
>    val org = originalXml
>
>    (org \ "metadata").map(_.text).first
>  }
>
> Anyone have any idea what the problem is?
>
> There is also a JIRA item for thsi:
> https://issues.apache.org/jira/browse/ESME-242
>
> D.
>
>
> ------------------------
>
> curl -b headers -d "message=test70&metadata=<metadata>"
> meta":[{"place":{"place_type":"city","region":"CA+"}},{"song":{"artist":"Prince"
> ,"songtitle":"Never+Let+Me+Down"}}]</metadata>" 
> http://localhost:8080/api2/user/
> messages
>
> <?xml version="1.0" encoding="UTF-8"?>
> <api><message>
>  <id>47</id>
>  <date>Wed, 7 Jul 2010 07:57:03 UTC</date>
>  <source>api2</source>
>  <body>test70</body>
>  <metadata>meta:[{place:{place_type:city,region:CA 
> }},{song:{artist:Prince,song
> title:Never Let Me Down}}]</metadata>
>  <author><nickname>bob1</nickname><id>1</id></author>
>  <tags></tags><replyto></replyto><conversation></conversation>
> </message></api>
>

Reply via email to