eclipse-leshan / leshan

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

Give feedback to end user when something wrong occurs on notification reception. #206

Closed peteryang closed 7 years ago

peteryang commented 7 years ago

Even though the specs requires the client MUST send content format in the response, the server could have better handling strategy if this happens.

Please refer to the discussion in the pull request: https://github.com/eclipse/leshan/pull/204

One possible solution is to add Not spec compatible related APIs:

public class NotSpecCompatibleAPIs{ static void setResponseContentFormatIfNull(CaliforniumObservationRegistryImpl reg, ContentFormat cf){

} } I choose CaliforniumObservationRegistryImpl as the parameter because it will not change the public ObservationRegistry interface.

It is not elegant, but it helps to developers easy because it takes time to ask device manufacturers to fix their code.

sbernard31 commented 7 years ago

If you want a short term solution, you can implement your own DefaultLwM2mNodeDecoder.

hytromo commented 7 years ago

Just for anyone that wants a Custom decoder that is tested and works with Bosch XDK's observe:

https://gist.github.com/hytromo/b9c5ec7a308e24ca7cec3afcb86642e2 (implements the text decoder if the format is null)

Use it like this:

// Prepare LWM2M server1
LeshanServerBuilder builder = new LeshanServerBuilder();
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setEncoder(new DefaultLwM2mNodeEncoder());
LwM2mNodeDecoder decoder = new CustomLwM2mNodeDecoder();
builder.setDecoder(decoder);
sbernard31 commented 7 years ago

I renamed this issue because the conclusion of the #204 discussion was to "handle response of observation like other response (catch+log+return it to application layer)"

sbernard31 commented 7 years ago

Fixed as PR #244 and #245 are closed.