A common mistake a user makes when writing a decorator is:
ServerBuilder sb = new ServerBuilder();
sb.service("/svc", myService.decorate(delegate -> (ctx, req) -> {
...
return delegate.serve(ctx, req);
}));
The above decorator is not correct because the returned service does not override the default as() and serviceAdded() implementation. A correct usage is:
sb.service("/svc", myService.decorate((delegate, ctx, req) -> {
return delegate.serve(ctx, req);
});
// or
sb.service("/svc", myService.decorate(delegate -> new SimpleDecoratingService(delegate) {
...
return delegate().serve(ctx, req);
...
}));
We can detect such a mistake by checking if the decorator overrides the default as() and serviceAdded() implementation using Java reflection API and raise an exception.
I would like to also tackle this one :)
Thank you! :bowing_man:
Sorry guys, a month has already passed and I yet couldn't get to it. I will try to work on it over the course of the next week. 馃槥
No worries. I really appreciate that you're trying to help us! :bowing_man:
@trustin Could I try this issue?
I'm not trustin, but I could tell "Yes, please!" 馃槃
:rofl: Yes, please!
I've just realized this stops a user from using Function.identity() or other creative use of functions, like returning a completely different Client or Service which is not a decorator.
That means, I think we can't validate anything this way. :sob:
Most helpful comment
:rofl: Yes, please!