eclipse-leshan / leshan

Java Library for LWM2M
https://www.eclipse.org/leshan/
BSD 3-Clause "New" or "Revised" License
653 stars 408 forks source link

Error log when receiving a Send with an empty payload #1633

Closed slaft closed 3 months ago

slaft commented 3 months ago

Version(s)

2.0.0-M15

Which components

server

Tested With

No response

What happened

I get this Error log: Exception while handling request [CON-POST MID=22132, Token=2A2CF5E9B85E4A57, OptionSet={"Uri-Path":"dp", "Content-Format":"application/senml+json"}, <empty data>] on the resource /dp from IpPeer ...

The SendListener#onError receives a java.lang.IllegalArgumentException: The validated map is empty.

A 5.00 message is sent to the client (if the request was sent as a Confirmable message).

What did I expect:

No Error log. And if this has to be considered invalid, a more explicit exception (something like: InvalidRequestException: The payload should not be empty) and a 4.00 sent to the client.

How to reproduce

No response

Relevant Output

No response

sbernard31 commented 3 months ago

Thx for reporting that.

Just to be sure your device send a Send operation with no data at all ?

if this has to be considered invalid,

I didn't check if this is valid from a specification point of view but unless I miss something I don't get what could be the purpose of that ? :thinking:

a more explicit exception (something like: InvalidRequestException: The payload should not be empty) and a 4.00 sent to the client.

Yep we should do something like this. :+1:

slaft commented 3 months ago

Just to be sure your device send a Send operation with no data at all ?

I don't have access to what the device sent (I only had the error log) but I was able to reproduce it sending an empty payload with something like this:

Request request = new Request(Code.POST);
request.setPayload(new byte[0]);
request.setOptions(new OptionSet().setContentFormat(ContentFormat.SENML_JSON_CODE).setUriPath("dp"));
...
UdpDataSerializer serializer = new UdpDataSerializer();
RawData data = serializer.serializeRequest(request);
connector.send(data);

I didn't check if this is valid from a specification point of view but unless I miss something I don't get what could be the purpose of that ?

I cannot see the purpose of this too (and I haven't found anything about it in the specification).

sbernard31 commented 3 months ago

a more explicit exception (something like: InvalidRequestException: The payload should not be empty) and a 4.00 sent to the client.

I create a PR about that : https://github.com/eclipse-leshan/leshan/pull/1642

sbernard31 commented 3 months ago

Fix in master. This will be available in 2.0.0-M17.

(Thx again for reporting that :pray:)