I'm making the following curl request to a legacy JSF application:
curl -H "Accept: application/json" -H "Content-type: text/plain" -X POST \
-d '{"name":"value"}' http://localhost:8080/aaa/bbb
The problem I'm having is I don't know how to retrieve the posted JSON data from the FacesContext as a raw String.
I've tried the following:
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
and this returns an empty map, which I'm assuming is because the posted data is not keyed to a parameter name.
If I debug with the following:
FacesContext.getCurrentInstance().getExternalContext().getRequestContentLength()
I get the correct data length, i.e. 16
If I debug with the following:
FacesContext.getCurrentInstance().getExternalContext().getRequestContentType()
I get the correct type, i.e. text/plain.
But what I can't work out is how to actually retrieve the posted data itself.
Any help would be appreciated.
Kind regards
You can call the
getReader()method of theHttpServletRequestclass to obtain aBufferedReaderthat'll allow you to read the POST content data.