[camel] branch master updated (ac304cc -> 7b018bc)

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated (ac304cc -> 7b018bc)

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from ac304cc  CAMEL-13572: proper message body handling
     new f2e24c8  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 1863e5d  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 5bccb7f  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 21f7433  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new d4972be  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 9af09b9  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new f301f09  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 91765b4  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 6113385  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 992273f  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 5af11b8  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 0301d11  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new d42da8c  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 5e450ac  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 829296d  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new ab39c60  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 140ae76  Reduce logging noise for standard discovered factories
     new 8796747  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 35f0ad9  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 2f71934  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new f88ca73  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new 4a0bb04  CAMEL-13566: IntrospectionSupport - Remove old legacy JDK PropertyEditor
     new 9f90947  CAMEL-13569: JndiContext - Remove old bean binding
     new 2339884  CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
     new f142447  CAMEL-13557: Regen
     new b3421fd  CAMEL-13557: Regen
     new 7b018bc  CAMEL-13557: Camel main can configure properties on camel context also

The 27 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/docs/activemq-component.adoc          |   9 +-
 .../src/main/docs/ahc-ws-component.adoc            |   9 +-
 .../camel-ahc/src/main/docs/ahc-component.adoc     |   9 +-
 .../camel-amqp/src/main/docs/amqp-component.adoc   |   9 +-
 .../camel-apns/src/main/docs/apns-component.adoc   |   9 +-
 .../src/main/docs/as2-component.adoc               |   9 +-
 .../src/main/docs/asterisk-component.adoc          |  17 +-
 .../camel-atmos/src/main/docs/atmos-component.adoc |   9 +-
 .../main/docs/atmosphere-websocket-component.adoc  |   9 +-
 .../camel-atom/src/main/docs/atom-component.adoc   |  17 +-
 .../src/main/docs/atomix-map-component.adoc        |   9 +-
 .../src/main/docs/atomix-messaging-component.adoc  |   9 +-
 .../src/main/docs/atomix-multimap-component.adoc   |   9 +-
 .../src/main/docs/atomix-queue-component.adoc      |   9 +-
 .../src/main/docs/atomix-set-component.adoc        |   9 +-
 .../src/main/docs/atomix-value-component.adoc      |   9 +-
 .../camel-avro/src/main/docs/avro-component.adoc   |   9 +-
 .../camel-avro/src/main/docs/avro-dataformat.adoc  |   3 +-
 .../src/main/docs/aws-cw-component.adoc            |   9 +-
 .../src/main/docs/aws-ddb-component.adoc           |   9 +-
 .../src/main/docs/aws-ddbstream-component.adoc     |   9 +-
 .../src/main/docs/aws-ec2-component.adoc           |   9 +-
 .../src/main/docs/aws-ecs-component.adoc           |   9 +-
 .../src/main/docs/aws-eks-component.adoc           |   9 +-
 .../src/main/docs/aws-iam-component.adoc           |   9 +-
 .../src/main/docs/aws-kinesis-component.adoc       |   9 +-
 .../main/docs/aws-kinesis-firehose-component.adoc  |   9 +-
 .../src/main/docs/aws-kms-component.adoc           |   9 +-
 .../src/main/docs/aws-lambda-component.adoc        |   9 +-
 .../src/main/docs/aws-mq-component.adoc            |   9 +-
 .../src/main/docs/aws-msk-component.adoc           |   9 +-
 .../src/main/docs/aws-s3-component.adoc            |   9 +-
 .../src/main/docs/aws-sdb-component.adoc           |  17 +-
 .../src/main/docs/aws-ses-component.adoc           |   9 +-
 .../src/main/docs/aws-sns-component.adoc           |   9 +-
 .../src/main/docs/aws-sqs-component.adoc           |   9 +-
 .../src/main/docs/aws-swf-component.adoc           |   9 +-
 .../src/main/docs/azure-blob-component.adoc        |   9 +-
 .../src/main/docs/azure-queue-component.adoc       |   9 +-
 .../src/main/docs/bean-validator-component.adoc    |  17 +-
 .../camel-bean/src/main/docs/bean-component.adoc   |   6 +-
 .../camel-bean/src/main/docs/class-component.adoc  |   6 +-
 .../src/main/docs/beanstalk-component.adoc         |   9 +-
 .../src/main/docs/bonita-component.adoc            |  17 +-
 .../src/main/docs/box-component.adoc               |   9 +-
 .../src/main/docs/braintree-component.adoc         |   9 +-
 .../src/main/docs/browse-component.adoc            |  17 +-
 .../src/main/docs/caffeine-cache-component.adoc    |   9 +-
 .../main/docs/caffeine-loadcache-component.adoc    |   9 +-
 .../src/main/docs/cql-component.adoc               |  17 +-
 .../src/main/docs/chatscript-component.adoc        |  17 +-
 .../camel-chunk/src/main/docs/chunk-component.adoc |  17 +-
 .../src/main/docs/cm-sms-component.adoc            |  17 +-
 .../camel-cmis/src/main/docs/cmis-component.adoc   |   9 +-
 .../camel-coap/src/main/docs/coap-component.adoc   |  17 +-
 .../src/main/docs/cometd-component.adoc            |   9 +-
 .../src/main/docs/consul-component.adoc            |   9 +-
 .../src/main/docs/controlbus-component.adoc        |  17 +-
 .../camel-corda/src/main/docs/corda-component.adoc |   9 +-
 .../src/main/docs/couchbase-component.adoc         |  17 +-
 .../src/main/docs/couchdb-component.adoc           |  17 +-
 .../src/main/docs/crypto-cms-component.adoc        |   9 +-
 .../src/main/docs/crypto-component.adoc            |   9 +-
 .../src/main/docs/crypto-dataformat.adoc           |   3 +-
 .../camel-cxf/src/main/docs/cxf-component.adoc     |   9 +-
 .../camel-cxf/src/main/docs/cxfrs-component.adoc   |   9 +-
 .../src/main/docs/dataformat-component.adoc        |  17 +-
 .../src/main/docs/dataset-component.adoc           |  17 +-
 .../src/main/docs/dataset-test-component.adoc      |  19 +-
 .../src/main/docs/digitalocean-component.adoc      |  17 +-
 .../src/main/docs/direct-component.adoc            |   9 +-
 .../src/main/docs/direct-vm-component.adoc         |   6 +-
 .../src/main/docs/disruptor-component.adoc         |  10 +-
 .../camel-dns/src/main/docs/dns-component.adoc     |  17 +-
 .../src/main/docs/docker-component.adoc            |   9 +-
 .../camel-dozer/src/main/docs/dozer-component.adoc |  17 +-
 .../camel-drill/src/main/docs/drill-component.adoc |  17 +-
 .../src/main/docs/dropbox-component.adoc           |  17 +-
 .../src/main/docs/ehcache-component.adoc           |   9 +-
 .../camel-ejb/src/main/docs/ejb-component.adoc     |   6 +-
 .../main/docs/elasticsearch-rest-component.adoc    |   9 +-
 .../camel-elsql/src/main/docs/elsql-component.adoc |   9 +-
 .../camel-etcd/src/main/docs/etcd-component.adoc   |   9 +-
 .../src/main/docs/eventadmin-component.adoc        |   6 +-
 .../camel-exec/src/main/docs/exec-component.adoc   |  17 +-
 .../src/main/docs/facebook-component.adoc          |   9 +-
 .../src/main/docs/fhir-component.adoc              |   9 +-
 .../camel-file/src/main/docs/file-component.adoc   |  17 +-
 .../src/main/docs/flatpack-component.adoc          |  17 +-
 .../src/main/docs/flatpack-dataformat.adoc         |   3 +-
 .../camel-flink/src/main/docs/flink-component.adoc |   9 +-
 .../camel-fop/src/main/docs/fop-component.adoc     |  17 +-
 .../src/main/docs/freemarker-component.adoc        |   9 +-
 .../camel-ftp/src/main/docs/ftp-component.adoc     |  17 +-
 .../camel-ftp/src/main/docs/ftps-component.adoc    |   9 +-
 .../camel-ftp/src/main/docs/sftp-component.adoc    |  14 +-
 .../src/main/docs/ganglia-component.adoc           |   9 +-
 .../src/main/docs/geocoder-component.adoc          |  17 +-
 .../camel-git/src/main/docs/git-component.adoc     |  17 +-
 .../src/main/docs/github-component.adoc            |  17 +-
 .../src/main/docs/google-bigquery-component.adoc   |   9 +-
 .../main/docs/google-bigquery-sql-component.adoc   |   9 +-
 .../src/main/docs/google-calendar-component.adoc   |   9 +-
 .../docs/google-calendar-stream-component.adoc     |   9 +-
 .../src/main/docs/google-drive-component.adoc      |   9 +-
 .../src/main/docs/google-mail-component.adoc       |   9 +-
 .../main/docs/google-mail-stream-component.adoc    |   9 +-
 .../src/main/docs/google-pubsub-component.adoc     |   9 +-
 .../src/main/docs/google-sheets-component.adoc     |   9 +-
 .../main/docs/google-sheets-stream-component.adoc  |   9 +-
 .../camel-gora/src/main/docs/gora-component.adoc   |  17 +-
 .../camel-grape/src/main/docs/grape-component.adoc |   6 +-
 .../camel-grpc/src/main/docs/grpc-component.adoc   |  17 +-
 .../src/main/docs/guava-eventbus-component.adoc    |   9 +-
 .../main/docs/hazelcast-atomicvalue-component.adoc |   9 +-
 .../main/docs/hazelcast-instance-component.adoc    |   9 +-
 .../src/main/docs/hazelcast-list-component.adoc    |   9 +-
 .../src/main/docs/hazelcast-map-component.adoc     |   9 +-
 .../main/docs/hazelcast-multimap-component.adoc    |   9 +-
 .../src/main/docs/hazelcast-queue-component.adoc   |   9 +-
 .../docs/hazelcast-replicatedmap-component.adoc    |   9 +-
 .../main/docs/hazelcast-ringbuffer-component.adoc  |   9 +-
 .../src/main/docs/hazelcast-seda-component.adoc    |   9 +-
 .../src/main/docs/hazelcast-set-component.adoc     |   9 +-
 .../src/main/docs/hazelcast-topic-component.adoc   |   9 +-
 .../camel-hbase/src/main/docs/hbase-component.adoc |   9 +-
 .../camel-hdfs2/src/main/docs/hdfs2-component.adoc |   9 +-
 .../src/main/docs/hipchat-component.adoc           |  17 +-
 .../camel-http4/src/main/docs/http4-component.adoc |   9 +-
 .../src/main/docs/iec60870-client-component.adoc   |   9 +-
 .../src/main/docs/iec60870-server-component.adoc   |   9 +-
 .../src/main/docs/ignite-cache-component.adoc      |   9 +-
 .../src/main/docs/ignite-compute-component.adoc    |   9 +-
 .../src/main/docs/ignite-events-component.adoc     |   9 +-
 .../src/main/docs/ignite-idgen-component.adoc      |   9 +-
 .../src/main/docs/ignite-messaging-component.adoc  |   9 +-
 .../src/main/docs/ignite-queue-component.adoc      |   9 +-
 .../src/main/docs/ignite-set-component.adoc        |   9 +-
 .../src/main/docs/infinispan-component.adoc        |   9 +-
 .../src/main/docs/influxdb-component.adoc          |  17 +-
 .../camel-iota/src/main/docs/iota-component.adoc   |  17 +-
 .../camel-ipfs/src/main/docs/ipfs-component.adoc   |  17 +-
 .../camel-irc/src/main/docs/irc-component.adoc     |   9 +-
 .../src/main/docs/ironmq-component.adoc            |  17 +-
 .../camel-jbpm/src/main/docs/jbpm-component.adoc   |  17 +-
 .../src/main/docs/jcache-component.adoc            |   9 +-
 .../src/main/docs/jclouds-component.adoc           |   9 +-
 .../camel-jcr/src/main/docs/jcr-component.adoc     |  17 +-
 .../camel-jdbc/src/main/docs/jdbc-component.adoc   |   9 +-
 .../camel-jetty/src/main/docs/jetty-component.adoc |   9 +-
 .../src/main/docs/jgroups-raft-component.adoc      |   9 +-
 .../src/main/docs/jgroups-component.adoc           |   9 +-
 .../camel-jing/src/main/docs/jing-component.adoc   |  17 +-
 .../camel-jira/src/main/docs/jira-component.adoc   |   9 +-
 .../camel-jms/src/main/docs/jms-component.adoc     |   9 +-
 .../camel-jmx/src/main/docs/jmx-component.adoc     |  17 +-
 .../camel-jolt/src/main/docs/jolt-component.adoc   |   9 +-
 .../camel-jooq/src/main/docs/jooq-component.adoc   |   9 +-
 .../camel-jpa/src/main/docs/jpa-component.adoc     |   9 +-
 .../camel-jsch/src/main/docs/scp-component.adoc    |   9 +-
 .../src/main/docs/json-validator-component.adoc    |  17 +-
 .../camel-jt400/src/main/docs/jt400-component.adoc |   9 +-
 .../camel-kafka/src/main/docs/kafka-component.adoc |   9 +-
 .../docs/kubernetes-config-maps-component.adoc     |  17 +-
 .../docs/kubernetes-deployments-component.adoc     |  17 +-
 .../src/main/docs/kubernetes-hpa-component.adoc    |  17 +-
 .../src/main/docs/kubernetes-job-component.adoc    |  17 +-
 .../main/docs/kubernetes-namespaces-component.adoc |  17 +-
 .../src/main/docs/kubernetes-nodes-component.adoc  |  17 +-
 ...rnetes-persistent-volumes-claims-component.adoc |  17 +-
 .../kubernetes-persistent-volumes-component.adoc   |  17 +-
 .../src/main/docs/kubernetes-pods-component.adoc   |  17 +-
 ...bernetes-replication-controllers-component.adoc |  17 +-
 .../docs/kubernetes-resources-quota-component.adoc |  17 +-
 .../main/docs/kubernetes-secrets-component.adoc    |  17 +-
 .../kubernetes-service-accounts-component.adoc     |  17 +-
 .../main/docs/kubernetes-services-component.adoc   |  17 +-
 .../docs/openshift-build-configs-component.adoc    |  14 +-
 .../src/main/docs/openshift-builds-component.adoc  |  14 +-
 .../src/main/docs/language-component.adoc          |  17 +-
 .../camel-ldap/src/main/docs/ldap-component.adoc   |  17 +-
 .../camel-ldif/src/main/docs/ldif-component.adoc   |  17 +-
 .../src/main/docs/linkedin-component.adoc          |   9 +-
 .../camel-log/src/main/docs/log-component.adoc     |   9 +-
 .../src/main/docs/lucene-component.adoc            |   9 +-
 .../src/main/docs/lumberjack-component.adoc        |   9 +-
 .../camel-mail/src/main/docs/mail-component.adoc   |   9 +-
 .../src/main/docs/master-component.adoc            |   9 +-
 .../src/main/docs/metrics-component.adoc           |   9 +-
 .../src/main/docs/micrometer-component.adoc        |   9 +-
 .../src/main/docs/milo-client-component.adoc       |   9 +-
 .../src/main/docs/milo-server-component.adoc       |   9 +-
 .../camel-mina2/src/main/docs/mina2-component.adoc |   9 +-
 .../camel-mllp/src/main/docs/mllp-component.adoc   |   9 +-
 .../camel-mock/src/main/docs/mock-component.adoc   |  14 +-
 .../src/main/docs/mongodb-gridfs-component.adoc    |  17 +-
 .../src/main/docs/mongodb3-component.adoc          |  17 +-
 .../camel-mqtt/src/main/docs/mqtt-component.adoc   |   9 +-
 .../camel-msv/src/main/docs/msv-component.adoc     |   9 +-
 .../src/main/docs/mustache-component.adoc          |   9 +-
 .../camel-mvel/src/main/docs/mvel-component.adoc   |  17 +-
 .../camel-mvel/src/main/docs/mvel-language.adoc    |   3 +-
 .../src/main/docs/mybatis-bean-component.adoc      |   9 +-
 .../src/main/docs/mybatis-component.adoc           |   9 +-
 .../src/main/docs/nagios-component.adoc            |   9 +-
 .../camel-nats/src/main/docs/nats-component.adoc   |   9 +-
 .../src/main/docs/netty4-http-component.adoc       |   9 +-
 .../src/main/docs/netty4-component.adoc            |   9 +-
 .../camel-nsq/src/main/docs/nsq-component.adoc     |   9 +-
 .../src/main/docs/olingo2-component.adoc           |   9 +-
 .../src/main/docs/olingo4-component.adoc           |   9 +-
 .../src/main/docs/openstack-cinder-component.adoc  |  17 +-
 .../src/main/docs/openstack-glance-component.adoc  |  17 +-
 .../main/docs/openstack-keystone-component.adoc    |  17 +-
 .../src/main/docs/openstack-neutron-component.adoc |  17 +-
 .../src/main/docs/openstack-nova-component.adoc    |  17 +-
 .../src/main/docs/openstack-swift-component.adoc   |  17 +-
 .../src/main/docs/optaplanner-component.adoc       |  17 +-
 .../camel-paho/src/main/docs/paho-component.adoc   |   9 +-
 .../src/main/docs/paxlogging-component.adoc        |   6 +-
 .../camel-pdf/src/main/docs/pdf-component.adoc     |  17 +-
 .../src/main/docs/pgevent-component.adoc           |  17 +-
 .../camel-printer/src/main/docs/lpr-component.adoc |  17 +-
 .../src/main/docs/properties-component.adoc        |   9 +-
 .../src/main/docs/pubnub-component.adoc            |  17 +-
 .../src/main/docs/pulsar-component.adoc            |  11 +-
 .../src/main/docs/quartz2-component.adoc           |   9 +-
 .../src/main/docs/quickfix-component.adoc          |   9 +-
 .../src/main/docs/rabbitmq-component.adoc          |   9 +-
 .../src/main/docs/reactive-streams-component.adoc  |   9 +-
 .../camel-ref/src/main/docs/ref-component.adoc     |  17 +-
 .../src/main/docs/rest-swagger-component.adoc      |   9 +-
 .../src/main/docs/rest-api-component.adoc          |  17 +-
 .../camel-rest/src/main/docs/rest-component.adoc   |   9 +-
 .../src/main/docs/restlet-component.adoc           |   9 +-
 .../camel-rss/src/main/docs/rss-component.adoc     |  17 +-
 .../camel-rss/src/main/docs/rss-dataformat.adoc    |   3 +-
 .../camel-saga/src/main/docs/saga-component.adoc   |  17 +-
 .../src/main/docs/salesforce-component.adoc        |   9 +-
 .../src/main/docs/sap-netweaver-component.adoc     |  17 +-
 .../src/main/docs/xquery-component.adoc            |   9 +-
 .../camel-saxon/src/main/docs/xquery-language.adoc |   3 +-
 .../src/main/docs/scheduler-component.adoc         |   9 +-
 .../src/main/docs/schematron-component.adoc        |  17 +-
 .../camel-seda/src/main/docs/seda-component.adoc   |   9 +-
 .../src/main/docs/service-component.adoc           |   9 +-
 .../src/main/docs/servicenow-component.adoc        |   9 +-
 .../src/main/docs/servlet-component.adoc           |   9 +-
 .../camel-sip/src/main/docs/sip-component.adoc     |  17 +-
 .../src/main/docs/sjms-batch-component.adoc        |   9 +-
 .../camel-sjms/src/main/docs/sjms-component.adoc   |   9 +-
 .../camel-sjms2/src/main/docs/sjms2-component.adoc |   9 +-
 .../camel-slack/src/main/docs/slack-component.adoc |   9 +-
 .../camel-smpp/src/main/docs/smpp-component.adoc   |   9 +-
 .../camel-snmp/src/main/docs/snmp-component.adoc   |  17 +-
 .../camel-solr/src/main/docs/solr-component.adoc   |  17 +-
 .../src/main/docs/soroush-component.adoc           |   9 +-
 .../src/main/docs/spark-rest-component.adoc        |   6 +-
 .../camel-spark/src/main/docs/spark-component.adoc |   9 +-
 .../src/main/docs/splunk-component.adoc            |   9 +-
 .../src/main/docs/spring-batch-component.adoc      |   9 +-
 .../main/docs/spring-integration-component.adoc    |  17 +-
 .../src/main/docs/spring-ldap-component.adoc       |  17 +-
 .../src/main/docs/spring-redis-component.adoc      |  17 +-
 .../src/main/docs/spring-ws-component.adoc         |   9 +-
 .../src/main/docs/spring-event-component.adoc      |  17 +-
 .../camel-sql/src/main/docs/sql-component.adoc     |   9 +-
 .../src/main/docs/sql-stored-component.adoc        |   9 +-
 .../camel-ssh/src/main/docs/ssh-component.adoc     |   9 +-
 .../camel-stax/src/main/docs/stax-component.adoc   |  17 +-
 .../camel-stomp/src/main/docs/stomp-component.adoc |   9 +-
 .../src/main/docs/stream-component.adoc            |  17 +-
 .../src/main/docs/string-template-component.adoc   |  17 +-
 .../camel-stub/src/main/docs/stub-component.adoc   |   9 +-
 .../src/main/docs/telegram-component.adoc          |   9 +-
 .../src/main/docs/thrift-component.adoc            |   9 +-
 .../src/main/docs/thrift-dataformat.adoc           |   3 +-
 .../camel-tika/src/main/docs/tika-component.adoc   |  17 +-
 .../camel-timer/src/main/docs/timer-component.adoc |  17 +-
 .../src/main/docs/twilio-component.adoc            |   9 +-
 .../main/docs/twitter-directmessage-component.adoc |   9 +-
 .../src/main/docs/twitter-search-component.adoc    |   9 +-
 .../src/main/docs/twitter-streaming-component.adoc |   9 +-
 .../src/main/docs/twitter-timeline-component.adoc  |   9 +-
 .../src/main/docs/undertow-component.adoc          |   9 +-
 .../src/main/docs/validator-component.adoc         |   9 +-
 .../src/main/docs/velocity-component.adoc          |   9 +-
 .../camel-vertx/src/main/docs/vertx-component.adoc |   9 +-
 .../camel-vm/src/main/docs/vm-component.adoc       |   9 +-
 .../src/main/docs/weather-component.adoc           |   9 +-
 .../camel-web3j/src/main/docs/web3j-component.adoc |   9 +-
 .../src/main/docs/webhook-component.adoc           |   9 +-
 .../src/main/docs/websocket-jsr356-component.adoc  |  17 +-
 .../src/main/docs/websocket-component.adoc         |   9 +-
 .../src/main/docs/wordpress-component.adoc         |   9 +-
 .../src/main/docs/xchange-component.adoc           |  17 +-
 .../src/main/docs/xmlsecurity-component.adoc       |   9 +-
 .../camel-xmpp/src/main/docs/xmpp-component.adoc   |  17 +-
 .../camel-xslt/src/main/docs/xslt-component.adoc   |   9 +-
 .../src/main/docs/yammer-component.adoc            |   9 +-
 .../src/main/docs/zendesk-component.adoc           |   9 +-
 .../src/main/docs/zookeeper-master-component.adoc  |   9 +-
 .../src/main/docs/zookeeper-component.adoc         |   9 +-
 ...xception.java => PropertyBindingException.java} |  32 +-
 .../impl/engine/BeanProcessorFactoryResolver.java  |   2 +-
 .../impl/engine/BeanProxyFactoryResolver.java      |   2 +-
 .../impl/engine/RestRegistryFactoryResolver.java   |   4 +-
 .../java/org/apache/camel/main/MainSupport.java    |  99 +----
 .../camel/model/ProcessorDefinitionHelper.java     |   8 +-
 .../cloud/ServiceCallExpressionConfiguration.java  |   3 +-
 .../ServiceCallServiceChooserConfiguration.java    |   3 +-
 .../ServiceCallServiceDiscoveryConfiguration.java  |   3 +-
 .../ServiceCallServiceFilterConfiguration.java     |   3 +-
 ...erviceCallServiceLoadBalancerConfiguration.java |   3 +-
 .../file/FileProducerChmodOptionTest.java          |   9 +-
 .../DefaultComponentReferencePropertiesTest.java   |   4 +-
 .../java/org/apache/camel/impl/RegistryTest.java   |  56 ---
 .../java/org/apache/camel/support/Company.java     |   5 +-
 .../camel/support/IntrospectionSupportTest.java    |  96 ++++-
 .../PropertyBindingSupportAutowireTest.java        | 107 +++++
 .../camel/support/PropertyBindingSupportTest.java  | 268 +++++++++++++
 .../org/apache/camel/support/jndi/JndiTest.java    |  11 +-
 .../src/test/resources/jndi-example.properties     |   4 -
 .../management/JmxManagementStrategyFactory.java   |   4 +-
 .../DefaultComponentVerifierExtension.java         |  16 +-
 .../org/apache/camel/support/DefaultComponent.java |  45 ++-
 .../org/apache/camel/support/DefaultEndpoint.java  |  40 +-
 .../org/apache/camel/support/EndpointHelper.java   |   9 +-
 .../apache/camel/support/IntrospectionSupport.java | 111 +++---
 .../camel/support/PropertyBindingSupport.java      | 439 +++++++++++++++++++++
 .../camel/support/RestProducerFactoryHelper.java   |   7 +-
 .../camel/support/ScheduledPollConsumer.java       |  10 +-
 .../camel/support/ScheduledPollEndpoint.java       |   5 +-
 .../support/component/AbstractApiComponent.java    |   3 +-
 .../support/component/AbstractApiEndpoint.java     |   3 +-
 .../org/apache/camel/support/jndi/JndiContext.java |  23 +-
 .../modules/ROOT/pages/activemq-component.adoc     |   9 +-
 .../modules/ROOT/pages/ahc-component.adoc          |   9 +-
 .../modules/ROOT/pages/ahc-ws-component.adoc       |   9 +-
 .../modules/ROOT/pages/amqp-component.adoc         |   9 +-
 .../modules/ROOT/pages/apns-component.adoc         |   9 +-
 .../modules/ROOT/pages/asterisk-component.adoc     |  17 +-
 .../modules/ROOT/pages/atmos-component.adoc        |   9 +-
 .../ROOT/pages/atmosphere-websocket-component.adoc |   9 +-
 .../modules/ROOT/pages/atom-component.adoc         |  17 +-
 .../modules/ROOT/pages/atomix-map-component.adoc   |   9 +-
 .../ROOT/pages/atomix-messaging-component.adoc     |   9 +-
 .../ROOT/pages/atomix-multimap-component.adoc      |   9 +-
 .../modules/ROOT/pages/atomix-queue-component.adoc |   9 +-
 .../modules/ROOT/pages/atomix-set-component.adoc   |   9 +-
 .../modules/ROOT/pages/atomix-value-component.adoc |   9 +-
 .../modules/ROOT/pages/avro-component.adoc         |   9 +-
 .../modules/ROOT/pages/avro-dataformat.adoc        |   3 +-
 .../modules/ROOT/pages/aws-cw-component.adoc       |   9 +-
 .../modules/ROOT/pages/aws-ddb-component.adoc      |   9 +-
 .../ROOT/pages/aws-ddbstream-component.adoc        |   9 +-
 .../modules/ROOT/pages/aws-ec2-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-ecs-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-eks-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-iam-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-kinesis-component.adoc  |   9 +-
 .../ROOT/pages/aws-kinesis-firehose-component.adoc |   9 +-
 .../modules/ROOT/pages/aws-kms-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-lambda-component.adoc   |   9 +-
 .../modules/ROOT/pages/aws-mq-component.adoc       |   9 +-
 .../modules/ROOT/pages/aws-msk-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-s3-component.adoc       |   9 +-
 .../modules/ROOT/pages/aws-sdb-component.adoc      |  17 +-
 .../modules/ROOT/pages/aws-ses-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-sns-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-sqs-component.adoc      |   9 +-
 .../modules/ROOT/pages/aws-swf-component.adoc      |   9 +-
 .../modules/ROOT/pages/azure-blob-component.adoc   |   9 +-
 .../modules/ROOT/pages/azure-queue-component.adoc  |   9 +-
 .../modules/ROOT/pages/bean-component.adoc         |   6 +-
 .../ROOT/pages/bean-validator-component.adoc       |  17 +-
 .../modules/ROOT/pages/beanstalk-component.adoc    |   9 +-
 .../modules/ROOT/pages/bonita-component.adoc       |  17 +-
 .../modules/ROOT/pages/braintree-component.adoc    |   9 +-
 .../modules/ROOT/pages/browse-component.adoc       |  17 +-
 .../ROOT/pages/caffeine-cache-component.adoc       |   9 +-
 .../ROOT/pages/caffeine-loadcache-component.adoc   |   9 +-
 .../modules/ROOT/pages/chatscript-component.adoc   |  17 +-
 .../modules/ROOT/pages/chunk-component.adoc        |  17 +-
 .../modules/ROOT/pages/class-component.adoc        |   6 +-
 .../modules/ROOT/pages/cm-sms-component.adoc       |  17 +-
 .../modules/ROOT/pages/cmis-component.adoc         |   9 +-
 .../modules/ROOT/pages/coap-component.adoc         |  17 +-
 .../modules/ROOT/pages/cometd-component.adoc       |   9 +-
 .../modules/ROOT/pages/consul-component.adoc       |   9 +-
 .../modules/ROOT/pages/controlbus-component.adoc   |  17 +-
 .../modules/ROOT/pages/corda-component.adoc        |   9 +-
 .../modules/ROOT/pages/couchbase-component.adoc    |  17 +-
 .../modules/ROOT/pages/couchdb-component.adoc      |  17 +-
 .../modules/ROOT/pages/cql-component.adoc          |  17 +-
 .../modules/ROOT/pages/crypto-cms-component.adoc   |   9 +-
 .../modules/ROOT/pages/crypto-component.adoc       |   9 +-
 .../modules/ROOT/pages/crypto-dataformat.adoc      |   3 +-
 .../modules/ROOT/pages/cxf-component.adoc          |   9 +-
 .../modules/ROOT/pages/cxfrs-component.adoc        |   9 +-
 .../modules/ROOT/pages/dataformat-component.adoc   |  17 +-
 .../modules/ROOT/pages/dataset-component.adoc      |  17 +-
 .../modules/ROOT/pages/dataset-test-component.adoc |  19 +-
 .../modules/ROOT/pages/digitalocean-component.adoc |  17 +-
 .../modules/ROOT/pages/direct-component.adoc       |   9 +-
 .../modules/ROOT/pages/direct-vm-component.adoc    |   6 +-
 .../modules/ROOT/pages/disruptor-component.adoc    |  10 +-
 .../modules/ROOT/pages/dns-component.adoc          |  17 +-
 .../modules/ROOT/pages/docker-component.adoc       |   9 +-
 .../modules/ROOT/pages/dozer-component.adoc        |  17 +-
 .../modules/ROOT/pages/drill-component.adoc        |  17 +-
 .../modules/ROOT/pages/dropbox-component.adoc      |  17 +-
 .../modules/ROOT/pages/ehcache-component.adoc      |   9 +-
 .../modules/ROOT/pages/ejb-component.adoc          |   6 +-
 .../ROOT/pages/elasticsearch-rest-component.adoc   |   9 +-
 .../modules/ROOT/pages/elsql-component.adoc        |   9 +-
 .../modules/ROOT/pages/etcd-component.adoc         |   9 +-
 .../modules/ROOT/pages/eventadmin-component.adoc   |   6 +-
 .../modules/ROOT/pages/exec-component.adoc         |  17 +-
 .../modules/ROOT/pages/facebook-component.adoc     |   9 +-
 .../modules/ROOT/pages/file-component.adoc         |  17 +-
 .../modules/ROOT/pages/flatpack-component.adoc     |  17 +-
 .../modules/ROOT/pages/flatpack-dataformat.adoc    |   3 +-
 .../modules/ROOT/pages/flink-component.adoc        |   9 +-
 .../modules/ROOT/pages/fop-component.adoc          |  17 +-
 .../modules/ROOT/pages/freemarker-component.adoc   |   9 +-
 .../modules/ROOT/pages/ftp-component.adoc          |  17 +-
 .../modules/ROOT/pages/ftps-component.adoc         |   9 +-
 .../modules/ROOT/pages/ganglia-component.adoc      |   9 +-
 .../modules/ROOT/pages/geocoder-component.adoc     |  17 +-
 .../modules/ROOT/pages/git-component.adoc          |  17 +-
 .../modules/ROOT/pages/github-component.adoc       |  17 +-
 .../ROOT/pages/google-bigquery-component.adoc      |   9 +-
 .../ROOT/pages/google-bigquery-sql-component.adoc  |   9 +-
 .../ROOT/pages/google-calendar-component.adoc      |   9 +-
 .../pages/google-calendar-stream-component.adoc    |   9 +-
 .../modules/ROOT/pages/google-drive-component.adoc |   9 +-
 .../modules/ROOT/pages/google-mail-component.adoc  |   9 +-
 .../ROOT/pages/google-mail-stream-component.adoc   |   9 +-
 .../ROOT/pages/google-pubsub-component.adoc        |   9 +-
 .../ROOT/pages/google-sheets-component.adoc        |   9 +-
 .../ROOT/pages/google-sheets-stream-component.adoc |   9 +-
 .../modules/ROOT/pages/gora-component.adoc         |  17 +-
 .../modules/ROOT/pages/grape-component.adoc        |   6 +-
 .../modules/ROOT/pages/grpc-component.adoc         |  17 +-
 .../ROOT/pages/guava-eventbus-component.adoc       |   9 +-
 .../pages/hazelcast-atomicvalue-component.adoc     |   9 +-
 .../ROOT/pages/hazelcast-instance-component.adoc   |   9 +-
 .../ROOT/pages/hazelcast-list-component.adoc       |   9 +-
 .../ROOT/pages/hazelcast-map-component.adoc        |   9 +-
 .../ROOT/pages/hazelcast-multimap-component.adoc   |   9 +-
 .../ROOT/pages/hazelcast-queue-component.adoc      |   9 +-
 .../pages/hazelcast-replicatedmap-component.adoc   |   9 +-
 .../ROOT/pages/hazelcast-ringbuffer-component.adoc |   9 +-
 .../ROOT/pages/hazelcast-seda-component.adoc       |   9 +-
 .../ROOT/pages/hazelcast-set-component.adoc        |   9 +-
 .../ROOT/pages/hazelcast-topic-component.adoc      |   9 +-
 .../modules/ROOT/pages/hbase-component.adoc        |   9 +-
 .../modules/ROOT/pages/hdfs2-component.adoc        |   9 +-
 .../modules/ROOT/pages/hipchat-component.adoc      |  17 +-
 .../modules/ROOT/pages/http4-component.adoc        |   9 +-
 .../ROOT/pages/iec60870-client-component.adoc      |   9 +-
 .../ROOT/pages/iec60870-server-component.adoc      |   9 +-
 .../modules/ROOT/pages/ignite-cache-component.adoc |   9 +-
 .../ROOT/pages/ignite-compute-component.adoc       |   9 +-
 .../ROOT/pages/ignite-events-component.adoc        |   9 +-
 .../modules/ROOT/pages/ignite-idgen-component.adoc |   9 +-
 .../ROOT/pages/ignite-messaging-component.adoc     |   9 +-
 .../modules/ROOT/pages/ignite-queue-component.adoc |   9 +-
 .../modules/ROOT/pages/ignite-set-component.adoc   |   9 +-
 .../modules/ROOT/pages/infinispan-component.adoc   |   9 +-
 .../modules/ROOT/pages/influxdb-component.adoc     |  17 +-
 .../modules/ROOT/pages/iota-component.adoc         |  17 +-
 .../modules/ROOT/pages/ipfs-component.adoc         |  17 +-
 .../modules/ROOT/pages/irc-component.adoc          |   9 +-
 .../modules/ROOT/pages/ironmq-component.adoc       |  17 +-
 .../modules/ROOT/pages/jbpm-component.adoc         |  17 +-
 .../modules/ROOT/pages/jcache-component.adoc       |   9 +-
 .../modules/ROOT/pages/jclouds-component.adoc      |   9 +-
 .../modules/ROOT/pages/jcr-component.adoc          |  17 +-
 .../modules/ROOT/pages/jdbc-component.adoc         |   9 +-
 .../modules/ROOT/pages/jetty-component.adoc        |   9 +-
 .../modules/ROOT/pages/jgroups-component.adoc      |   9 +-
 .../modules/ROOT/pages/jgroups-raft-component.adoc |   9 +-
 .../modules/ROOT/pages/jing-component.adoc         |  17 +-
 .../modules/ROOT/pages/jira-component.adoc         |   9 +-
 .../modules/ROOT/pages/jms-component.adoc          |   9 +-
 .../modules/ROOT/pages/jmx-component.adoc          |  17 +-
 .../modules/ROOT/pages/jolt-component.adoc         |   9 +-
 .../modules/ROOT/pages/jooq-component.adoc         |   9 +-
 .../modules/ROOT/pages/jpa-component.adoc          |   9 +-
 .../ROOT/pages/json-validator-component.adoc       |  17 +-
 .../modules/ROOT/pages/jt400-component.adoc        |   9 +-
 .../modules/ROOT/pages/kafka-component.adoc        |   9 +-
 .../pages/kubernetes-config-maps-component.adoc    |  17 +-
 .../pages/kubernetes-deployments-component.adoc    |  17 +-
 .../ROOT/pages/kubernetes-hpa-component.adoc       |  17 +-
 .../ROOT/pages/kubernetes-job-component.adoc       |  17 +-
 .../pages/kubernetes-namespaces-component.adoc     |  17 +-
 .../ROOT/pages/kubernetes-nodes-component.adoc     |  17 +-
 ...rnetes-persistent-volumes-claims-component.adoc |  17 +-
 .../kubernetes-persistent-volumes-component.adoc   |  17 +-
 .../ROOT/pages/kubernetes-pods-component.adoc      |  17 +-
 ...bernetes-replication-controllers-component.adoc |  17 +-
 .../kubernetes-resources-quota-component.adoc      |  17 +-
 .../ROOT/pages/kubernetes-secrets-component.adoc   |  17 +-
 .../kubernetes-service-accounts-component.adoc     |  17 +-
 .../ROOT/pages/kubernetes-services-component.adoc  |  17 +-
 .../modules/ROOT/pages/language-component.adoc     |  17 +-
 .../modules/ROOT/pages/ldap-component.adoc         |  17 +-
 .../modules/ROOT/pages/ldif-component.adoc         |  17 +-
 .../modules/ROOT/pages/log-component.adoc          |   9 +-
 .../modules/ROOT/pages/lpr-component.adoc          |  17 +-
 .../modules/ROOT/pages/lucene-component.adoc       |   9 +-
 .../modules/ROOT/pages/lumberjack-component.adoc   |   9 +-
 .../modules/ROOT/pages/mail-component.adoc         |   9 +-
 .../modules/ROOT/pages/master-component.adoc       |   9 +-
 .../modules/ROOT/pages/metrics-component.adoc      |   9 +-
 .../modules/ROOT/pages/micrometer-component.adoc   |   9 +-
 .../modules/ROOT/pages/milo-client-component.adoc  |   9 +-
 .../modules/ROOT/pages/milo-server-component.adoc  |   9 +-
 .../modules/ROOT/pages/mina2-component.adoc        |   9 +-
 .../modules/ROOT/pages/mllp-component.adoc         |   9 +-
 .../modules/ROOT/pages/mock-component.adoc         |  14 +-
 .../ROOT/pages/mongodb-gridfs-component.adoc       |  17 +-
 .../modules/ROOT/pages/mongodb3-component.adoc     |  17 +-
 .../modules/ROOT/pages/mqtt-component.adoc         |   9 +-
 .../modules/ROOT/pages/msv-component.adoc          |   9 +-
 .../modules/ROOT/pages/mustache-component.adoc     |   9 +-
 .../modules/ROOT/pages/mvel-component.adoc         |  17 +-
 .../modules/ROOT/pages/mvel-language.adoc          |   3 +-
 .../modules/ROOT/pages/mybatis-bean-component.adoc |   9 +-
 .../modules/ROOT/pages/mybatis-component.adoc      |   9 +-
 .../modules/ROOT/pages/nagios-component.adoc       |   9 +-
 .../modules/ROOT/pages/nats-component.adoc         |   9 +-
 .../modules/ROOT/pages/netty4-component.adoc       |   9 +-
 .../modules/ROOT/pages/netty4-http-component.adoc  |   9 +-
 .../modules/ROOT/pages/nsq-component.adoc          |   9 +-
 .../pages/openshift-build-configs-component.adoc   |  14 +-
 .../ROOT/pages/openshift-builds-component.adoc     |  14 +-
 .../ROOT/pages/openstack-cinder-component.adoc     |  17 +-
 .../ROOT/pages/openstack-glance-component.adoc     |  17 +-
 .../ROOT/pages/openstack-keystone-component.adoc   |  17 +-
 .../ROOT/pages/openstack-neutron-component.adoc    |  17 +-
 .../ROOT/pages/openstack-nova-component.adoc       |  17 +-
 .../ROOT/pages/openstack-swift-component.adoc      |  17 +-
 .../modules/ROOT/pages/optaplanner-component.adoc  |  17 +-
 .../modules/ROOT/pages/paho-component.adoc         |   9 +-
 .../modules/ROOT/pages/paxlogging-component.adoc   |   6 +-
 .../modules/ROOT/pages/pdf-component.adoc          |  17 +-
 .../modules/ROOT/pages/pgevent-component.adoc      |  17 +-
 .../modules/ROOT/pages/properties-component.adoc   |   9 +-
 .../modules/ROOT/pages/pubnub-component.adoc       |  17 +-
 .../modules/ROOT/pages/pulsar-component.adoc       |  11 +-
 .../modules/ROOT/pages/quartz2-component.adoc      |   9 +-
 .../modules/ROOT/pages/quickfix-component.adoc     |   9 +-
 .../modules/ROOT/pages/rabbitmq-component.adoc     |   9 +-
 .../ROOT/pages/reactive-streams-component.adoc     |   9 +-
 .../modules/ROOT/pages/ref-component.adoc          |  17 +-
 .../modules/ROOT/pages/rest-api-component.adoc     |  17 +-
 .../modules/ROOT/pages/rest-component.adoc         |   9 +-
 .../modules/ROOT/pages/rest-swagger-component.adoc |   9 +-
 .../modules/ROOT/pages/restlet-component.adoc      |   9 +-
 .../modules/ROOT/pages/rss-component.adoc          |  17 +-
 .../modules/ROOT/pages/rss-dataformat.adoc         |   3 +-
 .../modules/ROOT/pages/saga-component.adoc         |  17 +-
 .../ROOT/pages/sap-netweaver-component.adoc        |  17 +-
 .../modules/ROOT/pages/scheduler-component.adoc    |   9 +-
 .../modules/ROOT/pages/schematron-component.adoc   |  17 +-
 .../modules/ROOT/pages/scp-component.adoc          |   9 +-
 .../modules/ROOT/pages/seda-component.adoc         |   9 +-
 .../modules/ROOT/pages/service-component.adoc      |   9 +-
 .../modules/ROOT/pages/servlet-component.adoc      |   9 +-
 .../modules/ROOT/pages/sftp-component.adoc         |  14 +-
 .../modules/ROOT/pages/sip-component.adoc          |  17 +-
 .../modules/ROOT/pages/sjms-batch-component.adoc   |   9 +-
 .../modules/ROOT/pages/sjms-component.adoc         |   9 +-
 .../modules/ROOT/pages/sjms2-component.adoc        |   9 +-
 .../modules/ROOT/pages/slack-component.adoc        |   9 +-
 .../modules/ROOT/pages/smpp-component.adoc         |   9 +-
 .../modules/ROOT/pages/snmp-component.adoc         |  17 +-
 .../modules/ROOT/pages/solr-component.adoc         |  17 +-
 .../modules/ROOT/pages/soroush-component.adoc      |   9 +-
 .../modules/ROOT/pages/spark-component.adoc        |   9 +-
 .../modules/ROOT/pages/spark-rest-component.adoc   |   6 +-
 .../modules/ROOT/pages/splunk-component.adoc       |   9 +-
 .../modules/ROOT/pages/spring-batch-component.adoc |   9 +-
 .../modules/ROOT/pages/spring-event-component.adoc |  17 +-
 .../ROOT/pages/spring-integration-component.adoc   |  17 +-
 .../modules/ROOT/pages/spring-ldap-component.adoc  |  17 +-
 .../modules/ROOT/pages/spring-redis-component.adoc |  17 +-
 .../modules/ROOT/pages/spring-ws-component.adoc    |   9 +-
 .../modules/ROOT/pages/sql-component.adoc          |   9 +-
 .../modules/ROOT/pages/sql-stored-component.adoc   |   9 +-
 .../modules/ROOT/pages/ssh-component.adoc          |   9 +-
 .../modules/ROOT/pages/stax-component.adoc         |  17 +-
 .../modules/ROOT/pages/stomp-component.adoc        |   9 +-
 .../modules/ROOT/pages/stream-component.adoc       |  17 +-
 .../ROOT/pages/string-template-component.adoc      |  17 +-
 .../modules/ROOT/pages/stub-component.adoc         |   9 +-
 .../modules/ROOT/pages/telegram-component.adoc     |   9 +-
 .../modules/ROOT/pages/thrift-component.adoc       |   9 +-
 .../modules/ROOT/pages/thrift-dataformat.adoc      |   3 +-
 .../modules/ROOT/pages/tika-component.adoc         |  17 +-
 .../modules/ROOT/pages/timer-component.adoc        |  17 +-
 .../modules/ROOT/pages/twilio-component.adoc       |   9 +-
 .../pages/twitter-directmessage-component.adoc     |   9 +-
 .../ROOT/pages/twitter-search-component.adoc       |   9 +-
 .../ROOT/pages/twitter-streaming-component.adoc    |   9 +-
 .../ROOT/pages/twitter-timeline-component.adoc     |   9 +-
 .../modules/ROOT/pages/undertow-component.adoc     |   9 +-
 .../modules/ROOT/pages/validator-component.adoc    |   9 +-
 .../modules/ROOT/pages/velocity-component.adoc     |   9 +-
 .../modules/ROOT/pages/vertx-component.adoc        |   9 +-
 .../modules/ROOT/pages/vm-component.adoc           |   9 +-
 .../modules/ROOT/pages/weather-component.adoc      |   9 +-
 .../modules/ROOT/pages/web3j-component.adoc        |   9 +-
 .../modules/ROOT/pages/webhook-component.adoc      |   9 +-
 .../modules/ROOT/pages/websocket-component.adoc    |   9 +-
 .../ROOT/pages/websocket-jsr356-component.adoc     |  17 +-
 .../modules/ROOT/pages/wordpress-component.adoc    |   9 +-
 .../modules/ROOT/pages/xchange-component.adoc      |  17 +-
 .../modules/ROOT/pages/xmlsecurity-component.adoc  |   9 +-
 .../modules/ROOT/pages/xmpp-component.adoc         |  17 +-
 .../modules/ROOT/pages/xquery-component.adoc       |   9 +-
 .../modules/ROOT/pages/xquery-language.adoc        |   3 +-
 .../modules/ROOT/pages/xslt-component.adoc         |   9 +-
 .../modules/ROOT/pages/yammer-component.adoc       |   9 +-
 .../modules/ROOT/pages/zendesk-component.adoc      |   9 +-
 .../modules/ROOT/pages/zookeeper-component.adoc    |   9 +-
 .../ROOT/pages/zookeeper-master-component.adoc     |   9 +-
 .../src/main/resources/application.properties      |   4 +
 .../springboot/ActiveMQComponentConfiguration.java |  13 +
 .../ahc/springboot/AhcComponentConfiguration.java  |  13 +
 .../ws/springboot/WsComponentConfiguration.java    |  13 +
 .../springboot/AMQPComponentConfiguration.java     |  13 +
 .../springboot/ApnsComponentConfiguration.java     |  13 +
 .../as2/springboot/AS2ComponentConfiguration.java  |  13 +
 .../springboot/AsteriskComponentConfiguration.java |  13 +
 .../springboot/AtmosComponentConfiguration.java    |  13 +
 .../WebsocketComponentConfiguration.java           |  13 +
 .../springboot/AtomComponentConfiguration.java     |  13 +
 .../AtomixMapComponentConfiguration.java           |  13 +
 .../AtomixMessagingComponentConfiguration.java     |  13 +
 .../AtomixMultiMapComponentConfiguration.java      |  13 +
 .../AtomixQueueComponentConfiguration.java         |  13 +
 .../AtomixSetComponentConfiguration.java           |  13 +
 .../AtomixValueComponentConfiguration.java         |  13 +
 .../springboot/AvroComponentConfiguration.java     |  13 +
 .../cw/springboot/CwComponentConfiguration.java    |  13 +
 .../ddb/springboot/DdbComponentConfiguration.java  |  13 +
 .../DdbStreamComponentConfiguration.java           |  13 +
 .../ec2/springboot/EC2ComponentConfiguration.java  |  13 +
 .../ecs/springboot/ECSComponentConfiguration.java  |  13 +
 .../eks/springboot/EKSComponentConfiguration.java  |  13 +
 .../iam/springboot/IAMComponentConfiguration.java  |  13 +
 .../KinesisFirehoseComponentConfiguration.java     |  13 +
 .../springboot/KinesisComponentConfiguration.java  |  13 +
 .../kms/springboot/KMSComponentConfiguration.java  |  13 +
 .../springboot/LambdaComponentConfiguration.java   |  13 +
 .../mq/springboot/MQComponentConfiguration.java    |  13 +
 .../msk/springboot/MSKComponentConfiguration.java  |  13 +
 .../s3/springboot/S3ComponentConfiguration.java    |  13 +
 .../sdb/springboot/SdbComponentConfiguration.java  |  13 +
 .../ses/springboot/SesComponentConfiguration.java  |  13 +
 .../sns/springboot/SnsComponentConfiguration.java  |  13 +
 .../sqs/springboot/SqsComponentConfiguration.java  |  13 +
 .../swf/springboot/SWFComponentConfiguration.java  |  13 +
 .../BlobServiceComponentConfiguration.java         |  13 +
 .../QueueServiceComponentConfiguration.java        |  13 +
 .../springboot/BeanComponentConfiguration.java     |  13 +
 .../springboot/ClassComponentConfiguration.java    |  13 +
 .../BeanValidatorComponentConfiguration.java       |  13 +
 .../BeanstalkComponentConfiguration.java           |  13 +
 .../springboot/BonitaComponentConfiguration.java   |  13 +
 .../box/springboot/BoxComponentConfiguration.java  |  13 +
 .../BraintreeComponentConfiguration.java           |  13 +
 .../springboot/BrowseComponentConfiguration.java   |  13 +
 .../CaffeineCacheComponentConfiguration.java       |  13 +
 .../CaffeineLoadCacheComponentConfiguration.java   |  13 +
 .../CassandraComponentConfiguration.java           |  13 +
 .../ChatScriptComponentConfiguration.java          |  13 +
 .../springboot/ChunkComponentConfiguration.java    |  13 +
 .../cm/springboot/CMComponentConfiguration.java    |  13 +
 .../springboot/CMISComponentConfiguration.java     |  13 +
 .../springboot/CoAPComponentConfiguration.java     |  13 +
 .../springboot/CometdComponentConfiguration.java   |  13 +
 .../springboot/ConsulComponentConfiguration.java   |  13 +
 .../ControlBusComponentConfiguration.java          |  13 +
 .../springboot/CordaComponentConfiguration.java    |  13 +
 .../CouchbaseComponentConfiguration.java           |  13 +
 .../springboot/CouchDbComponentConfiguration.java  |  13 +
 .../CryptoCmsComponentConfiguration.java           |  13 +
 .../DigitalSignatureComponentConfiguration.java    |  13 +
 .../springboot/CxfRsComponentConfiguration.java    |  13 +
 .../cxf/springboot/CxfComponentConfiguration.java  |  13 +
 .../DataFormatComponentConfiguration.java          |  13 +
 .../springboot/DataSetComponentConfiguration.java  |  13 +
 .../DataSetTestComponentConfiguration.java         |  13 +
 .../DigitalOceanComponentConfiguration.java        |  13 +
 .../springboot/DirectComponentConfiguration.java   |  13 +
 .../springboot/DirectVmComponentConfiguration.java |  13 +
 .../DisruptorComponentConfiguration.java           |  13 +
 .../DisruptorVmComponentConfiguration.java         |  13 +
 .../dns/springboot/DnsComponentConfiguration.java  |  13 +
 .../springboot/DockerComponentConfiguration.java   |  13 +
 .../springboot/DozerComponentConfiguration.java    |  13 +
 .../springboot/DrillComponentConfiguration.java    |  13 +
 .../springboot/DropboxComponentConfiguration.java  |  13 +
 .../springboot/EhcacheComponentConfiguration.java  |  13 +
 .../ElasticsearchComponentConfiguration.java       |  13 +
 .../springboot/ElsqlComponentConfiguration.java    |  13 +
 .../springboot/EtcdComponentConfiguration.java     |  13 +
 .../springboot/ExecComponentConfiguration.java     |  13 +
 .../springboot/FacebookComponentConfiguration.java |  13 +
 .../springboot/FhirComponentConfiguration.java     |  13 +
 .../springboot/FileComponentConfiguration.java     |  13 +
 .../springboot/FlatpackComponentConfiguration.java |  13 +
 .../springboot/FlinkComponentConfiguration.java    |  13 +
 .../fop/springboot/FopComponentConfiguration.java  |  13 +
 .../FreemarkerComponentConfiguration.java          |  13 +
 .../springboot/FtpComponentConfiguration.java      |  13 +
 .../springboot/FtpsComponentConfiguration.java     |  13 +
 .../springboot/SftpComponentConfiguration.java     |  13 +
 .../springboot/GangliaComponentConfiguration.java  |  13 +
 .../springboot/GeoCoderComponentConfiguration.java |  13 +
 .../git/springboot/GitComponentConfiguration.java  |  13 +
 .../springboot/GitHubComponentConfiguration.java   |  13 +
 .../GoogleBigQueryComponentConfiguration.java      |  13 +
 .../GoogleBigQuerySQLComponentConfiguration.java   |  13 +
 .../GoogleCalendarComponentConfiguration.java      |  13 +
 ...GoogleCalendarStreamComponentConfiguration.java |  13 +
 .../GoogleDriveComponentConfiguration.java         |  13 +
 .../GoogleMailComponentConfiguration.java          |  13 +
 .../GoogleMailStreamComponentConfiguration.java    |  13 +
 .../GooglePubsubComponentConfiguration.java        |  13 +
 .../GoogleSheetsComponentConfiguration.java        |  13 +
 .../GoogleSheetsStreamComponentConfiguration.java  |  13 +
 .../springboot/GoraComponentConfiguration.java     |  13 +
 .../springboot/GrpcComponentConfiguration.java     |  13 +
 .../GuavaEventBusComponentConfiguration.java       |  13 +
 ...azelcastAtomicnumberComponentConfiguration.java |  13 +
 .../HazelcastInstanceComponentConfiguration.java   |  13 +
 .../HazelcastListComponentConfiguration.java       |  13 +
 .../HazelcastMapComponentConfiguration.java        |  13 +
 .../HazelcastMultimapComponentConfiguration.java   |  13 +
 .../HazelcastQueueComponentConfiguration.java      |  13 +
 ...zelcastReplicatedmapComponentConfiguration.java |  13 +
 .../HazelcastRingbufferComponentConfiguration.java |  13 +
 .../HazelcastSedaComponentConfiguration.java       |  13 +
 .../HazelcastSetComponentConfiguration.java        |  13 +
 .../HazelcastTopicComponentConfiguration.java      |  13 +
 .../springboot/HBaseComponentConfiguration.java    |  13 +
 .../springboot/HdfsComponentConfiguration.java     |  13 +
 .../springboot/HipchatComponentConfiguration.java  |  13 +
 .../springboot/HttpComponentConfiguration.java     |  13 +
 .../springboot/ClientComponentConfiguration.java   |  13 +
 .../springboot/ServerComponentConfiguration.java   |  13 +
 .../IgniteCacheComponentConfiguration.java         |  13 +
 .../IgniteComputeComponentConfiguration.java       |  13 +
 .../IgniteEventsComponentConfiguration.java        |  13 +
 .../IgniteIdGenComponentConfiguration.java         |  13 +
 .../IgniteMessagingComponentConfiguration.java     |  13 +
 .../IgniteQueueComponentConfiguration.java         |  13 +
 .../IgniteSetComponentConfiguration.java           |  13 +
 .../InfinispanComponentConfiguration.java          |  13 +
 .../springboot/InfluxDbComponentConfiguration.java |  13 +
 .../springboot/IOTAComponentConfiguration.java     |  13 +
 .../springboot/IPFSComponentConfiguration.java     |  13 +
 .../irc/springboot/IrcComponentConfiguration.java  |  13 +
 .../springboot/IronMQComponentConfiguration.java   |  13 +
 .../springboot/JBPMComponentConfiguration.java     |  13 +
 .../springboot/JCacheComponentConfiguration.java   |  13 +
 .../springboot/JcloudsComponentConfiguration.java  |  13 +
 .../jcr/springboot/JcrComponentConfiguration.java  |  13 +
 .../springboot/JdbcComponentConfiguration.java     |  13 +
 .../JettyHttpComponentConfiguration9.java          |  13 +
 .../JGroupsRaftComponentConfiguration.java         |  13 +
 .../springboot/JGroupsComponentConfiguration.java  |  13 +
 .../springboot/JingComponentConfiguration.java     |  13 +
 .../springboot/JiraComponentConfiguration.java     |  13 +
 .../jms/springboot/JmsComponentConfiguration.java  |  13 +
 .../jmx/springboot/JMXComponentConfiguration.java  |  13 +
 .../springboot/JoltComponentConfiguration.java     |  13 +
 .../springboot/JooqComponentConfiguration.java     |  13 +
 .../jpa/springboot/JpaComponentConfiguration.java  |  13 +
 .../scp/springboot/ScpComponentConfiguration.java  |  13 +
 .../JsonValidatorComponentConfiguration.java       |  13 +
 .../springboot/Jt400ComponentConfiguration.java    |  13 +
 .../springboot/KafkaComponentConfiguration.java    |  13 +
 ...KubernetesConfigMapsComponentConfiguration.java |  13 +
 ...ubernetesDeploymentsComponentConfiguration.java |  13 +
 .../KubernetesHPAComponentConfiguration.java       |  13 +
 .../KubernetesJobComponentConfiguration.java       |  13 +
 ...KubernetesNamespacesComponentConfiguration.java |  13 +
 .../KubernetesNodesComponentConfiguration.java     |  13 +
 ...tesPersistentVolumesComponentConfiguration.java |  13 +
 ...sistentVolumesClaimsComponentConfiguration.java |  13 +
 .../KubernetesPodsComponentConfiguration.java      |  13 +
 ...plicationControllersComponentConfiguration.java |  13 +
 ...rnetesResourcesQuotaComponentConfiguration.java |  13 +
 .../KubernetesSecretsComponentConfiguration.java   |  13 +
 ...netesServiceAccountsComponentConfiguration.java |  13 +
 .../KubernetesServicesComponentConfiguration.java  |  13 +
 ...penshiftBuildConfigsComponentConfiguration.java |  13 +
 .../OpenshiftBuildsComponentConfiguration.java     |  13 +
 .../springboot/LanguageComponentConfiguration.java |  13 +
 .../springboot/LdapComponentConfiguration.java     |  13 +
 .../springboot/LdifComponentConfiguration.java     |  13 +
 .../springboot/LinkedInComponentConfiguration.java |  13 +
 .../log/springboot/LogComponentConfiguration.java  |  13 +
 .../springboot/LuceneComponentConfiguration.java   |  13 +
 .../LumberjackComponentConfiguration.java          |  13 +
 .../springboot/MailComponentConfiguration.java     |  13 +
 .../springboot/MasterComponentConfiguration.java   |  13 +
 .../springboot/MetricsComponentConfiguration.java  |  13 +
 .../MicrometerComponentConfiguration.java          |  13 +
 .../MiloClientComponentConfiguration.java          |  13 +
 .../MiloServerComponentConfiguration.java          |  13 +
 .../springboot/Mina2ComponentConfiguration.java    |  13 +
 .../springboot/MllpComponentConfiguration.java     |  13 +
 .../springboot/MockComponentConfiguration.java     |  13 +
 .../springboot/GridFsComponentConfiguration.java   |  13 +
 .../springboot/MongoDbComponentConfiguration.java  |  13 +
 .../springboot/MQTTComponentConfiguration.java     |  13 +
 .../msv/springboot/MsvComponentConfiguration.java  |  13 +
 .../springboot/MustacheComponentConfiguration.java |  13 +
 .../springboot/MvelComponentConfiguration.java     |  13 +
 .../MyBatisBeanComponentConfiguration.java         |  13 +
 .../springboot/MyBatisComponentConfiguration.java  |  13 +
 .../springboot/NagiosComponentConfiguration.java   |  13 +
 .../springboot/NatsComponentConfiguration.java     |  13 +
 .../NettyHttpComponentConfiguration.java           |  13 +
 .../springboot/NettyComponentConfiguration.java    |  13 +
 .../nsq/springboot/NsqComponentConfiguration.java  |  13 +
 .../springboot/Olingo2ComponentConfiguration.java  |  13 +
 .../springboot/Olingo4ComponentConfiguration.java  |  13 +
 .../springboot/CinderComponentConfiguration.java   |  13 +
 .../springboot/GlanceComponentConfiguration.java   |  13 +
 .../springboot/KeystoneComponentConfiguration.java |  13 +
 .../springboot/NeutronComponentConfiguration.java  |  13 +
 .../springboot/NovaComponentConfiguration.java     |  13 +
 .../springboot/SwiftComponentConfiguration.java    |  13 +
 .../OptaPlannerComponentConfiguration.java         |  13 +
 .../springboot/PahoComponentConfiguration.java     |  13 +
 .../pdf/springboot/PdfComponentConfiguration.java  |  13 +
 .../springboot/PgEventComponentConfiguration.java  |  13 +
 .../springboot/PrinterComponentConfiguration.java  |  13 +
 .../PropertiesComponentConfiguration.java          |  13 +
 .../springboot/PubNubComponentConfiguration.java   |  13 +
 .../springboot/PulsarComponentConfiguration.java   |  13 +
 .../springboot/QuartzComponentConfiguration.java   |  13 +
 .../QuickfixjComponentConfiguration.java           |  13 +
 .../springboot/RabbitMQComponentConfiguration.java |  13 +
 .../ReactiveStreamsComponentConfiguration.java     |  13 +
 .../ref/springboot/RefComponentConfiguration.java  |  13 +
 .../springboot/RestApiComponentConfiguration.java  |  13 +
 .../springboot/RestComponentConfiguration.java     |  13 +
 .../RestSwaggerComponentConfiguration.java         |  13 +
 .../springboot/RestletComponentConfiguration.java  |  13 +
 .../rss/springboot/RssComponentConfiguration.java  |  13 +
 .../springboot/SagaComponentConfiguration.java     |  13 +
 .../SalesforceComponentConfiguration.java          |  13 +
 .../NetWeaverComponentConfiguration.java           |  13 +
 .../springboot/XQueryComponentConfiguration.java   |  13 +
 .../SchedulerComponentConfiguration.java           |  13 +
 .../SchematronComponentConfiguration.java          |  13 +
 .../springboot/SedaComponentConfiguration.java     |  13 +
 .../springboot/ServiceComponentConfiguration.java  |  13 +
 .../ServiceNowComponentConfiguration.java          |  13 +
 .../springboot/ServletComponentConfiguration.java  |  13 +
 .../sip/springboot/SipComponentConfiguration.java  |  13 +
 .../SjmsBatchComponentConfiguration.java           |  13 +
 .../springboot/SjmsComponentConfiguration.java     |  13 +
 .../springboot/Sjms2ComponentConfiguration.java    |  13 +
 .../springboot/SlackComponentConfiguration.java    |  13 +
 .../springboot/SmppComponentConfiguration.java     |  13 +
 .../springboot/SnmpComponentConfiguration.java     |  13 +
 .../springboot/SolrComponentConfiguration.java     |  13 +
 .../SoroushBotComponentConfiguration.java          |  13 +
 .../springboot/SparkComponentConfiguration.java    |  13 +
 .../springboot/SplunkComponentConfiguration.java   |  13 +
 .../SpringBatchComponentConfiguration.java         |  13 +
 .../SpringIntegrationComponentConfiguration.java   |  13 +
 .../SpringLdapComponentConfiguration.java          |  13 +
 .../springboot/RedisComponentConfiguration.java    |  13 +
 .../springboot/EventComponentConfiguration.java    |  13 +
 .../SpringWebserviceComponentConfiguration.java    |  13 +
 .../sql/springboot/SqlComponentConfiguration.java  |  13 +
 .../SqlStoredComponentConfiguration.java           |  13 +
 .../ssh/springboot/SshComponentConfiguration.java  |  13 +
 .../springboot/StAXComponentConfiguration.java     |  13 +
 .../springboot/StompComponentConfiguration.java    |  13 +
 .../springboot/StreamComponentConfiguration.java   |  13 +
 .../StringTemplateComponentConfiguration.java      |  13 +
 .../springboot/StubComponentConfiguration.java     |  13 +
 .../springboot/TelegramComponentConfiguration.java |  13 +
 .../springboot/ThriftComponentConfiguration.java   |  13 +
 .../springboot/TikaComponentConfiguration.java     |  13 +
 .../springboot/TimerComponentConfiguration.java    |  13 +
 .../springboot/TwilioComponentConfiguration.java   |  13 +
 ...TwitterDirectMessageComponentConfiguration.java |  13 +
 .../TwitterSearchComponentConfiguration.java       |  13 +
 .../TwitterStreamingComponentConfiguration.java    |  13 +
 .../TwitterTimelineComponentConfiguration.java     |  13 +
 .../springboot/UndertowComponentConfiguration.java |  13 +
 .../ValidatorComponentConfiguration.java           |  13 +
 .../springboot/VelocityComponentConfiguration.java |  13 +
 .../springboot/VertxComponentConfiguration.java    |  13 +
 .../vm/springboot/VmComponentConfiguration.java    |  13 +
 .../springboot/WeatherComponentConfiguration.java  |  13 +
 .../springboot/Web3jComponentConfiguration.java    |  13 +
 .../springboot/WebhookComponentConfiguration.java  |  13 +
 .../JSR356WebSocketComponentConfiguration.java     |  13 +
 .../WebsocketComponentConfiguration.java           |  13 +
 .../WordpressComponentConfiguration.java           |  13 +
 .../springboot/XChangeComponentConfiguration.java  |  13 +
 .../XmlSignatureComponentConfiguration.java        |  13 +
 .../springboot/XmppComponentConfiguration.java     |  13 +
 .../springboot/XsltComponentConfiguration.java     |  13 +
 .../springboot/YammerComponentConfiguration.java   |  13 +
 .../springboot/ZendeskComponentConfiguration.java  |  13 +
 .../springboot/MasterComponentConfiguration.java   |  13 +
 .../ZooKeeperComponentConfiguration.java           |  13 +
 924 files changed, 9996 insertions(+), 2045 deletions(-)
 copy core/camel-api/src/main/java/org/apache/camel/{InvalidPropertyException.java => PropertyBindingException.java} (55%)
 delete mode 100644 core/camel-core/src/test/java/org/apache/camel/impl/RegistryTest.java
 copy components/camel-restlet/src/test/java/org/apache/camel/component/restlet/UserPojo.java => core/camel-core/src/test/java/org/apache/camel/support/Company.java (94%)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportAutowireTest.java
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
 create mode 100644 core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java

Reply | Threaded
Open this post in threaded view
|

[camel] 01/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f2e24c802005649520e6971b776caa22643b6a8a
Author: Claus Ibsen <[hidden email]>
AuthorDate: Wed May 22 15:47:57 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../java/org/apache/camel/main/MainSupport.java    |  31 +----
 .../camel/support/PropertyBindingSupportTest.java  | 146 +++++++++++++++++++++
 .../apache/camel/support/IntrospectionSupport.java |  58 +++++++-
 .../camel/support/PropertyBindingSupport.java      |  47 +++++++
 4 files changed, 254 insertions(+), 28 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index 0f3570e..fedb2cd 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -81,10 +81,9 @@ import org.apache.camel.spi.StreamCachingStrategy;
 import org.apache.camel.spi.ThreadPoolProfile;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
-import org.apache.camel.support.DefaultExchange;
-import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.IntrospectionSupport;
 import org.apache.camel.support.LifecycleStrategySupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.support.jsse.GlobalSSLContextParametersSupplier;
 import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.support.service.ServiceSupport;
@@ -1261,6 +1260,8 @@ public abstract class MainSupport extends ServiceSupport {
                 Map<String, Object> properties = new LinkedHashMap<>();
                 IntrospectionSupport.getProperties(component, properties, null);
 
+                // TODO: Use PropertyBindingSupport to make it support this kind of use-case too
+
                 // lookup complex types
                 properties.forEach((k, v) -> {
                     // if the property has not been set and its a complex type (not simple or string etc)
@@ -1343,34 +1344,10 @@ public abstract class MainSupport extends ServiceSupport {
             String name = entry.getKey();
             Object value = entry.getValue();
 
-            // if the name has dot's then its an OGNL expressions (so lets use simple language to walk down this ognl path)
-            boolean ognl = name.contains(".");
-            if (ognl) {
-                Language method = context.resolveLanguage("simple");
-                String path = name.substring(0, name.lastIndexOf('.'));
-                Expression exp = method.createExpression("${body." + path + "}");
-                Exchange dummy = new DefaultExchange(context);
-                dummy.getMessage().setBody(target);
-                Object newTarget = exp.evaluate(dummy, Object.class);
-                if (newTarget != null) {
-                    target = newTarget;
-                    name = name.substring(name.lastIndexOf('.') + 1);
-                }
-            }
-
             String stringValue = value != null ? value.toString() : null;
-            boolean hit = false;
 
             LOG.debug("Setting property {} on {} with value {}", name, target, stringValue);
-            if (EndpointHelper.isReferenceParameter(stringValue)) {
-                hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, null, stringValue, true);
-            } else if (value != null) {
-                try {
-                    hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value);
-                } catch (IllegalArgumentException var12) {
-                    hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, null, stringValue, true);
-                }
-            }
+            boolean hit = PropertyBindingSupport.bindProperty(context, target, name, stringValue);
 
             if (hit) {
                 it.remove();
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
new file mode 100644
index 0000000..c55745f
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.junit.Test;
+
+/**
+ * Unit test for PropertyBindingSupport with nested properties
+ */
+public class PropertyBindingSupportTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        Company work = new Company();
+        work.setId(456);
+        work.setName("Acme");
+        context.getRegistry().bind("myWork", work);
+
+        return context;
+    }
+
+    @Test
+    public void testNested() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work.id", "123");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work.name", "Acme");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertEquals(123, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    @Test
+    public void testNestedReference() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#myWork");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertEquals(456, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    public static class Foo {
+        private String name;
+        private Bar bar = new Bar();
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public Bar getBar() {
+            return bar;
+        }
+
+        public void setBar(Bar bar) {
+            this.bar = bar;
+        }
+    }
+
+    public static class Bar {
+        private int age;
+        private boolean rider;
+        private Company work; // has no default value but Camel can automatic create one if there is a setter
+
+        public int getAge() {
+            return age;
+        }
+
+        public void setAge(int age) {
+            this.age = age;
+        }
+
+        public boolean isRider() {
+            return rider;
+        }
+
+        public void setRider(boolean rider) {
+            this.rider = rider;
+        }
+
+        public Company getWork() {
+            return work;
+        }
+
+        public void setWork(Company work) {
+            this.work = work;
+        }
+    }
+
+    public static class Company {
+        private int id;
+        private String name;
+
+        public int getId() {
+            return id;
+        }
+
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+}
+
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 55f2612..28a1e3f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -513,12 +513,68 @@ public final class IntrospectionSupport {
      * 2. Setting a property that has not yet been resolved, the property will be resolved based on the suitable methods
      * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
      * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
+     */
+    public static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
+                                      boolean allowBuilderPattern) throws Exception {
+        return setProperty(context, typeConverter, target, name, value, refName, allowBuilderPattern, false);
+    }
+    /**
+     * This method supports two modes to set a property:
+     *
+     * 1. Setting a property that has already been resolved, this is the case when {@code context} and {@code refName} are
+     * NULL and {@code value} is non-NULL.
      *
+     * 2. Setting a property that has not yet been resolved, the property will be resolved based on the suitable methods
+     * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
+     * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
      */
-    public static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName, boolean allowBuilderPattern) throws Exception {
+    public static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
+                                      boolean allowBuilderPattern, boolean allowNestedProperties) throws Exception {
         Class<?> clazz = target.getClass();
         Collection<Method> setters;
 
+        // if name has dot then we need to OGNL walk it
+        if (allowNestedProperties && name.indexOf('.') > 0) {
+            String[] parts = name.split("\\.");
+            Object newTarget = target;
+            Class<?> newClass = clazz;
+            // we should only iterate until until 2nd last so we use -1 in the for loop
+            for (int i = 0; i < parts.length - 1; i++) {
+                String part = parts[i];
+                Object prop = getOrElseProperty(newTarget, part, null);
+                if (prop == null) {
+                    // okay is there a setter so we can create a new instance and set it automatic
+                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
+                    if (newSetters.size() == 1) {
+                        Method method = newSetters.iterator().next();
+                        Class<?> parameterType = method.getParameterTypes()[0];
+                        if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
+                            Object instance = context.getInjector().newInstance(parameterType);
+                            if (instance != null) {
+                                org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance);
+                                newTarget = instance;
+                                newClass = newTarget.getClass();
+                            }
+                        }
+                    }
+                } else {
+                    newTarget = prop;
+                    newClass = newTarget.getClass();
+                }
+            }
+            // okay we found a nested property, then lets change to use that
+            target = newTarget;
+            clazz = newTarget.getClass();
+            name = parts[parts.length - 1];
+            if (value instanceof String) {
+                if (EndpointHelper.isReferenceParameter(value.toString())) {
+                    // okay its a reference so swap to lookup this
+                    refName = value.toString();
+                    value = null;
+                }
+            }
+        }
+
         // we need to lookup the value from the registry
         if (context != null && refName != null && value == null) {
             setters = findSetterMethodsOrderedByParameterType(clazz, name, allowBuilderPattern);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
new file mode 100644
index 0000000..b9d98bf
--- /dev/null
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import org.apache.camel.CamelContext;
+
+import java.util.Map;
+
+/**
+ * A convenient support class for binding String valued properties to an instance which
+ * uses a set of conventions:
+ * <ul>
+ *     <li>nested - Properties can be nested using the dot syntax (OGNL)</li>
+ *     <li>reference by id - Values can refer to other beans by their id using # syntax</li>
+ * </ul>
+ */
+public final class PropertyBindingSupport {
+
+    private PropertyBindingSupport() {
+    }
+
+    public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) throws Exception {
+        boolean answer = true;
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            answer &= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
+        }
+        return answer;
+    }
+
+    public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
+        return IntrospectionSupport.setProperty(camelContext, camelContext.getTypeConverter(), target, name, value, null, true, true);
+    }
+}

Reply | Threaded
Open this post in threaded view
|

[camel] 02/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 1863e5dcaa1ec1cd3228fb04ed59d4dd52d77598
Author: Claus Ibsen <[hidden email]>
AuthorDate: Wed May 22 21:53:23 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../apache/camel/support/IntrospectionSupport.java | 65 ++---------------
 .../camel/support/PropertyBindingSupport.java      | 84 ++++++++++++++++++++--
 2 files changed, 85 insertions(+), 64 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 28a1e3f..02d2f47 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -516,65 +516,10 @@ public final class IntrospectionSupport {
      */
     public static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
                                       boolean allowBuilderPattern) throws Exception {
-        return setProperty(context, typeConverter, target, name, value, refName, allowBuilderPattern, false);
-    }
-    /**
-     * This method supports two modes to set a property:
-     *
-     * 1. Setting a property that has already been resolved, this is the case when {@code context} and {@code refName} are
-     * NULL and {@code value} is non-NULL.
-     *
-     * 2. Setting a property that has not yet been resolved, the property will be resolved based on the suitable methods
-     * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
-     * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
-     */
-    public static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
-                                      boolean allowBuilderPattern, boolean allowNestedProperties) throws Exception {
+
         Class<?> clazz = target.getClass();
         Collection<Method> setters;
 
-        // if name has dot then we need to OGNL walk it
-        if (allowNestedProperties && name.indexOf('.') > 0) {
-            String[] parts = name.split("\\.");
-            Object newTarget = target;
-            Class<?> newClass = clazz;
-            // we should only iterate until until 2nd last so we use -1 in the for loop
-            for (int i = 0; i < parts.length - 1; i++) {
-                String part = parts[i];
-                Object prop = getOrElseProperty(newTarget, part, null);
-                if (prop == null) {
-                    // okay is there a setter so we can create a new instance and set it automatic
-                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
-                    if (newSetters.size() == 1) {
-                        Method method = newSetters.iterator().next();
-                        Class<?> parameterType = method.getParameterTypes()[0];
-                        if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
-                            Object instance = context.getInjector().newInstance(parameterType);
-                            if (instance != null) {
-                                org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance);
-                                newTarget = instance;
-                                newClass = newTarget.getClass();
-                            }
-                        }
-                    }
-                } else {
-                    newTarget = prop;
-                    newClass = newTarget.getClass();
-                }
-            }
-            // okay we found a nested property, then lets change to use that
-            target = newTarget;
-            clazz = newTarget.getClass();
-            name = parts[parts.length - 1];
-            if (value instanceof String) {
-                if (EndpointHelper.isReferenceParameter(value.toString())) {
-                    // okay its a reference so swap to lookup this
-                    refName = value.toString();
-                    value = null;
-                }
-            }
-        }
-
         // we need to lookup the value from the registry
         if (context != null && refName != null && value == null) {
             setters = findSetterMethodsOrderedByParameterType(clazz, name, allowBuilderPattern);
@@ -676,7 +621,7 @@ public final class IntrospectionSupport {
         }
     }
 
-    private static boolean isPropertyPlaceholder(CamelContext context, Object value) {
+    static boolean isPropertyPlaceholder(CamelContext context, Object value) {
         if (context != null) {
             PropertiesComponent pc = context.getPropertiesComponent(false);
             if (pc != null) {
@@ -711,7 +656,7 @@ public final class IntrospectionSupport {
         return setProperty(target, name, value, true);
     }
 
-    private static Object convert(TypeConverter typeConverter, Class<?> type, Object value)
+    static Object convert(TypeConverter typeConverter, Class<?> type, Object value)
         throws URISyntaxException, NoTypeConversionAvailableException {
         if (typeConverter != null) {
             return typeConverter.mandatoryConvertTo(type, value);
@@ -760,7 +705,7 @@ public final class IntrospectionSupport {
         return candidates;
     }
 
-    private static Set<Method> findSetterMethods(Class<?> clazz, String name, Object value, boolean allowBuilderPattern) {
+    static Set<Method> findSetterMethods(Class<?> clazz, String name, Object value, boolean allowBuilderPattern) {
         Set<Method> candidates = findSetterMethods(clazz, name, allowBuilderPattern);
 
         if (candidates.isEmpty()) {
@@ -786,7 +731,7 @@ public final class IntrospectionSupport {
         }
     }
 
-    protected static List<Method> findSetterMethodsOrderedByParameterType(Class<?> target, String propertyName, boolean allowBuilderPattern) {
+    static List<Method> findSetterMethodsOrderedByParameterType(Class<?> target, String propertyName, boolean allowBuilderPattern) {
         List<Method> answer = new LinkedList<>();
         List<Method> primitives = new LinkedList<>();
         Set<Method> setters = findSetterMethods(target, propertyName, allowBuilderPattern);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index b9d98bf..38b2d10 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -16,20 +16,34 @@
  */
 package org.apache.camel.support;
 
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
 import org.apache.camel.CamelContext;
+import org.apache.camel.TypeConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.util.Map;
+import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
+import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
 
 /**
  * A convenient support class for binding String valued properties to an instance which
  * uses a set of conventions:
  * <ul>
- *     <li>nested - Properties can be nested using the dot syntax (OGNL)</li>
- *     <li>reference by id - Values can refer to other beans by their id using # syntax</li>
+ *     <li>nested - Properties can be nested using the dot syntax (OGNL), eg foo.bar=123</li>
+ *     <li>reference by id - Values can refer to other beans in the registry by prefixing with # syntax, eg #myBean</li>
  * </ul>
+ * This implementations reuses parts of {@link IntrospectionSupport}.
  */
 public final class PropertyBindingSupport {
 
+    private static final Pattern SECRETS = Pattern.compile(".*(passphrase|password|secretKey).*", Pattern.CASE_INSENSITIVE);
+    private static final Logger LOG = LoggerFactory.getLogger(PropertyBindingSupport.class);
+
     private PropertyBindingSupport() {
     }
 
@@ -42,6 +56,68 @@ public final class PropertyBindingSupport {
     }
 
     public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
-        return IntrospectionSupport.setProperty(camelContext, camelContext.getTypeConverter(), target, name, value, null, true, true);
+        return setProperty(camelContext, camelContext.getTypeConverter(), target, name, value, null, true, true);
+    }
+
+    /**
+     * This method supports two modes to set a property:
+     *
+     * 1. Setting a property that has already been resolved, this is the case when {@code context} and {@code refName} are
+     * NULL and {@code value} is non-NULL.
+     *
+     * 2. Setting a property that has not yet been resolved, the property will be resolved based on the suitable methods
+     * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
+     * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
+     */
+    private static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
+                                      boolean allowBuilderPattern, boolean allowNestedProperties) throws Exception {
+        Class<?> clazz = target.getClass();
+        Collection<Method> setters;
+
+        // if name has dot then we need to OGNL walk it
+        if (allowNestedProperties && name.indexOf('.') > 0) {
+            String[] parts = name.split("\\.");
+            Object newTarget = target;
+            Class<?> newClass = clazz;
+            // we should only iterate until until 2nd last so we use -1 in the for loop
+            for (int i = 0; i < parts.length - 1; i++) {
+                String part = parts[i];
+                Object prop = getOrElseProperty(newTarget, part, null);
+                if (prop == null) {
+                    // okay is there a setter so we can create a new instance and set it automatic
+                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
+                    if (newSetters.size() == 1) {
+                        Method method = newSetters.iterator().next();
+                        Class<?> parameterType = method.getParameterTypes()[0];
+                        if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
+                            Object instance = context.getInjector().newInstance(parameterType);
+                            if (instance != null) {
+                                org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance);
+                                newTarget = instance;
+                                newClass = newTarget.getClass();
+                            }
+                        }
+                    }
+                } else {
+                    newTarget = prop;
+                    newClass = newTarget.getClass();
+                }
+            }
+            // okay we found a nested property, then lets change to use that
+            target = newTarget;
+            clazz = newTarget.getClass();
+            name = parts[parts.length - 1];
+            if (value instanceof String) {
+                if (EndpointHelper.isReferenceParameter(value.toString())) {
+                    // okay its a reference so swap to lookup this
+                    refName = value.toString();
+                    value = null;
+                }
+            }
+        }
+
+        // TODO: At this point we can likely just call IntrospectionSupport directly
+        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
     }
+
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 03/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5bccb7fad7df2f9547431097ed13d535b6c84e7d
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 04:48:20 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../src/main/java/org/apache/camel/support/PropertyBindingSupport.java | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 38b2d10..85a98a1 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -41,6 +41,9 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  */
 public final class PropertyBindingSupport {
 
+    // TODO: Add support for auto binding to singleton instance by type from registry (boolean on|off)
+    // TODO: builder pattern with naming prefix: withXXX
+
     private static final Pattern SECRETS = Pattern.compile(".*(passphrase|password|secretKey).*", Pattern.CASE_INSENSITIVE);
     private static final Logger LOG = LoggerFactory.getLogger(PropertyBindingSupport.class);
 

Reply | Threaded
Open this post in threaded view
|

[camel] 04/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 21f7433b2a3b89ffa65dad9bc66d818d4c89176c
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 06:03:42 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../camel/support/IntrospectionSupportTest.java    | 90 +++++++++++++++++++++-
 .../camel/support/PropertyBindingSupportTest.java  | 13 ++++
 .../apache/camel/support/IntrospectionSupport.java | 21 +++--
 .../camel/support/PropertyBindingSupport.java      | 21 ++---
 4 files changed, 122 insertions(+), 23 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
index b2b87f5..874fe41 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
@@ -134,7 +134,95 @@ public class IntrospectionSupportTest extends ContextTestSupport {
             return this;
         }
     }
-    
+
+    @Test
+    public void testBuilderPatternWith() throws Exception {
+        MyBuilderPatternWithBean builderBean = new MyBuilderPatternWithBean();
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "name", "Donald");
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "age", "33");
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "gold-customer", "true");
+        assertEquals("Donald", builderBean.getName());
+        assertEquals(33, builderBean.getAge());
+        assertTrue(builderBean.isGoldCustomer());
+    }
+
+    public class MyBuilderPatternWithBean {
+        private String name;
+        private int age;
+        private boolean goldCustomer;
+
+        public MyBuilderPatternWithBean withName(String name) {
+            this.name = name;
+            return this;
+        }
+
+        public MyBuilderPatternWithBean withAge(int age) {
+            this.age = age;
+            return this;
+        }
+
+        public MyBuilderPatternWithBean withGoldCustomer(boolean goldCustomer) {
+            this.goldCustomer = goldCustomer;
+            return this;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public boolean isGoldCustomer() {
+            return goldCustomer;
+        }
+    }
+
+    @Test
+    public void testBuilderPattern() throws Exception {
+        MyBuilderPatternBean builderBean = new MyBuilderPatternBean();
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "name", "Goofy");
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "age", "34");
+        IntrospectionSupport.setProperty(context.getTypeConverter(), builderBean, "gold-customer", "true");
+        assertEquals("Goofy", builderBean.getName());
+        assertEquals(34, builderBean.getAge());
+        assertTrue(builderBean.isGoldCustomer());
+    }
+
+    public class MyBuilderPatternBean {
+        private String name;
+        private int age;
+        private boolean goldCustomer;
+
+        public MyBuilderPatternBean name(String name) {
+            this.name = name;
+            return this;
+        }
+
+        public MyBuilderPatternBean age(int age) {
+            this.age = age;
+            return this;
+        }
+
+        public MyBuilderPatternBean goldCustomer(boolean goldCustomer) {
+            this.goldCustomer = goldCustomer;
+            return this;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public boolean isGoldCustomer() {
+            return goldCustomer;
+        }
+    }
+
     @Test
     public void testIsSetterBuilderPatternSupport() throws Exception {
         Method setter = MyBuilderBean.class.getMethod("setName", String.class);
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index c55745f..86118be 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -44,12 +44,14 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         PropertyBindingSupport.bindProperty(context, foo, "name", "James");
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
         PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.work.id", "123");
         PropertyBindingSupport.bindProperty(context, foo, "bar.work.name", "Acme");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
         assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
         assertEquals(123, foo.getBar().getWork().getId());
         assertEquals("Acme", foo.getBar().getWork().getName());
     }
@@ -60,12 +62,14 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
 
         PropertyBindingSupport.bindProperty(context, foo, "name", "James");
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#myWork");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
         assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
         assertEquals(456, foo.getBar().getWork().getId());
         assertEquals("Acme", foo.getBar().getWork().getName());
     }
@@ -95,6 +99,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         private int age;
         private boolean rider;
         private Company work; // has no default value but Camel can automatic create one if there is a setter
+        private boolean goldCustomer;
 
         public int getAge() {
             return age;
@@ -119,6 +124,14 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         public void setWork(Company work) {
             this.work = work;
         }
+
+        public boolean isGoldCustomer() {
+            return goldCustomer;
+        }
+
+        public void setGoldCustomer(boolean goldCustomer) {
+            this.goldCustomer = goldCustomer;
+        }
     }
 
     public static class Company {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 02d2f47..8e4ea5f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -195,9 +195,14 @@ public final class IntrospectionSupport {
         Class<?> type = method.getReturnType();
         int parameterCount = method.getParameterCount();
 
-        // is it a getXXX method
-        if (name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3))) {
-            return parameterCount == 1 && (type.equals(Void.TYPE) || (allowBuilderPattern && method.getDeclaringClass().isAssignableFrom(type)));
+        // is it a setXXX method
+        boolean validName = name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3));
+        if (validName) {
+            return parameterCount == 1 && type.equals(Void.TYPE);
+        }
+        // or if its a builder method
+        if (allowBuilderPattern && parameterCount == 1 && method.getDeclaringClass().isAssignableFrom(type)) {
+            return true;
         }
 
         return false;
@@ -680,15 +685,19 @@ public final class IntrospectionSupport {
     public static Set<Method> findSetterMethods(Class<?> clazz, String name, boolean allowBuilderPattern) {
         Set<Method> candidates = new LinkedHashSet<>();
 
-        // Build the method name.
-        name = "set" + StringHelper.capitalize(name, true);
+        // Build the method name
+        String builderName = "with" + StringHelper.capitalize(name, true);
+        String builderName2 = StringHelper.capitalize(name, true);
+        builderName2 = Character.toLowerCase(builderName2.charAt(0)) + builderName2.substring(1);
+        String setName = "set" + StringHelper.capitalize(name, true);
         while (clazz != Object.class) {
             // Since Object.class.isInstance all the objects,
             // here we just make sure it will be add to the bottom of the set.
             Method objectSetMethod = null;
             Method[] methods = clazz.getMethods();
             for (Method method : methods) {
-                if (method.getName().equals(name) && isSetter(method, allowBuilderPattern)) {
+                boolean validName = method.getName().equals(setName) || allowBuilderPattern && method.getName().equals(builderName) || allowBuilderPattern && method.getName().equals(builderName2);
+                if (validName && isSetter(method, allowBuilderPattern)) {
                     Class<?>[] params = method.getParameterTypes();
                     if (params[0].equals(Object.class)) {
                         objectSetMethod = method;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 85a98a1..66bb0b4 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -17,15 +17,10 @@
 package org.apache.camel.support;
 
 import java.lang.reflect.Method;
-import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
-import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.TypeConverter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
 import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
@@ -34,7 +29,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  * A convenient support class for binding String valued properties to an instance which
  * uses a set of conventions:
  * <ul>
- *     <li>nested - Properties can be nested using the dot syntax (OGNL), eg foo.bar=123</li>
+ *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
  *     <li>reference by id - Values can refer to other beans in the registry by prefixing with # syntax, eg #myBean</li>
  * </ul>
  * This implementations reuses parts of {@link IntrospectionSupport}.
@@ -42,10 +37,6 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
 public final class PropertyBindingSupport {
 
     // TODO: Add support for auto binding to singleton instance by type from registry (boolean on|off)
-    // TODO: builder pattern with naming prefix: withXXX
-
-    private static final Pattern SECRETS = Pattern.compile(".*(passphrase|password|secretKey).*", Pattern.CASE_INSENSITIVE);
-    private static final Logger LOG = LoggerFactory.getLogger(PropertyBindingSupport.class);
 
     private PropertyBindingSupport() {
     }
@@ -59,7 +50,7 @@ public final class PropertyBindingSupport {
     }
 
     public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
-        return setProperty(camelContext, camelContext.getTypeConverter(), target, name, value, null, true, true);
+        return setProperty(camelContext, target, name, value, null, true, true);
     }
 
     /**
@@ -72,10 +63,9 @@ public final class PropertyBindingSupport {
      * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
      * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
      */
-    private static boolean setProperty(CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
+    private static boolean setProperty(CamelContext context, Object target, String name, Object value, String refName,
                                       boolean allowBuilderPattern, boolean allowNestedProperties) throws Exception {
         Class<?> clazz = target.getClass();
-        Collection<Method> setters;
 
         // if name has dot then we need to OGNL walk it
         if (allowNestedProperties && name.indexOf('.') > 0) {
@@ -88,7 +78,7 @@ public final class PropertyBindingSupport {
                 Object prop = getOrElseProperty(newTarget, part, null);
                 if (prop == null) {
                     // okay is there a setter so we can create a new instance and set it automatic
-                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
+                    Set<Method> newSetters = findSetterMethods(newClass, part, allowBuilderPattern);
                     if (newSetters.size() == 1) {
                         Method method = newSetters.iterator().next();
                         Class<?> parameterType = method.getParameterTypes()[0];
@@ -119,8 +109,7 @@ public final class PropertyBindingSupport {
             }
         }
 
-        // TODO: At this point we can likely just call IntrospectionSupport directly
-        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
+        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, allowBuilderPattern);
     }
 
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 05/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d4972be9a0416dffa77bcc169c60dbe5c887bde3
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 06:17:11 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../src/main/java/org/apache/camel/support/IntrospectionSupport.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 8e4ea5f..3585940 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -197,8 +197,9 @@ public final class IntrospectionSupport {
 
         // is it a setXXX method
         boolean validName = name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3));
-        if (validName) {
-            return parameterCount == 1 && type.equals(Void.TYPE);
+        if (validName && parameterCount == 1) {
+            // a setXXX can also be a builder pattern so check for its return type is itself
+            return type.equals(Void.TYPE) || allowBuilderPattern && method.getDeclaringClass().isAssignableFrom(type);
         }
         // or if its a builder method
         if (allowBuilderPattern && parameterCount == 1 && method.getDeclaringClass().isAssignableFrom(type)) {

Reply | Threaded
Open this post in threaded view
|

[camel] 06/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 9af09b9676e3c6364f048b71ce2597df09d028ce
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 06:38:33 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../java/org/apache/camel/main/MainSupport.java    |  2 +
 .../camel/support/PropertyBindingSupportTest.java  | 37 +++++++++++--
 .../camel/support/PropertyBindingSupport.java      | 61 +++++++++++++++-------
 3 files changed, 78 insertions(+), 22 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index fedb2cd..4a249dc 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -1261,6 +1261,8 @@ public abstract class MainSupport extends ServiceSupport {
                 IntrospectionSupport.getProperties(component, properties, null);
 
                 // TODO: Use PropertyBindingSupport to make it support this kind of use-case too
+                // TODO: Allow nested properties too
+                // TODO: Allow fluent builders
 
                 // lookup complex types
                 properties.forEach((k, v) -> {
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index 86118be..3f28037 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -16,12 +16,16 @@
  */
 package org.apache.camel.support;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.junit.Test;
 
 /**
- * Unit test for PropertyBindingSupport with nested properties
+ * Unit test for PropertyBindingSupport
  */
 public class PropertyBindingSupportTest extends ContextTestSupport {
 
@@ -34,19 +38,46 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         work.setName("Acme");
         context.getRegistry().bind("myWork", work);
 
+        Properties placeholders = new Properties();
+        placeholders.put("companyName", "Acme");
+        placeholders.put("committer", "rider");
+        context.getPropertiesComponent().setInitialProperties(placeholders);
+
         return context;
     }
 
     @Test
+    public void testProperties() throws Exception {
+        Foo foo = new Foo();
+
+        Map<String, Object> prop = new HashMap<>();
+        prop.put("name", "James");
+        prop.put("bar.age", "33");
+        prop.put("bar.{{committer}}", "true");
+        prop.put("bar.gold-customer", "true");
+        prop.put("bar.work.id", "123");
+        prop.put("bar.work.name", "{{companyName}}");
+
+        PropertyBindingSupport.bindProperties(context, foo, prop);
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+        assertEquals(123, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    @Test
     public void testNested() throws Exception {
         Foo foo = new Foo();
 
         PropertyBindingSupport.bindProperty(context, foo, "name", "James");
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
-        PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.{{committer}}", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.work.id", "123");
-        PropertyBindingSupport.bindProperty(context, foo, "bar.work.name", "Acme");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work.name", "{{companyName}}");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 66bb0b4..d9bfb03 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
 
 import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
 import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
@@ -29,6 +30,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  * A convenient support class for binding String valued properties to an instance which
  * uses a set of conventions:
  * <ul>
+ *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
  *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
  *     <li>reference by id - Values can refer to other beans in the registry by prefixing with # syntax, eg #myBean</li>
  * </ul>
@@ -41,34 +43,52 @@ public final class PropertyBindingSupport {
     private PropertyBindingSupport() {
     }
 
+    /**
+     * Binds the properties to the target object.
+     *
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @param properties    the properties
+     * @return              true if one or more properties was bound, false otherwise
+     */
     public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) throws Exception {
-        boolean answer = true;
+        boolean answer = false;
         for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            answer &= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
+            answer |= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
         }
         return answer;
     }
 
-    public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
-        return setProperty(camelContext, target, name, value, null, true, true);
-    }
-
     /**
-     * This method supports two modes to set a property:
-     *
-     * 1. Setting a property that has already been resolved, this is the case when {@code context} and {@code refName} are
-     * NULL and {@code value} is non-NULL.
+     * Binds the property to the target object.
      *
-     * 2. Setting a property that has not yet been resolved, the property will be resolved based on the suitable methods
-     * found matching the property name on the {@code target} bean. For this mode to be triggered the parameters
-     * {@code context} and {@code refName} must NOT be NULL, and {@code value} MUST be NULL.
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @param name          name of property
+     * @param value         value of property
+     * @return              true if property was bound, false otherwise
      */
-    private static boolean setProperty(CamelContext context, Object target, String name, Object value, String refName,
-                                      boolean allowBuilderPattern, boolean allowNestedProperties) throws Exception {
+    public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
+        if (target != null && name != null) {
+            return setProperty(camelContext, target, name, value);
+        } else {
+            return false;
+        }
+    }
+
+    private static boolean setProperty(CamelContext context, Object target, String name, Object value) {
         Class<?> clazz = target.getClass();
+        String refName = null;
+
+        // resolve property placeholders
+        name = context.resolvePropertyPlaceholders(name);
+        if (value instanceof String) {
+            // resolve property placeholders
+            value = context.resolvePropertyPlaceholders(value.toString());
+        }
 
         // if name has dot then we need to OGNL walk it
-        if (allowNestedProperties && name.indexOf('.') > 0) {
+        if (name.indexOf('.') > 0) {
             String[] parts = name.split("\\.");
             Object newTarget = target;
             Class<?> newClass = clazz;
@@ -78,7 +98,7 @@ public final class PropertyBindingSupport {
                 Object prop = getOrElseProperty(newTarget, part, null);
                 if (prop == null) {
                     // okay is there a setter so we can create a new instance and set it automatic
-                    Set<Method> newSetters = findSetterMethods(newClass, part, allowBuilderPattern);
+                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
                     if (newSetters.size() == 1) {
                         Method method = newSetters.iterator().next();
                         Class<?> parameterType = method.getParameterTypes()[0];
@@ -98,7 +118,6 @@ public final class PropertyBindingSupport {
             }
             // okay we found a nested property, then lets change to use that
             target = newTarget;
-            clazz = newTarget.getClass();
             name = parts[parts.length - 1];
             if (value instanceof String) {
                 if (EndpointHelper.isReferenceParameter(value.toString())) {
@@ -109,7 +128,11 @@ public final class PropertyBindingSupport {
             }
         }
 
-        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, allowBuilderPattern);
+        try {
+            return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
+        } catch (Exception e) {
+            throw RuntimeCamelException.wrapRuntimeException(e);
+        }
     }
 
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 07/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f301f09759a063e0c26613a5a4eb14d79391abdb
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 07:15:32 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../java/org/apache/camel/support/Company.java     | 38 ++++++++++++++
 .../camel/support/PropertyBindingSupportTest.java  | 58 ++++++++++++++--------
 .../camel/support/PropertyBindingSupport.java      | 38 +++++++++++---
 3 files changed, 106 insertions(+), 28 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/Company.java b/core/camel-core/src/test/java/org/apache/camel/support/Company.java
new file mode 100644
index 0000000..1f5caba
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/support/Company.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+public class Company {
+    private int id;
+    private String name;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index 3f28037..e6e4245 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -105,6 +105,43 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         assertEquals("Acme", foo.getBar().getWork().getName());
     }
 
+    @Test
+    public void testNestedType() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.{{committer}}", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#type:org.apache.camel.support.Company");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+        assertEquals(456, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    @Test
+    public void testNestedClass() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.{{committer}}", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "class:org.apache.camel.support.Company");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+        // a new class was created so its empty
+        assertEquals(0, foo.getBar().getWork().getId());
+        assertEquals(null, foo.getBar().getWork().getName());
+    }
+
     public static class Foo {
         private String name;
         private Bar bar = new Bar();
@@ -165,26 +202,5 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         }
     }
 
-    public static class Company {
-        private int id;
-        private String name;
-
-        public int getId() {
-            return id;
-        }
-
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-    }
-
 }
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index d9bfb03..1577b14 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -33,12 +33,15 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
  *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
  *     <li>reference by id - Values can refer to other beans in the registry by prefixing with # syntax, eg #myBean</li>
+ *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
+ *     <li>new class - Values can refer to creating new beans by their class name syntax, eg class:com.foo.MyClassType</li>
  * </ul>
  * This implementations reuses parts of {@link IntrospectionSupport}.
  */
 public final class PropertyBindingSupport {
 
     // TODO: Add support for auto binding to singleton instance by type from registry (boolean on|off)
+    // TODO: Better exception message if something goes wrong (output target, name of property etc)
 
     private PropertyBindingSupport() {
     }
@@ -117,14 +120,35 @@ public final class PropertyBindingSupport {
                 }
             }
             // okay we found a nested property, then lets change to use that
-            target = newTarget;
-            name = parts[parts.length - 1];
-            if (value instanceof String) {
-                if (EndpointHelper.isReferenceParameter(value.toString())) {
-                    // okay its a reference so swap to lookup this
-                    refName = value.toString();
-                    value = null;
+            try {
+                target = newTarget;
+                name = parts[parts.length - 1];
+                if (value instanceof String) {
+                    if (value.toString().startsWith("class:")) {
+                        // its a new class to be created
+                        String className = value.toString().substring(6);
+                        Class<?> type = context.getClassResolver().resolveMandatoryClass(className);
+                        if (type != null) {
+                            value = context.getInjector().newInstance(type);
+                        }
+                    } else if (value.toString().startsWith("#type:")) {
+                        // its reference by type, so lookup the actual value and use it if there is only one instance in the registry
+                        String typeName = value.toString().substring(6);
+                        Class<?> type = context.getClassResolver().resolveMandatoryClass(typeName);
+                        if (type != null) {
+                            Set<?> types = context.getRegistry().findByType(type);
+                            if (types.size() == 1) {
+                                value = types.iterator().next();
+                            }
+                        }
+                    } else if (EndpointHelper.isReferenceParameter(value.toString())) {
+                        // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
+                        refName = value.toString();
+                        value = null;
+                    }
                 }
+            } catch (Exception e) {
+                throw RuntimeCamelException.wrapRuntimeException(e);
             }
         }
 

Reply | Threaded
Open this post in threaded view
|

[camel] 08/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 91765b481b2d80438850f512b27288ef4b7f5b0a
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 07:54:29 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../org/apache/camel/PropertyBindingException.java |  46 +++++++++
 .../camel/support/PropertyBindingSupportTest.java  |  19 ++++
 .../camel/support/PropertyBindingSupport.java      | 114 ++++++++++++---------
 3 files changed, 131 insertions(+), 48 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java b/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java
new file mode 100644
index 0000000..ed6e61b
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel;
+
+/**
+ * Error binding property to a bean.
+ */
+public class PropertyBindingException extends RuntimeCamelException {
+
+    private final Object target;
+    private final String propertyName;
+
+    public PropertyBindingException(Object target, String propertyName) {
+        super("No such property: " + propertyName + " on bean: " + target);
+        this.target = target;
+        this.propertyName = propertyName;
+    }
+
+    public PropertyBindingException(Object target, String propertyName, Exception e) {
+        super("Error binding property: " + propertyName + " on bean: " + target, e);
+        this.target = target;
+        this.propertyName = propertyName;
+    }
+
+    public Object getTarget() {
+        return target;
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index e6e4245..b3f32c7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -22,6 +22,7 @@ import java.util.Properties;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.PropertyBindingException;
 import org.junit.Test;
 
 /**
@@ -142,6 +143,24 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         assertEquals(null, foo.getBar().getWork().getName());
     }
 
+    @Test
+    public void testMandatory() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindMandatoryProperty(context, foo, "name", "James");
+
+        boolean bound = PropertyBindingSupport.bindProperty(context, foo, "bar.myAge", "33");
+        assertFalse(bound);
+
+        try {
+            PropertyBindingSupport.bindMandatoryProperty(context, foo, "bar.myAge", "33");
+            fail("Should have thrown exception");
+        } catch (PropertyBindingException e) {
+            assertEquals("bar.myAge", e.getPropertyName());
+            assertSame(foo, e.getTarget());
+        }
+    }
+
     public static class Foo {
         private String name;
         private Bar bar = new Bar();
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 1577b14..5d06df4 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -1,13 +1,13 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.PropertyBindingException;
 
 import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
 import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
@@ -41,7 +41,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
 public final class PropertyBindingSupport {
 
     // TODO: Add support for auto binding to singleton instance by type from registry (boolean on|off)
-    // TODO: Better exception message if something goes wrong (output target, name of property etc)
+    // TODO: Add support for Map/List
 
     private PropertyBindingSupport() {
     }
@@ -52,12 +52,12 @@ public final class PropertyBindingSupport {
      * @param camelContext  the camel context
      * @param target        the target object
      * @param properties    the properties
-     * @return              true if one or more properties was bound, false otherwise
+     * @return              true if all the properties was bound, false otherwise
      */
-    public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) throws Exception {
-        boolean answer = false;
+    public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) {
+        boolean answer = true;
         for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            answer |= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
+            answer &= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
         }
         return answer;
     }
@@ -71,15 +71,40 @@ public final class PropertyBindingSupport {
      * @param value         value of property
      * @return              true if property was bound, false otherwise
      */
-    public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) throws Exception {
-        if (target != null && name != null) {
-            return setProperty(camelContext, target, name, value);
-        } else {
-            return false;
+    public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) {
+        try {
+            if (target != null && name != null) {
+                return setProperty(camelContext, target, name, value);
+            }
+        } catch (Exception e) {
+            throw new PropertyBindingException(target, name, e);
         }
+
+        return false;
     }
 
-    private static boolean setProperty(CamelContext context, Object target, String name, Object value) {
+    /**
+     * Binds the mandatory property to the target object (will fail if not set/bound).
+     *
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @param name          name of property
+     * @param value         value of property
+     */
+    public static void bindMandatoryProperty(CamelContext camelContext, Object target, String name, Object value) {
+        try {
+            if (target != null && name != null) {
+                boolean bound = setProperty(camelContext, target, name, value);
+                if (!bound) {
+                    throw new PropertyBindingException(target, name);
+                }
+            }
+        } catch (Exception e) {
+            throw new PropertyBindingException(target, name, e);
+        }
+    }
+
+    private static boolean setProperty(CamelContext context, Object target, String name, Object value) throws Exception {
         Class<?> clazz = target.getClass();
         String refName = null;
 
@@ -120,43 +145,36 @@ public final class PropertyBindingSupport {
                 }
             }
             // okay we found a nested property, then lets change to use that
-            try {
-                target = newTarget;
-                name = parts[parts.length - 1];
-                if (value instanceof String) {
-                    if (value.toString().startsWith("class:")) {
-                        // its a new class to be created
-                        String className = value.toString().substring(6);
-                        Class<?> type = context.getClassResolver().resolveMandatoryClass(className);
-                        if (type != null) {
-                            value = context.getInjector().newInstance(type);
-                        }
-                    } else if (value.toString().startsWith("#type:")) {
-                        // its reference by type, so lookup the actual value and use it if there is only one instance in the registry
-                        String typeName = value.toString().substring(6);
-                        Class<?> type = context.getClassResolver().resolveMandatoryClass(typeName);
-                        if (type != null) {
-                            Set<?> types = context.getRegistry().findByType(type);
-                            if (types.size() == 1) {
-                                value = types.iterator().next();
-                            }
-                        }
-                    } else if (EndpointHelper.isReferenceParameter(value.toString())) {
-                        // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
-                        refName = value.toString();
-                        value = null;
+            target = newTarget;
+            name = parts[parts.length - 1];
+        }
+
+        if (value instanceof String) {
+            if (value.toString().startsWith("class:")) {
+                // its a new class to be created
+                String className = value.toString().substring(6);
+                Class<?> type = context.getClassResolver().resolveMandatoryClass(className);
+                if (type != null) {
+                    value = context.getInjector().newInstance(type);
+                }
+            } else if (value.toString().startsWith("#type:")) {
+                // its reference by type, so lookup the actual value and use it if there is only one instance in the registry
+                String typeName = value.toString().substring(6);
+                Class<?> type = context.getClassResolver().resolveMandatoryClass(typeName);
+                if (type != null) {
+                    Set<?> types = context.getRegistry().findByType(type);
+                    if (types.size() == 1) {
+                        value = types.iterator().next();
                     }
                 }
-            } catch (Exception e) {
-                throw RuntimeCamelException.wrapRuntimeException(e);
+            } else if (EndpointHelper.isReferenceParameter(value.toString())) {
+                // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
+                refName = value.toString();
+                value = null;
             }
         }
 
-        try {
-            return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
-        } catch (Exception e) {
-            throw RuntimeCamelException.wrapRuntimeException(e);
-        }
+        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
     }
 
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 09/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6113385992353e4311c64df11e1ffb1c9430dd1d
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 09:57:29 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../camel/support/PropertyBindingSupportTest.java    | 20 +++++++++++++++++++-
 .../apache/camel/support/PropertyBindingSupport.java |  8 ++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index b3f32c7..bce0ad0 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -107,6 +107,24 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
     }
 
     @Test
+    public void testNestedReferenceId() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#id:myWork");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+        assertEquals(456, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    @Test
     public void testNestedType() throws Exception {
         Foo foo = new Foo();
 
@@ -132,7 +150,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
         PropertyBindingSupport.bindProperty(context, foo, "bar.{{committer}}", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
-        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "class:org.apache.camel.support.Company");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#class:org.apache.camel.support.Company");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 5d06df4..6765233 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -32,7 +32,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  * <ul>
  *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
  *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
- *     <li>reference by id - Values can refer to other beans in the registry by prefixing with # syntax, eg #myBean</li>
+ *     <li>reference by id - Values can refer to other beans in the registry by prefixing with #id: or # syntax, eg #id:myBean or #myBean</li>
  *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
  *     <li>new class - Values can refer to creating new beans by their class name syntax, eg class:com.foo.MyClassType</li>
  * </ul>
@@ -150,7 +150,7 @@ public final class PropertyBindingSupport {
         }
 
         if (value instanceof String) {
-            if (value.toString().startsWith("class:")) {
+            if (value.toString().startsWith("#class:")) {
                 // its a new class to be created
                 String className = value.toString().substring(6);
                 Class<?> type = context.getClassResolver().resolveMandatoryClass(className);
@@ -167,6 +167,10 @@ public final class PropertyBindingSupport {
                         value = types.iterator().next();
                     }
                 }
+            } else if (value.toString().startsWith("#id:")) {
+                // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
+                refName = ((String) value).substring(4);
+                value = null;
             } else if (EndpointHelper.isReferenceParameter(value.toString())) {
                 // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
                 refName = value.toString();

Reply | Threaded
Open this post in threaded view
|

[camel] 10/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 992273fe180eb2194043220c30b2058f9ff43e33
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 10:12:14 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../camel/support/PropertyBindingSupportTest.java  | 18 +++++++++++
 .../camel/support/PropertyBindingSupport.java      | 35 ++++++++++++++++++++--
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index bce0ad0..35bfadf 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -162,6 +162,24 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
     }
 
     @Test
+    public void testAutowire() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.{{committer}}", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#autowire");
+
+        assertEquals("James", foo.getName());
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+        assertEquals(456, foo.getBar().getWork().getId());
+        assertEquals("Acme", foo.getBar().getWork().getName());
+    }
+
+    @Test
     public void testMandatory() throws Exception {
         Foo foo = new Foo();
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 6765233..453e5b0 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -34,19 +34,34 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
  *     <li>reference by id - Values can refer to other beans in the registry by prefixing with #id: or # syntax, eg #id:myBean or #myBean</li>
  *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
+ *     <li>autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowire</li>
  *     <li>new class - Values can refer to creating new beans by their class name syntax, eg class:com.foo.MyClassType</li>
  * </ul>
  * This implementations reuses parts of {@link IntrospectionSupport}.
  */
 public final class PropertyBindingSupport {
 
-    // TODO: Add support for auto binding to singleton instance by type from registry (boolean on|off)
     // TODO: Add support for Map/List
 
     private PropertyBindingSupport() {
     }
 
     /**
+     * This will discover all the properties on the target, and automatic bind the properties that are null by
+     * looking up in the registry to see if there is a single instance of the same type as the property.
+     * This is used for convention over configuration to automatic configure resources such as DataSource, Amazon Logins and
+     * so on.
+     *
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @return              true if one ore more properties was auto wired
+     */
+    public static boolean autowireSingletonPropertiesFromRegistry(CamelContext camelContext, Object target) {
+        // TODO: implement me
+        return false;
+    }
+
+    /**
      * Binds the properties to the target object.
      *
      * @param camelContext  the camel context
@@ -105,7 +120,6 @@ public final class PropertyBindingSupport {
     }
 
     private static boolean setProperty(CamelContext context, Object target, String name, Object value) throws Exception {
-        Class<?> clazz = target.getClass();
         String refName = null;
 
         // resolve property placeholders
@@ -119,7 +133,7 @@ public final class PropertyBindingSupport {
         if (name.indexOf('.') > 0) {
             String[] parts = name.split("\\.");
             Object newTarget = target;
-            Class<?> newClass = clazz;
+            Class<?> newClass = target.getClass();
             // we should only iterate until until 2nd last so we use -1 in the for loop
             for (int i = 0; i < parts.length - 1; i++) {
                 String part = parts[i];
@@ -127,6 +141,7 @@ public final class PropertyBindingSupport {
                 if (prop == null) {
                     // okay is there a setter so we can create a new instance and set it automatic
                     Set<Method> newSetters = findSetterMethods(newClass, part, true);
+                    // TODO: you may have setter + fluent builder at the same time, so grab setter first, and fallback to fluent builder afterwards
                     if (newSetters.size() == 1) {
                         Method method = newSetters.iterator().next();
                         Class<?> parameterType = method.getParameterTypes()[0];
@@ -167,6 +182,20 @@ public final class PropertyBindingSupport {
                         value = types.iterator().next();
                     }
                 }
+            } else if (value.toString().equals("#autowire")) {
+                // we should get the type from the setter
+                // TODO: you may have setter + fluent builder at the same time, so grab setter first, and fallback to fluent builder afterwards
+                Set<Method> newSetters = findSetterMethods(target.getClass(), name, true);
+                if (newSetters.size() == 1) {
+                    Method method = newSetters.iterator().next();
+                    Class<?> parameterType = method.getParameterTypes()[0];
+                    if (parameterType != null) {
+                        Set<?> types = context.getRegistry().findByType(parameterType);
+                        if (types.size() == 1) {
+                            value = types.iterator().next();
+                        }
+                    }
+                }
             } else if (value.toString().startsWith("#id:")) {
                 // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
                 refName = ((String) value).substring(4);

Reply | Threaded
Open this post in threaded view
|

[camel] 11/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5af11b84d05982a683712f1db8d9ca608ff3f7f8
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 10:25:07 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../camel/support/PropertyBindingSupportTest.java  | 33 +++++++++++++---------
 .../camel/support/PropertyBindingSupport.java      | 28 ++++++++++++------
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index 35bfadf..c372e39 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -228,32 +228,39 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
             return age;
         }
 
-        public void setAge(int age) {
-            this.age = age;
-        }
-
         public boolean isRider() {
             return rider;
         }
 
-        public void setRider(boolean rider) {
-            this.rider = rider;
-        }
-
         public Company getWork() {
             return work;
         }
 
-        public void setWork(Company work) {
-            this.work = work;
-        }
-
         public boolean isGoldCustomer() {
             return goldCustomer;
         }
 
-        public void setGoldCustomer(boolean goldCustomer) {
+        // this has no setter but only builders
+        // and mix the builders with both styles (with as prefix and no prefix at all)
+
+        public Bar withAge(int age) {
+            this.age = age;
+            return this;
+        }
+
+        public Bar withRider(boolean rider) {
+            this.rider = rider;
+            return this;
+        }
+
+        public Bar work(Company work) {
+            this.work = work;
+            return this;
+        }
+
+        public Bar goldCustomer(boolean goldCustomer) {
             this.goldCustomer = goldCustomer;
+            return this;
         }
     }
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 453e5b0..d4a6980 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -140,10 +140,8 @@ public final class PropertyBindingSupport {
                 Object prop = getOrElseProperty(newTarget, part, null);
                 if (prop == null) {
                     // okay is there a setter so we can create a new instance and set it automatic
-                    Set<Method> newSetters = findSetterMethods(newClass, part, true);
-                    // TODO: you may have setter + fluent builder at the same time, so grab setter first, and fallback to fluent builder afterwards
-                    if (newSetters.size() == 1) {
-                        Method method = newSetters.iterator().next();
+                    Method method = findBestSetterMethod(newClass, part);
+                    if (method != null) {
                         Class<?> parameterType = method.getParameterTypes()[0];
                         if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
                             Object instance = context.getInjector().newInstance(parameterType);
@@ -184,10 +182,8 @@ public final class PropertyBindingSupport {
                 }
             } else if (value.toString().equals("#autowire")) {
                 // we should get the type from the setter
-                // TODO: you may have setter + fluent builder at the same time, so grab setter first, and fallback to fluent builder afterwards
-                Set<Method> newSetters = findSetterMethods(target.getClass(), name, true);
-                if (newSetters.size() == 1) {
-                    Method method = newSetters.iterator().next();
+                Method method = findBestSetterMethod(target.getClass(), name);
+                if (method != null) {
                     Class<?> parameterType = method.getParameterTypes()[0];
                     if (parameterType != null) {
                         Set<?> types = context.getRegistry().findByType(parameterType);
@@ -210,4 +206,20 @@ public final class PropertyBindingSupport {
         return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
     }
 
+    private static Method findBestSetterMethod(Class clazz, String name) {
+        // is there a direct setter?
+        Set<Method> candidates = findSetterMethods(clazz, name, false);
+        if (candidates.size() == 1) {
+            return candidates.iterator().next();
+        }
+
+        // okay now try with builder pattern
+        candidates = findSetterMethods(clazz, name, true);
+        if (candidates.size() == 1) {
+            return candidates.iterator().next();
+        }
+
+        return null;
+    }
+
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 12/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0301d11a194473fa1280dcf37474e76048559afa
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 11:51:39 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../org/apache/camel/PropertyBindingException.java |   6 ++
 .../java/org/apache/camel/main/MainSupport.java    |  58 +----------
 .../PropertyBindingSupportAutowireTest.java        | 107 +++++++++++++++++++++
 .../camel/support/PropertyBindingSupport.java      |  89 ++++++++++++++++-
 4 files changed, 203 insertions(+), 57 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java b/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java
index ed6e61b..fdc9005 100644
--- a/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java
+++ b/core/camel-api/src/main/java/org/apache/camel/PropertyBindingException.java
@@ -36,6 +36,12 @@ public class PropertyBindingException extends RuntimeCamelException {
         this.propertyName = propertyName;
     }
 
+    public PropertyBindingException(Object target, Exception e) {
+        super("Error binding properties on bean: " + target, e);
+        this.target = target;
+        this.propertyName = null;
+    }
+
     public Object getTarget() {
         return target;
     }
diff --git a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index 4a249dc..a20623b 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -21,7 +21,6 @@ import java.io.FileInputStream;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -81,7 +80,6 @@ import org.apache.camel.spi.StreamCachingStrategy;
 import org.apache.camel.spi.ThreadPoolProfile;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
-import org.apache.camel.support.IntrospectionSupport;
 import org.apache.camel.support.LifecycleStrategySupport;
 import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.support.jsse.GlobalSSLContextParametersSupplier;
@@ -1255,62 +1253,10 @@ public abstract class MainSupport extends ServiceSupport {
         camelContext.addLifecycleStrategy(new LifecycleStrategySupport() {
             @Override
             public void onComponentAdd(String name, Component component) {
-                // when adding a component then support auto-configuring complex types
-                // by looking up from registry, such as DataSource etc
-                Map<String, Object> properties = new LinkedHashMap<>();
-                IntrospectionSupport.getProperties(component, properties, null);
-
-                // TODO: Use PropertyBindingSupport to make it support this kind of use-case too
-                // TODO: Allow nested properties too
-                // TODO: Allow fluent builders
-
-                // lookup complex types
-                properties.forEach((k, v) -> {
-                    // if the property has not been set and its a complex type (not simple or string etc)
-                    Class type = getGetterType(component, k);
-                    if (isComplexType(type)) {
-                        Set lookup = findExplicitBindingByType(camelContext, type);
-                        if (lookup.size() == 1) {
-                            v = lookup.iterator().next();
-                            try {
-                                LOG.info("Auto configuring option: {} on component: {} as one instance of type: {} registered in the Camel Registry", k, name, type.getName());
-                                IntrospectionSupport.setProperty(camelContext, component, k, v);
-                            } catch (Exception e) {
-                                LOG.warn("Cannot auto configure option: " + k + " on component: " + name + " due to " + e.getMessage());
-                            }
-                        }
-                    }
+                PropertyBindingSupport.autowireSingletonPropertiesFromRegistry(camelContext, component, false, (obj, propertyName, type, value) -> {
+                    LOG.info("Auto configuring option: {} on component: {} as one instance of type: {} registered in the Camel Registry", propertyName, obj, type.getName());
                 });
             }
-
-            /**
-             * Finds any explicit bean bindings that has been added to the registry.
-             * This means that if there are any, then they have been added by the end user
-             * and we should favour using the bean if there is a single instance bound for the type.
-             */
-            private Set findExplicitBindingByType(CamelContext camelContext, Class type) {
-                if (camelContext.getRegistry() instanceof MainRegistry) {
-                    return ((MainRegistry) camelContext.getRegistry()).findBindingsByType(type);
-                }
-                return Collections.EMPTY_SET;
-            }
-
-            private boolean isComplexType(Class type) {
-                // lets consider all non java as complex types
-                return type != null && !type.isPrimitive() && !type.getName().startsWith("java");
-            }
-
-            private Class getGetterType(Component component, String key) {
-                try {
-                    Method getter = IntrospectionSupport.getPropertyGetter(component.getClass(), key);
-                    if (getter != null) {
-                        return getter.getReturnType();
-                    }
-                } catch (NoSuchMethodException e) {
-                    // ignore
-                }
-                return null;
-            }
         });
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportAutowireTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportAutowireTest.java
new file mode 100644
index 0000000..5b33d61
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportAutowireTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.junit.Test;
+
+/**
+ * Unit test for PropertyBindingSupport
+ */
+public class PropertyBindingSupportAutowireTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        Bar bar = new Bar();
+        bar.setAge(33);
+        bar.setGoldCustomer(true);
+        bar.setRider(true);
+        context.getRegistry().bind("myBar", bar);
+
+        return context;
+    }
+
+    @Test
+    public void testAutowireProperties() throws Exception {
+        Foo foo = new Foo();
+
+        PropertyBindingSupport.bindProperty(context, foo, "name", "James");
+        PropertyBindingSupport.autowireSingletonPropertiesFromRegistry(context, foo);
+
+        assertEquals("James", foo.getName());
+        // should be auto wired
+        assertEquals(33, foo.getBar().getAge());
+        assertTrue(foo.getBar().isRider());
+        assertTrue(foo.getBar().isGoldCustomer());
+    }
+
+    public static class Foo {
+        private String name;
+        private Bar bar;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public Bar getBar() {
+            return bar;
+        }
+
+        public void setBar(Bar bar) {
+            this.bar = bar;
+        }
+    }
+
+    public static class Bar {
+        private int age;
+        private boolean rider;
+        private boolean goldCustomer;
+
+        public int getAge() {
+            return age;
+        }
+
+        public void setAge(int age) {
+            this.age = age;
+        }
+
+        public boolean isRider() {
+            return rider;
+        }
+
+        public void setRider(boolean rider) {
+            this.rider = rider;
+        }
+
+        public boolean isGoldCustomer() {
+            return goldCustomer;
+        }
+
+        public void setGoldCustomer(boolean goldCustomer) {
+            this.goldCustomer = goldCustomer;
+        }
+    }
+
+}
+
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index d4a6980..f336d75 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -17,6 +17,7 @@
 package org.apache.camel.support;
 
 import java.lang.reflect.Method;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -46,6 +47,20 @@ public final class PropertyBindingSupport {
     private PropertyBindingSupport() {
     }
 
+    @FunctionalInterface
+    public interface OnAutowiring {
+
+        /**
+         * Callback when a property was autowired on a bean
+         *
+         * @param target        the targeted bean
+         * @param propertyName  the name of the property
+         * @param propertyType  the type of the property
+         * @param value         the property value
+         */
+        void onAutowire(Object target, String propertyName, Class propertyType, Object value);
+
+    }
     /**
      * This will discover all the properties on the target, and automatic bind the properties that are null by
      * looking up in the registry to see if there is a single instance of the same type as the property.
@@ -57,10 +72,65 @@ public final class PropertyBindingSupport {
      * @return              true if one ore more properties was auto wired
      */
     public static boolean autowireSingletonPropertiesFromRegistry(CamelContext camelContext, Object target) {
-        // TODO: implement me
+        return autowireSingletonPropertiesFromRegistry(camelContext, target, false,null);
+    }
+
+    /**
+     * This will discover all the properties on the target, and automatic bind the properties by
+     * looking up in the registry to see if there is a single instance of the same type as the property.
+     * This is used for convention over configuration to automatic configure resources such as DataSource, Amazon Logins and
+     * so on.
+     *
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @param bindNullOnly  whether to only autowire if the property has no default value or has not been configured explicit
+     * @param callback      optional callback when a property was auto wired
+     * @return              true if one ore more properties was auto wired
+     */
+    public static boolean autowireSingletonPropertiesFromRegistry(CamelContext camelContext, Object target, boolean bindNullOnly, OnAutowiring callback) {
+        try {
+            if (target != null) {
+                return doAutowireSingletonPropertiesFromRegistry(camelContext, target, bindNullOnly, callback);
+            }
+        } catch (Exception e) {
+            throw new PropertyBindingException(target, e);
+        }
+
         return false;
     }
 
+    private static boolean doAutowireSingletonPropertiesFromRegistry(CamelContext camelContext, Object target, boolean bindNullOnly, OnAutowiring callback) throws Exception {
+        // when adding a component then support auto-configuring complex types
+        // by looking up from registry, such as DataSource etc
+        Map<String, Object> properties = new LinkedHashMap<>();
+        IntrospectionSupport.getProperties(target, properties, null);
+
+        boolean hit = false;
+
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            Class<?> type = getGetterType(target, key);
+            if (isComplexUserType(type)) {
+                // if the property has not been set and its a complex type (not simple or string etc)
+                if (!bindNullOnly || value == null) {
+                    Set lookup = camelContext.getRegistry().findByType(type);
+                    if (lookup.size() == 1) {
+                        value = lookup.iterator().next();
+                        if (value != null) {
+                            hit |= IntrospectionSupport.setProperty(camelContext, target, key, value);
+                            if (hit && callback != null) {
+                                callback.onAutowire(target, key, type, value);
+                            }
+                        }
+                    }
+                }
+            }
+        };
+
+        return hit;
+    }
+
     /**
      * Binds the properties to the target object.
      *
@@ -222,4 +292,21 @@ public final class PropertyBindingSupport {
         return null;
     }
 
+    private static Class getGetterType(Object target, String name) {
+        try {
+            Method getter = IntrospectionSupport.getPropertyGetter(target.getClass(), name);
+            if (getter != null) {
+                return getter.getReturnType();
+            }
+        } catch (NoSuchMethodException e) {
+            // ignore
+        }
+        return null;
+    }
+
+    private static boolean isComplexUserType(Class type) {
+        // lets consider all non java, as complex types
+        return type != null && !type.isPrimitive() && !type.getName().startsWith("java");
+    }
+
 }

Reply | Threaded
Open this post in threaded view
|

[camel] 13/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d42da8c35a946fabad9d3ca2b96b6b7843de4de5
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 14:05:31 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../file/FileProducerChmodOptionTest.java          |  9 +++++---
 .../DefaultComponentReferencePropertiesTest.java   |  4 ++--
 .../org/apache/camel/support/EndpointHelper.java   |  4 +++-
 .../apache/camel/support/IntrospectionSupport.java | 16 ++++++++++++--
 .../camel/support/PropertyBindingSupport.java      | 25 +++++++++++++++-------
 5 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerChmodOptionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerChmodOptionTest.java
index 3a018d6..31c8ceb 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerChmodOptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerChmodOptionTest.java
@@ -26,6 +26,8 @@ import java.util.Set;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.PropertyBindingException;
+import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Before;
@@ -99,9 +101,10 @@ public class FileProducerChmodOptionTest extends ContextTestSupport {
                 }
             });
             fail("Expected FailedToCreateRouteException");
-        } catch (Exception e) {
-            assertTrue("Expected FailedToCreateRouteException, was " + e.getClass().getCanonicalName(), e instanceof FailedToCreateRouteException);
-            assertTrue("Message was [" + e.getMessage() + "]", e.getMessage().endsWith("conversion possible: chmod option [abc] is not valid"));
+        } catch (FailedToCreateRouteException e) {
+            assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+            PropertyBindingException pbe = assertIsInstanceOf(PropertyBindingException.class, e.getCause().getCause());
+            assertEquals("chmod", pbe.getPropertyName());
         }
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
index ecd1b6b..0ab463e 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
@@ -199,8 +199,8 @@ public class DefaultComponentReferencePropertiesTest extends ContextTestSupport
         MyComponent component = new MyComponent(context);
         try {
             component.createEndpoint("foo://?special=#dummy");
-            fail("Should have throw a IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
+            fail("Should have throw a ResolveEndpointFailedException");
+        } catch (ResolveEndpointFailedException e) {
             // ok
         }
     }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index d690bdd..adc82cd 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -157,7 +157,9 @@ public final class EndpointHelper {
      * @throws Exception is thrown if setting property fails
      */
     public static void setProperties(CamelContext context, Object bean, Map<String, Object> parameters) throws Exception {
-        IntrospectionSupport.setProperties(context.getTypeConverter(), bean, parameters);
+         // TODO: Use more advanced bindingDefaultComponentReferencePropertiesTes
+         PropertyBindingSupport.bindProperties(context, bean, parameters);
+         //IntrospectionSupport.setProperties(context.getTypeConverter(), bean, parameters);
     }
 
     /**
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 3585940..01f8eee 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -539,8 +539,14 @@ public final class IntrospectionSupport {
 
         // loop and execute the best setter method
         Exception typeConversionFailed = null;
-        for (Method setter : setters) {
+        Method stringSetterMethod = null;
+        Iterator<Method> it = setters.iterator();
+        while (it.hasNext()) {
+            Method setter = it.next();
             Class<?> parameterType = setter.getParameterTypes()[0];
+            if (parameterType.getName().equals("java.lang.String")) {
+                stringSetterMethod = setter;
+            }
             Object ref = value;
             // try and lookup the reference based on the method
             if (context != null && refName != null && ref == null) {
@@ -548,7 +554,13 @@ public final class IntrospectionSupport {
                 ref = CamelContextHelper.lookup(context, s);
                 if (ref == null) {
                     // try the next method if nothing was found
-                    continue;
+                    // if we did not found a good candidate then fallback to use the string setter (if possible) with the actual ref name value as-is
+                    if (!it.hasNext() && stringSetterMethod != null) {
+                        setter = stringSetterMethod;
+                        ref = refName;
+                    } else {
+                        continue;
+                    }
                 } else {
                     // setter method has not the correct type
                     // (must use ObjectHelper.isAssignableFrom which takes primitive types into account)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index f336d75..02c24c1 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -17,6 +17,7 @@
 package org.apache.camel.support;
 
 import java.lang.reflect.Method;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
@@ -132,20 +133,28 @@ public final class PropertyBindingSupport {
     }
 
     /**
-     * Binds the properties to the target object.
+     * Binds the properties to the target object, and removes the property that was bound from properties.
      *
      * @param camelContext  the camel context
      * @param target        the target object
-     * @param properties    the properties
-     * @return              true if all the properties was bound, false otherwise
+     * @param properties    the properties where the bound properties will be removed from
+     * @return              true if one or more properties was bound
      */
     public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) {
-        boolean answer = true;
-        for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            answer &= bindProperty(camelContext, target, entry.getKey(), entry.getValue());
+        org.apache.camel.util.ObjectHelper.notNull(target, "target");
+        org.apache.camel.util.ObjectHelper.notNull(properties, "properties");
+        boolean rc = false;
+
+        for (Iterator<Map.Entry<String, Object>> iter = properties.entrySet().iterator(); iter.hasNext();) {
+            Map.Entry<String, Object> entry = iter.next();
+            if (bindProperty(camelContext, target, entry.getKey(), entry.getValue())) {
+                iter.remove();
+                rc = true;
+            }
         }
-        return answer;
-    }
+
+        return rc;
+   }
 
     /**
      * Binds the property to the target object.

Reply | Threaded
Open this post in threaded view
|

[camel] 14/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5e450ac4a4209f700ea9c4202130c7822e3cd1f3
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 14:25:40 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../apache/camel/support/IntrospectionSupport.java | 25 ++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 01f8eee..6af2cec 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -419,7 +419,11 @@ public final class IntrospectionSupport {
         }
         return false;
     }
-    
+
+    /**
+     * @deprecated use {@link PropertyBindingSupport}
+     */
+    @Deprecated
     public static boolean setProperties(Object target, Map<String, Object> properties, String optionPrefix, boolean allowBuilderPattern) throws Exception {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");
@@ -441,6 +445,10 @@ public final class IntrospectionSupport {
         return rc;
     }
 
+    /**
+     * @deprecated use {@link PropertyBindingSupport}
+     */
+    @Deprecated
     public static boolean setProperties(Object target, Map<String, Object> properties, String optionPrefix) throws Exception {
         StringHelper.notEmpty(optionPrefix, "optionPrefix");
         return setProperties(target, properties, optionPrefix, false);
@@ -472,6 +480,7 @@ public final class IntrospectionSupport {
         return rc;
     }
 
+    @Deprecated
     public static Map<String, String> extractStringProperties(Map<String, Object> properties) {
         ObjectHelper.notNull(properties, "properties");
 
@@ -486,6 +495,10 @@ public final class IntrospectionSupport {
         return rc;
     }
 
+    /**
+     * @deprecated use {@link PropertyBindingSupport}
+     */
+    @Deprecated
     public static boolean setProperties(CamelContext context, TypeConverter typeConverter, Object target, Map<String, Object> properties) throws Exception {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");
@@ -501,11 +514,19 @@ public final class IntrospectionSupport {
 
         return rc;
     }
-    
+
+    /**
+     * @deprecated use {@link PropertyBindingSupport}
+     */
+    @Deprecated
     public static boolean setProperties(TypeConverter typeConverter, Object target, Map<String, Object> properties) throws Exception {
         return setProperties(null, typeConverter, target, properties);
     }
 
+    /**
+     * @deprecated use {@link PropertyBindingSupport}
+     */
+    @Deprecated
     public static boolean setProperties(Object target, Map<String, Object> properties) throws Exception {
         return setProperties(null, target, properties);
     }

Reply | Threaded
Open this post in threaded view
|

[camel] 15/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 829296d324960c2ac58f3772046b8ede02ba959e
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 15:09:45 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../camel/model/ProcessorDefinitionHelper.java     |   8 +-
 .../cloud/ServiceCallExpressionConfiguration.java  |   3 +-
 .../ServiceCallServiceChooserConfiguration.java    |   3 +-
 .../ServiceCallServiceDiscoveryConfiguration.java  |   3 +-
 .../ServiceCallServiceFilterConfiguration.java     |   3 +-
 ...erviceCallServiceLoadBalancerConfiguration.java |   3 +-
 .../management/JmxManagementStrategyFactory.java   |   3 +-
 .../DefaultComponentVerifierExtension.java         |  14 +-
 .../camel/support/PropertyBindingSupport.java      | 174 ++++++++++++++++-----
 .../camel/support/RestProducerFactoryHelper.java   |   7 +-
 .../camel/support/ScheduledPollConsumer.java       |  10 +-
 .../support/component/AbstractApiComponent.java    |   3 +-
 12 files changed, 163 insertions(+), 71 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 35ebbb2..8852307 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -33,6 +33,7 @@ import org.apache.camel.NamedNode;
 import org.apache.camel.spi.ExecutorServiceManager;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
@@ -644,9 +645,12 @@ public final class ProcessorDefinitionHelper {
             @Override
             public void run() {
                 try {
-                    IntrospectionSupport.setProperties(context, null, target, properties);
+                    // do not use property placeholders as we want to preserve the text as-is when we restore
+                    PropertyBindingSupport.build()
+                            .withPlaceholder(false).withNesting(false).withReference(false).withTarget(target).withProperties(properties)
+                            .bind(context);
                 } catch (Exception e) {
-                    LOG.warn("Could not restore definition properties", e);
+                    LOG.warn("Cannot restore definition properties. This exception is ignored.", e);
                 }
             }
         });
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
index 32d203c..d9f753c 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
@@ -43,6 +43,7 @@ import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 
 @Metadata(label = "routing,cloud")
 @XmlRootElement(name = "serviceExpression")
@@ -267,7 +268,7 @@ public class ServiceCallExpressionConfiguration extends IdentifiedType implement
 
                     postProcessFactoryParameters(camelContext, parameters);
 
-                    IntrospectionSupport.setProperties(factory, parameters);
+                    PropertyBindingSupport.bindProperties(camelContext, factory, parameters);
 
                     answer = factory.newInstance(camelContext);
                 } catch (Exception e) {
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceChooserConfiguration.java b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceChooserConfiguration.java
index 313f15d..2dc6dfc 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceChooserConfiguration.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceChooserConfiguration.java
@@ -39,6 +39,7 @@ import org.apache.camel.model.PropertyDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.ObjectHelper;
 
 @Metadata(label = "routing,cloud,service-discovery")
@@ -185,7 +186,7 @@ public class ServiceCallServiceChooserConfiguration extends IdentifiedType imple
 
                 postProcessFactoryParameters(camelContext, parameters);
 
-                IntrospectionSupport.setProperties(factory, parameters);
+                PropertyBindingSupport.bindProperties(camelContext, factory, parameters);
 
                 answer = factory.newInstance(camelContext);
             } catch (Exception e) {
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceDiscoveryConfiguration.java b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceDiscoveryConfiguration.java
index 57c4ec4..d153f41 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceDiscoveryConfiguration.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceDiscoveryConfiguration.java
@@ -40,6 +40,7 @@ import org.apache.camel.model.PropertyDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.ObjectHelper;
 
 @Metadata(label = "routing,cloud,service-discovery")
@@ -192,7 +193,7 @@ public class ServiceCallServiceDiscoveryConfiguration extends IdentifiedType imp
 
                 postProcessFactoryParameters(camelContext, parameters);
 
-                IntrospectionSupport.setProperties(factory, parameters);
+                PropertyBindingSupport.bindProperties(camelContext, factory, parameters);
 
                 answer = factory.newInstance(camelContext);
             } catch (Exception e) {
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceFilterConfiguration.java b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceFilterConfiguration.java
index a0465a3..db7887e 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceFilterConfiguration.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceFilterConfiguration.java
@@ -39,6 +39,7 @@ import org.apache.camel.model.PropertyDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.ObjectHelper;
 
 @Metadata(label = "routing,cloud,service-discovery")
@@ -185,7 +186,7 @@ public class ServiceCallServiceFilterConfiguration extends IdentifiedType implem
 
                 postProcessFactoryParameters(camelContext, parameters);
 
-                IntrospectionSupport.setProperties(factory, parameters);
+                PropertyBindingSupport.bindProperties(camelContext, factory, parameters);
 
                 answer = factory.newInstance(camelContext);
             } catch (Exception e) {
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
index 6e42e34e..6794a23 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
@@ -39,6 +39,7 @@ import org.apache.camel.model.PropertyDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.ObjectHelper;
 
 @Metadata(label = "routing,cloud,load-balancing")
@@ -185,7 +186,7 @@ public class ServiceCallServiceLoadBalancerConfiguration extends IdentifiedType
 
                 postProcessFactoryParameters(camelContext, parameters);
 
-                IntrospectionSupport.setProperties(factory, parameters);
+                PropertyBindingSupport.bindProperties(camelContext, factory, parameters);
 
                 answer = factory.newInstance(camelContext);
             } catch (Exception e) {
diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java b/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
index 6afcb47..b0dfde0 100644
--- a/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
+++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
@@ -23,6 +23,7 @@ import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.ManagementStrategyFactory;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 
 /**
  * Factory for creating JMX {@link ManagementStrategy}.
@@ -32,7 +33,7 @@ public class JmxManagementStrategyFactory implements ManagementStrategyFactory {
     public ManagementStrategy create(CamelContext context, Map<String, Object> options) throws Exception {
         DefaultManagementAgent agent = new DefaultManagementAgent(context);
         if (options != null) {
-            IntrospectionSupport.setProperties(agent, options);
+            PropertyBindingSupport.bindProperties(context, agent, options);
         }
 
         return new JmxManagementStrategy(context, agent);
diff --git a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
index e8b27f1..9e751de 100644
--- a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
+++ b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
@@ -32,6 +32,7 @@ import org.apache.camel.runtimecatalog.RuntimeCamelCatalog;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 
 import static org.apache.camel.util.StreamUtils.stream;
 
@@ -188,18 +189,7 @@ public class DefaultComponentVerifierExtension implements ComponentVerifierExten
         }
 
         if (!properties.isEmpty()) {
-            final TypeConverter converter = camelContext.getTypeConverter();
-
-            IntrospectionSupport.setProperties(converter, instance, properties);
-
-            for (Map.Entry<String, Object> entry : properties.entrySet()) {
-                if (entry.getValue() instanceof String) {
-                    String value = (String)entry.getValue();
-                    if (EndpointHelper.isReferenceParameter(value)) {
-                        IntrospectionSupport.setProperty(camelContext, converter, instance, entry.getKey(), null, value, true);
-                    }
-                }
-            }
+            PropertyBindingSupport.bindProperties(camelContext, instance, properties);
         }
 
         return instance;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 02c24c1..99f9638 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -43,11 +43,65 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  */
 public final class PropertyBindingSupport {
 
+    public static class Builder {
+
+        private boolean nesting = true;
+        private boolean reference = true;
+        private boolean placeholder = true;
+        private boolean fluentBuilder = true;
+
+        private Object target;
+        private Map<String, Object> properties;
+
+        public Builder withNesting(boolean nesting) {
+            this.nesting = nesting;
+            return this;
+        }
+
+        public Builder withReference(boolean reference) {
+            this.reference = reference;
+            return this;
+        }
+
+        public Builder withPlaceholder(boolean placeholder) {
+            this.placeholder = placeholder;
+            return this;
+        }
+
+        public Builder withFluentBuilder(boolean fluentBuilder) {
+            this.fluentBuilder = fluentBuilder;
+            return this;
+        }
+
+        public Builder withTarget(Object target) {
+            this.target = target;
+            return this;
+        }
+
+        public Builder withProperties(Map<String, Object> properties) {
+            this.properties = properties;
+            return this;
+        }
+
+        public boolean bind(CamelContext camelContext) {
+            org.apache.camel.util.ObjectHelper.notNull(camelContext, "camelContext");
+            org.apache.camel.util.ObjectHelper.notNull(target, "target");
+            org.apache.camel.util.ObjectHelper.notNull(properties, "properties");
+
+            return bindProperties(camelContext, target, properties, nesting, fluentBuilder, reference, placeholder);
+        }
+
+    }
+
     // TODO: Add support for Map/List
 
     private PropertyBindingSupport() {
     }
 
+    public static Builder build() {
+        return new Builder();
+    }
+
     @FunctionalInterface
     public interface OnAutowiring {
 
@@ -141,20 +195,38 @@ public final class PropertyBindingSupport {
      * @return              true if one or more properties was bound
      */
     public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties) {
+        return bindProperties(camelContext, target, properties, true, true, true, true);
+   }
+
+    /**
+     * Binds the properties to the target object, and removes the property that was bound from properties.
+     *
+     * @param camelContext  the camel context
+     * @param target        the target object
+     * @param properties    the properties where the bound properties will be removed from
+     * @param nesting       whether nesting is in use
+     * @param fluentBuilder whether fluent builder is allowed as a valid getter/setter
+     * @param reference     whether reference parameter (syntax starts with #) is in use
+     * @param placeholder   whether to use Camels property placeholder to resolve placeholders on keys and values
+     * @return              true if one or more properties was bound
+     */
+    public static boolean bindProperties(CamelContext camelContext, Object target, Map<String, Object> properties,
+                                         boolean nesting, boolean fluentBuilder, boolean reference, boolean placeholder) {
+        org.apache.camel.util.ObjectHelper.notNull(camelContext, "camelContext");
         org.apache.camel.util.ObjectHelper.notNull(target, "target");
         org.apache.camel.util.ObjectHelper.notNull(properties, "properties");
         boolean rc = false;
 
         for (Iterator<Map.Entry<String, Object>> iter = properties.entrySet().iterator(); iter.hasNext();) {
             Map.Entry<String, Object> entry = iter.next();
-            if (bindProperty(camelContext, target, entry.getKey(), entry.getValue())) {
+            if (bindProperty(camelContext, target, entry.getKey(), entry.getValue(), nesting, fluentBuilder, reference, placeholder)) {
                 iter.remove();
                 rc = true;
             }
         }
 
         return rc;
-   }
+    }
 
     /**
      * Binds the property to the target object.
@@ -168,7 +240,20 @@ public final class PropertyBindingSupport {
     public static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value) {
         try {
             if (target != null && name != null) {
-                return setProperty(camelContext, target, name, value);
+                return setProperty(camelContext, target, name, value, true, true, true, true);
+            }
+        } catch (Exception e) {
+            throw new PropertyBindingException(target, name, e);
+        }
+
+        return false;
+    }
+
+    private static boolean bindProperty(CamelContext camelContext, Object target, String name, Object value,
+                                boolean nesting, boolean fluentBuilder, boolean reference, boolean placeholder) {
+        try {
+            if (target != null && name != null) {
+                return setProperty(camelContext, target, name, value, nesting, fluentBuilder, reference, placeholder);
             }
         } catch (Exception e) {
             throw new PropertyBindingException(target, name, e);
@@ -188,7 +273,7 @@ public final class PropertyBindingSupport {
     public static void bindMandatoryProperty(CamelContext camelContext, Object target, String name, Object value) {
         try {
             if (target != null && name != null) {
-                boolean bound = setProperty(camelContext, target, name, value);
+                boolean bound = setProperty(camelContext, target, name, value, true, true, true, true);
                 if (!bound) {
                     throw new PropertyBindingException(target, name);
                 }
@@ -198,50 +283,55 @@ public final class PropertyBindingSupport {
         }
     }
 
-    private static boolean setProperty(CamelContext context, Object target, String name, Object value) throws Exception {
+    private static boolean setProperty(CamelContext context, Object target, String name, Object value,
+                                       boolean nesting, boolean fluentBuilder, boolean reference, boolean placeholder) throws Exception {
         String refName = null;
 
-        // resolve property placeholders
-        name = context.resolvePropertyPlaceholders(name);
-        if (value instanceof String) {
+        if (placeholder) {
             // resolve property placeholders
-            value = context.resolvePropertyPlaceholders(value.toString());
+            name = context.resolvePropertyPlaceholders(name);
+            if (value instanceof String) {
+                // resolve property placeholders
+                value = context.resolvePropertyPlaceholders(value.toString());
+            }
         }
 
         // if name has dot then we need to OGNL walk it
-        if (name.indexOf('.') > 0) {
-            String[] parts = name.split("\\.");
-            Object newTarget = target;
-            Class<?> newClass = target.getClass();
-            // we should only iterate until until 2nd last so we use -1 in the for loop
-            for (int i = 0; i < parts.length - 1; i++) {
-                String part = parts[i];
-                Object prop = getOrElseProperty(newTarget, part, null);
-                if (prop == null) {
-                    // okay is there a setter so we can create a new instance and set it automatic
-                    Method method = findBestSetterMethod(newClass, part);
-                    if (method != null) {
-                        Class<?> parameterType = method.getParameterTypes()[0];
-                        if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
-                            Object instance = context.getInjector().newInstance(parameterType);
-                            if (instance != null) {
-                                org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance);
-                                newTarget = instance;
-                                newClass = newTarget.getClass();
+        if (nesting) {
+            if (name.indexOf('.') > 0) {
+                String[] parts = name.split("\\.");
+                Object newTarget = target;
+                Class<?> newClass = target.getClass();
+                // we should only iterate until until 2nd last so we use -1 in the for loop
+                for (int i = 0; i < parts.length - 1; i++) {
+                    String part = parts[i];
+                    Object prop = getOrElseProperty(newTarget, part, null);
+                    if (prop == null) {
+                        // okay is there a setter so we can create a new instance and set it automatic
+                        Method method = findBestSetterMethod(newClass, part, fluentBuilder);
+                        if (method != null) {
+                            Class<?> parameterType = method.getParameterTypes()[0];
+                            if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) {
+                                Object instance = context.getInjector().newInstance(parameterType);
+                                if (instance != null) {
+                                    org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance);
+                                    newTarget = instance;
+                                    newClass = newTarget.getClass();
+                                }
                             }
                         }
+                    } else {
+                        newTarget = prop;
+                        newClass = newTarget.getClass();
                     }
-                } else {
-                    newTarget = prop;
-                    newClass = newTarget.getClass();
                 }
+                // okay we found a nested property, then lets change to use that
+                target = newTarget;
+                name = parts[parts.length - 1];
             }
-            // okay we found a nested property, then lets change to use that
-            target = newTarget;
-            name = parts[parts.length - 1];
         }
 
-        if (value instanceof String) {
+        if (reference && value instanceof String) {
             if (value.toString().startsWith("#class:")) {
                 // its a new class to be created
                 String className = value.toString().substring(6);
@@ -261,7 +351,7 @@ public final class PropertyBindingSupport {
                 }
             } else if (value.toString().equals("#autowire")) {
                 // we should get the type from the setter
-                Method method = findBestSetterMethod(target.getClass(), name);
+                Method method = findBestSetterMethod(target.getClass(), name, fluentBuilder);
                 if (method != null) {
                     Class<?> parameterType = method.getParameterTypes()[0];
                     if (parameterType != null) {
@@ -282,10 +372,10 @@ public final class PropertyBindingSupport {
             }
         }
 
-        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, true);
+        return IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value, refName, fluentBuilder);
     }
 
-    private static Method findBestSetterMethod(Class clazz, String name) {
+    private static Method findBestSetterMethod(Class clazz, String name, boolean fluentBuilder) {
         // is there a direct setter?
         Set<Method> candidates = findSetterMethods(clazz, name, false);
         if (candidates.size() == 1) {
@@ -293,9 +383,11 @@ public final class PropertyBindingSupport {
         }
 
         // okay now try with builder pattern
-        candidates = findSetterMethods(clazz, name, true);
-        if (candidates.size() == 1) {
-            return candidates.iterator().next();
+        if (fluentBuilder) {
+            candidates = findSetterMethods(clazz, name, true);
+            if (candidates.size() == 1) {
+                return candidates.iterator().next();
+            }
         }
 
         return null;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
index 657a33d..743f551 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.support;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -74,9 +74,8 @@ public final class RestProducerFactoryHelper {
         // need to make a copy of the component properties as
         // IntrospectionSupport::setProperties will remove any that are set and
         // we might be called multiple times
-        final Map<String, Object> copyOfComponentProperties = new HashMap<>(componentProperties);
-        IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), newlyCreated,
-            copyOfComponentProperties);
+        final Map<String, Object> copyOfComponentProperties = new LinkedHashMap<>(componentProperties);
+        PropertyBindingSupport.bindProperties(camelContext, newlyCreated, copyOfComponentProperties);
         ServiceHelper.startService(newlyCreated);
 
         return newlyCreated;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
index 2bc5e2f..1244fe5 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.support;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -417,13 +417,13 @@ public abstract class ScheduledPollConsumer extends DefaultConsumer implements R
         scheduler.onInit(this);
 
         // configure scheduler with options from this consumer
-        Map<String, Object> properties = new HashMap<>();
+        Map<String, Object> properties = new LinkedHashMap<>();
         IntrospectionSupport.getProperties(this, properties, null);
-        IntrospectionSupport.setProperties(getEndpoint().getCamelContext().getTypeConverter(), scheduler, properties);
+        PropertyBindingSupport.bindProperties(getEndpoint().getCamelContext(), scheduler, properties);
         if (schedulerProperties != null && !schedulerProperties.isEmpty()) {
             // need to use a copy in case the consumer is restarted so we keep the properties
-            Map<String, Object> copy = new HashMap<>(schedulerProperties);
-            IntrospectionSupport.setProperties(getEndpoint().getCamelContext().getTypeConverter(), scheduler, copy);
+            Map<String, Object> copy = new LinkedHashMap<>(schedulerProperties);
+            PropertyBindingSupport.bindProperties(getEndpoint().getCamelContext(), scheduler, copy);
             if (copy.size() > 0) {
                 throw new FailedToCreateConsumerException(getEndpoint(), "There are " + copy.size()
                         + " scheduler parameters that couldn't be set on the endpoint."
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
index d4cea3e..808c4ef 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
@@ -26,6 +26,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.support.PropertyBindingSupport;
 
 /**
  * Abstract base class for API Component Camel {@link org.apache.camel.Component} classes.
@@ -111,7 +112,7 @@ public abstract class AbstractApiComponent<E extends Enum<E> & ApiName, T, S ext
 
         // create endpoint configuration with component properties
         final T endpointConfiguration = collection.getEndpointConfiguration(name);
-        IntrospectionSupport.setProperties(endpointConfiguration, componentProperties);
+        PropertyBindingSupport.bindProperties(getCamelContext(), endpointConfiguration, componentProperties);
         return endpointConfiguration;
     }
 

Reply | Threaded
Open this post in threaded view
|

[camel] 16/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ab39c60342f3e7bccba7ae36bd21d2296d06d7e3
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 20:43:30 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../DefaultComponentReferencePropertiesTest.java   |  4 ++--
 .../camel/support/PropertyBindingSupportTest.java  |  4 ++--
 .../org/apache/camel/support/EndpointHelper.java   |  5 ++--
 .../camel/support/PropertyBindingSupport.java      | 27 ++++++++++++----------
 4 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
index 0ab463e..81fc01b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
@@ -199,8 +199,8 @@ public class DefaultComponentReferencePropertiesTest extends ContextTestSupport
         MyComponent component = new MyComponent(context);
         try {
             component.createEndpoint("foo://?special=#dummy");
-            fail("Should have throw a ResolveEndpointFailedException");
-        } catch (ResolveEndpointFailedException e) {
+            fail("Should have throw a Exception");
+        } catch (Exception e) {
             // ok
         }
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index c372e39..327c919 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -96,7 +96,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
         PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
-        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#myWork");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#bean:myWork");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
@@ -114,7 +114,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
         PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
         PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
         PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
-        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#id:myWork");
+        PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#bean:myWork");
 
         assertEquals("James", foo.getName());
         assertEquals(33, foo.getBar().getAge());
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index adc82cd..0dd2adc 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -157,9 +157,8 @@ public final class EndpointHelper {
      * @throws Exception is thrown if setting property fails
      */
     public static void setProperties(CamelContext context, Object bean, Map<String, Object> parameters) throws Exception {
-         // TODO: Use more advanced bindingDefaultComponentReferencePropertiesTes
-         PropertyBindingSupport.bindProperties(context, bean, parameters);
-         //IntrospectionSupport.setProperties(context.getTypeConverter(), bean, parameters);
+        // use the property binding which can do more advanced configuration
+        PropertyBindingSupport.bindProperties(context, bean, parameters);
     }
 
     /**
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 99f9638..d992565 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -34,7 +34,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  * <ul>
  *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
  *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
- *     <li>reference by id - Values can refer to other beans in the registry by prefixing with #id: or # syntax, eg #id:myBean or #myBean</li>
+ *     <li>reference by bean id - Values can refer to other beans in the registry by prefixing with #nean: eg #bean:myBean</li>
  *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
  *     <li>autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowire</li>
  *     <li>new class - Values can refer to creating new beans by their class name syntax, eg class:com.foo.MyClassType</li>
@@ -43,6 +43,13 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
  */
 public final class PropertyBindingSupport {
 
+    // TODO: Add support for Map/List
+    // TODO: Add option to turn on|off new class
+    // TODO: Add option to turn this binding on|off on component/endpoint level
+
+    /**
+     * To use a fluent builder style to configure this property binding support.
+     */
     public static class Builder {
 
         private boolean nesting = true;
@@ -93,8 +100,6 @@ public final class PropertyBindingSupport {
 
     }
 
-    // TODO: Add support for Map/List
-
     private PropertyBindingSupport() {
     }
 
@@ -325,9 +330,11 @@ public final class PropertyBindingSupport {
                         newClass = newTarget.getClass();
                     }
                 }
-                // okay we found a nested property, then lets change to use that
-                target = newTarget;
-                name = parts[parts.length - 1];
+                if (newTarget != target) {
+                    // okay we found a nested property, then lets change to use that
+                    target = newTarget;
+                    name = parts[parts.length - 1];
+                }
             }
         }
 
@@ -361,13 +368,9 @@ public final class PropertyBindingSupport {
                         }
                     }
                 }
-            } else if (value.toString().startsWith("#id:")) {
-                // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
-                refName = ((String) value).substring(4);
-                value = null;
-            } else if (EndpointHelper.isReferenceParameter(value.toString())) {
+            } else if (value.toString().startsWith("#bean:")) {
                 // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
-                refName = value.toString();
+                refName = ((String) value).substring(6);
                 value = null;
             }
         }

Reply | Threaded
Open this post in threaded view
|

[camel] 17/27: Reduce logging noise for standard discovered factories

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 140ae76014a34408aa0a05b4d2bf3ea82af5c9ed
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 21:11:01 2019 +0200

    Reduce logging noise for standard discovered factories
---
 .../org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java    | 2 +-
 .../java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java   | 2 +-
 .../org/apache/camel/impl/engine/RestRegistryFactoryResolver.java     | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java
index 01934ff..2dcca85 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java
@@ -51,7 +51,7 @@ public class BeanProcessorFactoryResolver {
             }
             if (BeanProcessorFactory.class.isAssignableFrom(type)) {
                 BeanProcessorFactory answer = (BeanProcessorFactory) context.getInjector().newInstance(type);
-                LOG.info("Detected and using custom BeanProcessorFactory: {}", answer);
+                LOG.debug("Detected and using BeanProcessorFactory: {}", answer);
                 return answer;
             } else {
                 throw new IllegalArgumentException("Type is not a BeanProcessorFactory implementation. Found: " + type.getName());
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java
index b53e1a8..cbe233c 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java
@@ -51,7 +51,7 @@ public class BeanProxyFactoryResolver {
             }
             if (BeanProxyFactory.class.isAssignableFrom(type)) {
                 BeanProxyFactory answer = (BeanProxyFactory) context.getInjector().newInstance(type);
-                LOG.info("Detected and using custom BeanProxyFactory: {}", answer);
+                LOG.debug("Detected and using BeanProxyFactory: {}", answer);
                 return answer;
             } else {
                 throw new IllegalArgumentException("Type is not a BeanProxyFactory implementation. Found: " + type.getName());
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java
index ad74fcf..130ef9f 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java
@@ -53,14 +53,14 @@ public class RestRegistryFactoryResolver {
             }
             if (RestRegistryFactory.class.isAssignableFrom(type)) {
                 RestRegistryFactory answer = (RestRegistryFactory) context.getInjector().newInstance(type);
-                LOG.info("Detected and using RestRegistryFactory: {}", answer);
+                LOG.debug("Detected and using RestRegistryFactory: {}", answer);
                 return answer;
             } else {
                 throw new IllegalArgumentException("Type is not a RestRegistryFactory implementation. Found: " + type.getName());
             }
         }
 
-        LOG.debug("No RestRegistryFactory implementation found.  You need to add camel-rest to the classpath.");
+        LOG.debug("Cannot find RestRegistryFactory. Make sure camel-rest is on the classpath.");
         return null;
     }
 

Reply | Threaded
Open this post in threaded view
|

[camel] 18/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8796747d07f47d8435b08f9fdaf0d459a57211b5
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 21:28:30 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../src/main/java/org/apache/camel/support/PropertyBindingSupport.java  | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index d992565..cd03b63 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -167,6 +167,8 @@ public final class PropertyBindingSupport {
 
         boolean hit = false;
 
+        // TODO: add support for nesting but not for inherited properties from base classes (eg CamelContext etc)
+
         for (Map.Entry<String, Object> entry : properties.entrySet()) {
             String key = entry.getKey();
             Object value = entry.getValue();

Reply | Threaded
Open this post in threaded view
|

[camel] 19/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

davsclaus-2
In reply to this post by davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 35f0ad989d8119a08333cb6f7a6af8b8117a1ec9
Author: Claus Ibsen <[hidden email]>
AuthorDate: Thu May 23 21:36:56 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../org/apache/camel/model/ProcessorDefinitionHelper.java |  4 ++--
 .../camel/management/JmxManagementStrategyFactory.java    |  1 -
 .../verifier/DefaultComponentVerifierExtension.java       |  2 --
 .../org/apache/camel/support/PropertyBindingSupport.java  | 15 +--------------
 4 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 8852307..b0f55c5 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -647,8 +647,8 @@ public final class ProcessorDefinitionHelper {
                 try {
                     // do not use property placeholders as we want to preserve the text as-is when we restore
                     PropertyBindingSupport.build()
-                            .withPlaceholder(false).withNesting(false).withReference(false).withTarget(target).withProperties(properties)
-                            .bind(context);
+                            .withPlaceholder(false).withNesting(false).withReference(false)
+                            .bind(context, target, properties);
                 } catch (Exception e) {
                     LOG.warn("Cannot restore definition properties. This exception is ignored.", e);
                 }
diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java b/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
index b0dfde0..1a8052a 100644
--- a/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
+++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/JmxManagementStrategyFactory.java
@@ -22,7 +22,6 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.ManagementStrategyFactory;
-import org.apache.camel.support.IntrospectionSupport;
 import org.apache.camel.support.PropertyBindingSupport;
 
 /**
diff --git a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
index 9e751de..c473b77 100644
--- a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
+++ b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
@@ -25,12 +25,10 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Component;
 import org.apache.camel.ComponentAware;
-import org.apache.camel.TypeConverter;
 import org.apache.camel.component.extension.ComponentVerifierExtension;
 import org.apache.camel.runtimecatalog.EndpointValidationResult;
 import org.apache.camel.runtimecatalog.RuntimeCamelCatalog;
 import org.apache.camel.support.CamelContextHelper;
-import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.IntrospectionSupport;
 import org.apache.camel.support.PropertyBindingSupport;
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index cd03b63..14e6a37 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -57,9 +57,6 @@ public final class PropertyBindingSupport {
         private boolean placeholder = true;
         private boolean fluentBuilder = true;
 
-        private Object target;
-        private Map<String, Object> properties;
-
         public Builder withNesting(boolean nesting) {
             this.nesting = nesting;
             return this;
@@ -80,17 +77,7 @@ public final class PropertyBindingSupport {
             return this;
         }
 
-        public Builder withTarget(Object target) {
-            this.target = target;
-            return this;
-        }
-
-        public Builder withProperties(Map<String, Object> properties) {
-            this.properties = properties;
-            return this;
-        }
-
-        public boolean bind(CamelContext camelContext) {
+        public boolean bind(CamelContext camelContext, Object target, Map<String, Object> properties) {
             org.apache.camel.util.ObjectHelper.notNull(camelContext, "camelContext");
             org.apache.camel.util.ObjectHelper.notNull(target, "target");
             org.apache.camel.util.ObjectHelper.notNull(properties, "properties");

12