open-coap / java-coap

CoAP Java library
Apache License 2.0
19 stars 6 forks source link

Access to CoapResponse Object in RegistrationManager #24

Closed JaroslawLegierski closed 1 year ago

JaroslawLegierski commented 1 year ago

As part of the tests 1338 I would like to replace the californium coap stack by java-coap in the LwM2M Leshan client. In the first stage, I was able to register the modified leshan-demo-client in the LwM2M server (using RegistrationManager) but unfortunately I have a problem with response. I must forward some information from CoapResponse to the LwM2M layer. Is there any callback mechanism implemented in RegistrationManager that allows me to get a access to coapresponse Object?

sbernard31 commented 1 year ago

@JaroslawLegierski do you have any code to share ?

JaroslawLegierski commented 1 year ago

Together with @adamsero we made this modification in RegistrationManager. But after recent internal discussions, I don't know if this is the right way to go. Maybe we need in java-coap mechanism similar to MessageObserver from Cf ?

sbernard31 commented 1 year ago

I'm not sure to get what you try to achieve here.

FMPOV you should not try to reuse RegistrationManager, I guess this is an implementation of CoAP resource directory.

And LWM2M has pretty much same kind of concept which is already implemented in Leshan.

I guess you "just" want : For sending request: take LWM2M request, translate it to a java-coap request, then send it, wait for response and translate it to LWM2M response. For Receiving : find the hook where you receive request, take the java-coap request, translate it to a LWM2M request, give it to Leshan, get the LWM2M response then translate it to java-coap response then send it.

I guess it should have API to doing this in java-coap. (I guess difficulty will come with observe , dtls, ...)

You need to find how to create a coap server (we need it for LWM2M client and server) Find the API to handle CoAP request. Find the API to Send CoAP Request.

There is some hints in the java-coap README about this.

szysas commented 1 year ago

I also think reusing RegistrationManager class might not be the right thing to do. Registration management is a core part of LwM2M so I'd say that it should come from Leshan. @JaroslawLegierski I can help with API and usage, just say what you need.

JaroslawLegierski commented 1 year ago

@szysas I have question in coap token topic - in californium we have something like RandomTokenGenerator. Does something similar exist in java-coap or do we have to generate the token ourselves ?

szysas commented 1 year ago

No, there is no such a generator. It should be simple to implement with Filter class, like this: EtagGeneratorFilter

sbernard31 commented 1 year ago

I created dedicated issue to talk about java-coap in leshan at https://github.com/open-coap/java-coap/issues/27

@JaroslawLegierski maybe we can close this one ?

JaroslawLegierski commented 1 year ago

Yes - very good idea