Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cf-dev] Pattern Matching Massage Deliverer

Hi,

I was playing with an idea of defining resource mapping with regular expressions:

https://github.com/macrosak/coap-server

You can define routes like this:

MessageDeliverer deliverer = new PatternMatchingMessageDeliverer()
  .registerResource(Pattern.compile("device/[^/]+/temperature"), new SensorsResource("temperature"));

Or in a similar way to Spring RequestMapping:

@CoapRequestMapping("land/people/[^/]+")
class MagicMirrorResource extends CoapResource {
  // ...
}

This is just a proof of concept right now, but I would be grateful for any feedback.

The actual implementation was super straight-forward. I just needed to change one method:

org.eclipse.californium.core.server.ServerMessageDeliverer#findResource

Since this method is private, I ended up copy-pasting ServerMessageDeliverer implementation to a separate class:

https://github.com/macrosak/coap-server/blob/master/src/main/groovy/com/tado/coap/PatternMatchingMessageDeliverer.groovy

Could we make this method protected in the future release? That would simplify it a lot. Or do you have any other ideas how to achieve this behavior?

Best,
Michal

Back to the top