open-coap / java-coap

CoAP Java library
Apache License 2.0
18 stars 5 forks source link

We should be able to add `/` and `/*` to `RouterService` #52

Open sbernard31 opened 1 year ago

sbernard31 commented 1 year ago

Currently this is not possible to do :

RouterService.RouteBuilder routerBuilder = new RouterService.RouteBuilder();
routerBuilder //
        .any("/", new RootResource() //
        .any("/myResource", new MyResource() //
        .any("/*", new Default());
router = routerBuilder.build();

If you do that RootResource will never be called. I think this is because / and /* will create 2 RequestMatcher which will be considered as equal and so Default will override RootResource in handlers hashmap. Maybe the solution is to add isPrefixed attribute to equals() and hashcode() methods ?

(triggered by https://github.com/open-coap/java-coap/issues/27#issuecomment-1527757330)

sbernard31 commented 1 year ago

Not directly linked but not sure to get why isPrefixed is transient ? :thinking:

static final class RequestMatcher {
    private final Method method;
    private final String uriPath;
    private transient final boolean isPrefixed;
szysas commented 1 year ago

Well, that transient was to prevent adding isPrefixed to equals method.

sbernard31 commented 1 year ago

Oh I was thinking transient was about Java Serialization. Not sure to know how this is related to equals ? Maybe something related to IDE code generation ?

szysas commented 1 year ago

That is needed by this testing tool: https://jqno.nl/equalsverifier/ to skip fields from being tested.

sbernard31 commented 1 year ago

Oh I didn't know about EqualsVerifier maybe this is a library we should use in Leshan :thinking:

About transient, I read documentation : https://jqno.nl/equalsverifier/manual/ignoring-fields/#transient-fields and they also talk about serialization maybe it make more sense to use : https://jqno.nl/equalsverifier/manual/ignoring-fields/#ignoring-fields (but clearly this is very small details)