2

There seems to be an issue regarding the addition of parameters in the Execution context when I am interacting with Moqui using AngularJS.

The content-type of the request header is automatically set to application/json; charset=UTF-8. But the code in the WebFacadeImpl.groovy for handling application/json requests is

String contentType = request.getHeader("Content-Type")
if (contentType == "application/json" || contentType == "text/json" || contentType.matches("(.*)application/json(.*)")) {
    JsonSlurper slurper = new JsonSlurper()
    Object jsonObj = null
    try {
        jsonObj = slurper.parse(new BufferedReader(new InputStreamReader(request.getInputStream(),
               request.getCharacterEncoding() ?: "UTF-8")))
    } catch (Throwable t) {
        logger.error("Error parsing HTTP request body JSON: ${t.toString()}", t)
        jsonParameters = [_requestBodyJsonParseError:t.getMessage()]
    }
    if (jsonObj instanceof Map) {
        jsonParameters = (Map<String, Object>) jsonObj
    } else if (jsonObj instanceof List) {
        jsonParameters = [_requestBodyJsonList:jsonObj]
    }
    // logger.warn("=========== Got JSON HTTP request body: ${jsonParameters}")
}

This code does not consider the case when the Content-Type is set to application/json; charset=UTF-8 and the parameters are not added to the context automatically.

Shouldn't there be a condition that checks for application/json as a substring for the content-type?

adityazoso
  • 514
  • 5
  • 15
  • StackOverflow is really a place for asking questions, not reporting issues. Please use the Github issue tracker for that: https://github.com/moqui/moqui/issues – David E. Jones Feb 24 '15 at 00:03
  • In the mean time, yes this is an issue for Content-Type strings with parameters (i.e. that have a semicolon following the type/subtype). I haven't run into this using jQuery or JSON-RPC requests which are what I've mainly used this for. If Angular wants to throw that on there it's not a big deal, I'll make a code change to use contains instead of equals. – David E. Jones Feb 24 '15 at 00:12

0 Answers0