ryuukei
ryuukei

Reputation: 23

How to read Apache Cocoon 2.1 handle Json request body

If the request is url-encoded, I can get the request parameter pairs using xsp or xsl. But when I send a application/json request, I could not read the request body.

The Cocoon request API doesn't support getReader() interface, thus read the request body as stream is also impossible. I found a similar question , the answer mentioned text generator , which is the one it meant to be in cocoon generator page?

The key request info I can get in cocoon is: 
Header information [name] : Content-Length
Header information [value] : 838
Header information [name] : Content-Type
Header information [value] : application/json

Upvotes: 1

Views: 363

Answers (1)

rakensi
rakensi

Reputation: 1447

Wow, someone else using Cocoon 2.1!

I don't usually look for questions on Cocoon on SO, and just happened to stumble across this.

I hope I understood your question correctly. Here are some suggestions, if it is still relevant:

You can transform the result with the XSLT JSON parser to get XML from your JSON. In one of my applications, I have a pipeline like this:

      <!-- Retrieve a list of documents.
        Request parameters:
          start (optional): The index of the first document, default is 0.
          length (optional): The maximum number of results in the list, default is 100.
      -->
      <map:match pattern="doclist">
        <map:generate type="request"/>
        <map:transform src="xsl/request_to_doclist-query.xslt">
          <map:parameter name="default-start" value="0"/>
          <map:parameter name="default-length" value="100"/>
        </map:transform>
        <map:transform type="sparql"/>
        <map:transform src="xsl/json-parser.xslt"/>
        <map:serialize type="xml"/>
      </map:match>

Upvotes: 0

Related Questions