Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 96DB919A1C for ; Fri, 25 Mar 2016 06:25:30 +0000 (UTC) Received: (qmail 34247 invoked by uid 500); 25 Mar 2016 06:25:30 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 34197 invoked by uid 500); 25 Mar 2016 06:25:30 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Received: (qmail 34185 invoked by uid 99); 25 Mar 2016 06:25:30 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Mar 2016 06:25:30 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id AF8B8C0A64 for ; Fri, 25 Mar 2016 06:25:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.802 X-Spam-Level: X-Spam-Status: No, score=-0.802 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id fimK0GizJEwa for ; Fri, 25 Mar 2016 06:25:26 +0000 (UTC) Received: from mail-io0-f180.google.com (mail-io0-f180.google.com [209.85.223.180]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 62CD85F246 for ; Fri, 25 Mar 2016 06:25:26 +0000 (UTC) Received: by mail-io0-f180.google.com with SMTP id 124so105345237iov.3 for ; Thu, 24 Mar 2016 23:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=aaFcsj2ssemq6/pFQJ6cNcDq1cIj1zJbxE/HJS+btqQ=; b=wnZy3peViRHfnMLg2mR5d1I8fKmX234cJ3HJGwjkPo7VrVpJlUlrog+NDe/py47WU0 IfzueY/VKLPTvDU1/fNoVCWpPgcfS+zIPRR8EGbiQ4b4zNdoYKKkm6e19s3Qww9OYbpk G6WIEZtTtF2eGfHv5E3KSS6MI91JKlZyT4GJ2fXRbMaeUQ6trO4iuei9tZRJLfM0bEwQ oKY6REk+K9YDupTUwBB6HGhuQyrggmQLtsdd4MJYe0xEZcH53+saC/keiYCpoaUDyLa1 E/e9TkFDy2Lal7GMrT9WbndvqIlWkZp9Hwa93cefPEvWpzQJe9C/30NROJTenLPbsAcd 01Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=aaFcsj2ssemq6/pFQJ6cNcDq1cIj1zJbxE/HJS+btqQ=; b=Gmzz0lAFItpo1Jl22Z2Nb+lFl/TIpmJZpKoXC/snYnc5Db3l9w5h6N2+3l8mfQR8i3 kEoUCSrJSysUl+nHvKpjNew6ZQtf+Ye/Z5mxeXX7rZ5d2I8ukaVpVp6X2FtcxPA+vkK5 93q4cWoXH3AU1mTU9fnCx3+F5pWHWtlFEkR2V28BBOn56otaD9LLWtZdgmYvkXzSuBow jDqwiJB07oTAnGwJJ9YbPE9ns9/TK/5xVvEGf8Sj/JFX+9/nj+cCqfn8kqd2DHb8UAvh gywwi/+A6ROqzf60E1zFWGSOzlc4wT+cc6tzwKBATTtFG+wBYi8vP18lPuM6z4irqx4E TELw== X-Gm-Message-State: AD7BkJI9PmFdHzPb8w8xZ4QKpwUqGLDUROy1zAWPjg/1N6kS10d90JeXdad1F2w7VtI4xVYjvitv/TCDS6zfRA== X-Received: by 10.107.159.137 with SMTP id i131mr11579245ioe.29.1458887125583; Thu, 24 Mar 2016 23:25:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.0.211 with HTTP; Thu, 24 Mar 2016 23:25:06 -0700 (PDT) In-Reply-To: References: From: Claus Ibsen Date: Fri, 25 Mar 2016 07:25:06 +0100 Message-ID: Subject: Re: Improve endpoint configuration To: dev Content-Type: text/plain; charset=UTF-8 Hi I do think there is some very good ideas in here. If we for Camel 3.0 can make those annotations mandatory and part of the auto configuration and validation of components. Today the annotations only play as a role of component documentation. You can remove the annotations and Camel at runtime will still run. And with the annotations as part of auto configuration we also close the circle and make configuration and the documented options aligned. For example you can try run the mvn plugin that validates the endpoint uris from source code http://www.davsclaus.com/2016/01/cheers-fabric8-camel-maven-plugin-to.html And see that you can find "mistakes" between the documented options vs what you can actual configure. Ideally that validation should always pass and be part of the endpoint auto configure. The validation uses the camel-catalog today for that, but part of that logic can be in camel-core. That can also help make better validation exceptions, such as the mvn plugin does. It even has that "did you mean" logic to suggest options you may have mistyped. Its currently using lucence for that, but we could have a simpler logic that can make suggestion in the camel-core so there is no runtime dependency on lucene. On Thu, Mar 24, 2016 at 2:05 PM, lb wrote: > On Thu, Mar 24, 2016 at 1:34 PM, Claus Ibsen wrote: >> On Wed, Mar 23, 2016 at 3:55 PM, lb wrote: >>> 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 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 users; >>> >>> @UriPath( elementType = User.class ) >>> private Map aliases; >>> >>> @UriPath( elementType = User.class ) >>> private Proxy proxy; >>> >>> @UriPath( elementType = String.class, enum = "NEW, UPDATE, DELETE") >>> private List 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" >>> >> >> We should avoid the proxy.xxx notation when possible and only use it >> for more advanced use cases. There is no type safety and the end user >> and tooling do not know what setters are possible to use. >> >> So its better to have a proxyUserName / proxyPassword as options in >> the configuration class so its nicely exposed as options. >> > > I forgot to mention that also Proxy need to be annotated :-) > >> Also its not so common to have Map types with nested type objects. eg >> going down that path makes configuring harder. Instead the endpoint >> should provide a easier to use configuration. >> > > Yep I agree that maps and beans are advanced configuration options and > should be avoided but there are cases where they make sense so I think > it is worth having native support in camel at least to make it a > common path so tooling & co may try to handle them properly. > >> And for enums, then if the type is an enum, then its out of the box. >> In your use case the type is String. So it can be any kind of string. >> Having enums in the annotation makes the component doc / schema aware >> of those and can make it easier for tooling where you can have a >> dropdown to chose among the enum values. >> > > Here the goal was to provide a option validation and yes an enum would > be better but sometimes not possible or not making much sense so imho > having a way to validate the options is valuable. > >> >> >> >>> 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 >>> >> >> Yes all good suggestions but I think its more a goal for Camel 3.0 >> than for 2.x. See further below. >> >> >>> 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. >>> >> >> The @UriParam et all was added much after how components is done >> today. They are a means for component documentation and tooling. Only >> recently we have @UriParams on all the options. >> >> And in the future we can make that mandatory so components and >> endpoints are always documented and we know what options there are and >> what they do etc. >> >> So in the future it may make feasible to use the @UriParam annotations >> as a means for validation and configuring as well. >> >> However I think we need to get the component docs and the other parts >> done before we go down this road. I suggest to take a look at after >> Camel 2.18, eg for Camel 3.0. There we can move to make using >> @UriParam mandatory. And figure out in camel-core how component and >> endpoint creation logic can tap into those annotations and do >> accordingly to your ideas. >> >> But I think its worth creating a JIRA and refer to this @dev and mark >> it for 3.0. >> > > I will -- Claus Ibsen ----------------- http://davsclaus.com @davsclaus Camel in Action 2: https://www.manning.com/ibsen2