Hi,
I've been working on a number of components in the lates months and what I found
a little bit repetitive is to handle endpoints configuration so I would like to
know if there is any interest about improving such area by adding
support as example
for:
- collections
- nested objects
- validation
- default values
As today a common pattern to configure an endpoint is:
@Override
protected Endpoint createEndpoint(
String uri, String remaining, Map<String, Object> parameters)
throws Exception {
MyConfiguration configuration = new MyConfiguration();
setProperties(configuration, parameters);
return new MyEndpoint(uri, this, configuration);
}
As far as I know, setProperties does not take into account field annotations so
handling i.e. multi value objects (lists, maps) has to be manually
done or default
values have to be defined on both the annotations and the fields.
So let's suppose to have a configuration bean like:
@UriParams
class MyConfiguration {
@UriPath
@Metadata(required = "true")
private String key;
@UriPath( defaultValue = "localhost" )
private String host;
@UriPath( elementType = User.class)
private List<User> users;
@UriPath( elementType = User.class )
private Map<String, User> aliases;
@UriPath( elementType = User.class )
private Proxy proxy;
@UriPath( elementType = String.class, enum = "NEW, UPDATE, DELETE")
private List<String> events;
// getter/setters as usual
}
I'd like to be able to write an endpint uri like:
"users=#usr1,#usr2&aliases.alias1=#usr1&proxy.userName=myUsr,proxy.password=myPwd&events=NEW,CANCEL"
And having camel to automatically bind/validate my options using annotations so:
- set defaults, in this case set host to "localhost" as indicated by
the annotation
- split users, lookup values in the registry and fill users
- set key/vaue for aliases
- set bean properties to proxy (of course proxy need to be instantiable)
- warn about unknown value (CACNEL) for events
- warn/fail as required field key is not provided
This enhancement is definitively not intended to replace any of the methods
available as now bur to leverage them and make configurations simpler
and a little
more annotation oriented.
If there is any interest I'd more than happy to work on it.
Regards,
Luca