Hono: Device Registry REST API: "enabled" field cannot be created/updated via POST/PUT request with urlencoded form data input

Created on 24 Aug 2017  路  6Comments  路  Source: eclipse/hono

When trying to create/update device registration data that has "enabled" set to "false", there is a 400 "bad request" response if the request was made with urlencoded form data input.

Example:
curl -i -X POST -d device_id=4711 -d enabled=false http://127.0.0.1:8080/registration/DEFAULT_TENANT

Internally there is a "ClassCastException: String cannot be cast to Boolean" in BaseRegistrationService.getRequestPayload().

HTTP Adapter bug

Most helpful comment

@dejanb @ppatierno @pellmann @sysexcontrol
any opinion on this? I would like to remove the form encoded parameter passing in the REST adapter altogether. WDYT?

All 6 comments

See unit test methods testAddDisabledDeviceUsingFormData() and testUpdateDeviceWithDisablingDeviceUsingFormData() introduced in PR #317 (annotated with @Ignore there for now).

The underlying problem seems to be that the service class has no clue about the type of the properties provided in form fields. Consequently, fixing the problem reported in this issue by assuming that a property called enabled is of type boolean will help much in general, i.e. we are facing the same problem with additional properties to be registered with the device as well.
Thus, I would rather propose to restrict the payload format to JSON only.
WDYT?

Yes, I'd be ok with removing formdata support.
Leads to a more consistent API with just one input/output data format.

@dejanb @ppatierno @pellmann @sysexcontrol
any opinion on this? I would like to remove the form encoded parameter passing in the REST adapter altogether. WDYT?

@sophokles73 absolutely fine for me, more consistent API is better ;)

fixed in 70c8d00941d8db8537a5cd43e2506910ab23a8a6

Was this page helpful?
0 / 5 - 0 ratings