← Back to team overview

dhis2-devs team mailing list archive

[Bug 1507725] Re: Error in posting non-String data to API

 

** Changed in: dhis2
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of DHIS 2
developers, which is subscribed to DHIS.
https://bugs.launchpad.net/bugs/1507725

Title:
  Error in posting non-String data to API

Status in DHIS:
  Fix Released

Bug description:
  Consider the following API call, as following the instructions on
  https://www.dhis2.org/doc/snapshot/en/user/html/ch32s28.html :

  $ curl -k -u 'system:redacted' -H "Content-Type: text/plain" -X POST -d 'true' https://apps.dhis2.org/demo/api/systemSettings/keyEmailTls
  {"httpStatus":"OK","httpStatusCode":200,"status":"OK","message":"System setting keyEmailTls set as value 'true'."}

  While technically the same, this yields the same result:

  $ curl -k -u 'system:redacted' -H "Content-Type: text/plain" -X POST https://apps.dhis2.org/demo/api/systemSettings/keyEmailTls?value=true
  {"httpStatus":"OK","httpStatusCode":200,"status":"OK","message":"System setting keyEmailTls set as value 'true'."

  Verify the correct value:

  $ curl -k -u 'system:redacted' -H "Accept: text/plain" -X GET https://apps.dhis2.org/demo/api/systemSettings/keyEmailTls
  true

  Then, go to https://apps.dhis2.org/demo/dhis-web-maintenance-
  settings/systemEmailSettings.action and you will get an error message.
  The application logs will say something similar to:

  * ERROR 2015-10-19 17:34:28,391 Error while executing action (ExceptionInterceptor.java [http-apr-8080-exec-2])
  java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

  The solution is to post the data as JSON:

  $ curl -k -u 'system:redacted' -H "Content-Type: application/json" -X POST -d '{"keyEmailTls":true}' https://apps.dhis2.org/demo/api/systemSettings
  {"httpStatus":"OK","httpStatusCode":200,"status":"OK","message":"System settings imported"}

  I understand the differences between the two requests, and how
  omitting quotation marks in the JSON payload means I am intending to
  send a boolean and not a string of "true", but I suspect some input
  manipulation and/or validation might be necessary for the text/plain
  API request.

  This has occurred on a current 2.20 installation as well as the latest
  stable demo version on apps.dhis2.org/demo/, so I presume it affects
  all stable branches. It does not appear to affect trunk, however, as
  observed https://apps.dhis2.org/dev/, but I did not have access to the
  logs or attempt to send a test email to see if the actual
  functionality is impacted.

To manage notifications about this bug go to:
https://bugs.launchpad.net/dhis2/+bug/1507725/+subscriptions


References