Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.10.3
    • Fix Version/s: 3.0.0
    • Component/s: camel-bindy
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      It looks like camel-bindy does not take into account the class specified in the method:

      bindy(BindyType.Csv, MyCamelBeans.TEST.class)

      I have class MyCamelBeans which includes several "bindies" among which I have a really simple MyCamelBeans.TEST:

      class MyCamelBeans {
      @CsvRecord(separator=";",isOrdered=true)
      public static final class TEST

      { @DataField(trim=true,pos= 1) public String tradingDate; @DataField(trim=true,pos= 2) public String isinCode; }

      ... some other @CsvRecord ....
      }

      I also have some @FixedLengthRecord classes defined in the same package.
      If I run the following route:

      from("file:data/test?noop=true&idempotent=true&fileName=test.csv&delay=60000")
      .split(body(String.class).tokenize("\n")).streaming()
      .unmarshal().bindy(BindyType.Csv, MyCamelBeans.TEST.class)
      .to("log:DS?level=INFO&showHeaders=true");

      Camel (2.10.3) fails with an NPE:

      java.lang.NullPointerException
      at org.apache.camel.dataformat.bindy.BindyCsvFactory.setDefaultValuesForFields(BindyCsvFactory.java:583)
      at org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:230)

      if I remove the other bindies, camel-bindy works as expected.

      Looking at the code, I've found that in BindyAbstractFactory.java :

      /**

      • method uses to initialize the model representing the classes who will
      • bind the data. This process will scan for classes according to the
      • package name provided, check the annotated classes and fields.
        *
      • @throws Exception
        */
        public void initModel() throws Exception
        Unknown macro: { // Find classes defined as Model if (packageNames != null) { initModelClasses(this.packageNames); } else if (type != null) { // use the package name from the type as it may refer to types in the same package String pckName = type.getPackage().getName(); initModelClasses(pckName); } else { throw new IllegalArgumentException("Either packagenames or type should be configured"); } }

      Looks like bindy scan the package even a class has been specified.

      Accordin to Claus, bindy needs to be refactored so it

      • requires the class type (no more packages)
      • uses the class type as root model
      • ... and initializes the model from the root, and follow and
        references to other classes (if the root has childs)

      This avoids picking up any other models.
      And we would know to marshal/unmarshal based on the root.

        Activity

        Hide
        Claus Ibsen added a comment -

        I think we should schedule this for Camel 3.0 where we can refactor camel-bindy - and drop the old package name and package scan approach.

        Show
        Claus Ibsen added a comment - I think we should schedule this for Camel 3.0 where we can refactor camel-bindy - and drop the old package name and package scan approach.
        Hide
        ASF GitHub Bot added a comment -

        GitHub user lburgazzoli opened a pull request:

        https://github.com/apache/camel/pull/271

        CAMEL-5958: Bindy ignores bean class type

        re-build PR against latest sources

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/lburgazzoli/camel CAMEL-5958

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/camel/pull/271.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #271


        commit 1c293a9c7083ed593a706f42ae6da7247741d9a9
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-10-27T15:04:33Z

        CAMEL-5958: Bindy ignores bean class type (initial work)

        commit 402f911aaaf3ddaebdad2b143557bd0179813721
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-06T14:07:11Z

        Merge remote-tracking branch 'upstream/master'

        commit ab71ee66d0f69369fa76d09d4a75159b24215c5f
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-06T21:07:18Z

        Merge remote-tracking branch 'upstream/master'

        commit 54440df7c2afefe7324bd5e235c693ccc12e8cff
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-06T21:17:23Z

        CAMEL-5958: Bindy ignores bean class type (initial work)

        commit 8d8e9cb8624cd54354dab12b843b82a94cc14baa
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-07T15:55:11Z

        Merge remote-tracking branch 'upstream/master'

        commit 08c97b5030687abf551a61ee7905465632927081
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-10T19:02:43Z

        Merge remote-tracking branch 'upstream/master'

        commit 095202dc8ee0d551381f275383f4d8afc9d5ac14
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-22T10:14:58Z

        Merge remote-tracking branch 'upstream/master'

        commit ce4e7928904abaa321a1e13e48e7d4f83ec428c2
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-24T17:19:34Z

        Merge remote-tracking branch 'upstream/master'

        commit c1005b5731b3eecbe1d56aa3692707b3ed3bf56f
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-26T09:58:21Z

        Merge remote-tracking branch 'upstream/master'

        commit 1b5c9be1affcfd80484071ec5da310733ed53f78
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-26T17:01:28Z

        CAMEL-5958: Bindy ignores bean class type (some more work)

        commit ab2719e2b6253a0114ec284b4fdfce15851ebb7c
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-11-29T21:46:27Z

        CAMEL-5958: Bindy ignores bean class type: load models recursively

        commit 2657ac1ba1099867132854780d7901c84fcb439d
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-12-17T13:16:37Z

        Merge remote-tracking branch 'upstream/master'

        commit 34e05bce2b0b8c708a8a8de673f1d7ece28519af
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-12-18T14:03:34Z

        CAMEL-5958: Bindy ignores bean class type

        commit 8a2457896aa4f49246463f1c8b9f9e1736d3d08b
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2013-12-18T15:57:51Z

        CAMEL-5958: Bindy ignores bean class type

        commit a6c89854ed13cabe263ad653b4c01299d7ece919
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2014-09-20T11:54:57Z

        Merge branch 'master' into CAMEL-5958

        commit 3aeed745fa1603da13512008070a9e8231ac5e07
        Author: lburgazzoli <lburgazzoli@gmail.com>
        Date: 2014-09-20T17:29:48Z

        CAMEL-5958: Bindy ignores bean class type


        Show
        ASF GitHub Bot added a comment - GitHub user lburgazzoli opened a pull request: https://github.com/apache/camel/pull/271 CAMEL-5958 : Bindy ignores bean class type re-build PR against latest sources You can merge this pull request into a Git repository by running: $ git pull https://github.com/lburgazzoli/camel CAMEL-5958 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/camel/pull/271.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #271 commit 1c293a9c7083ed593a706f42ae6da7247741d9a9 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-10-27T15:04:33Z CAMEL-5958 : Bindy ignores bean class type (initial work) commit 402f911aaaf3ddaebdad2b143557bd0179813721 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-06T14:07:11Z Merge remote-tracking branch 'upstream/master' commit ab71ee66d0f69369fa76d09d4a75159b24215c5f Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-06T21:07:18Z Merge remote-tracking branch 'upstream/master' commit 54440df7c2afefe7324bd5e235c693ccc12e8cff Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-06T21:17:23Z CAMEL-5958 : Bindy ignores bean class type (initial work) commit 8d8e9cb8624cd54354dab12b843b82a94cc14baa Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-07T15:55:11Z Merge remote-tracking branch 'upstream/master' commit 08c97b5030687abf551a61ee7905465632927081 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-10T19:02:43Z Merge remote-tracking branch 'upstream/master' commit 095202dc8ee0d551381f275383f4d8afc9d5ac14 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-22T10:14:58Z Merge remote-tracking branch 'upstream/master' commit ce4e7928904abaa321a1e13e48e7d4f83ec428c2 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-24T17:19:34Z Merge remote-tracking branch 'upstream/master' commit c1005b5731b3eecbe1d56aa3692707b3ed3bf56f Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-26T09:58:21Z Merge remote-tracking branch 'upstream/master' commit 1b5c9be1affcfd80484071ec5da310733ed53f78 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-26T17:01:28Z CAMEL-5958 : Bindy ignores bean class type (some more work) commit ab2719e2b6253a0114ec284b4fdfce15851ebb7c Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-11-29T21:46:27Z CAMEL-5958 : Bindy ignores bean class type: load models recursively commit 2657ac1ba1099867132854780d7901c84fcb439d Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-12-17T13:16:37Z Merge remote-tracking branch 'upstream/master' commit 34e05bce2b0b8c708a8a8de673f1d7ece28519af Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-12-18T14:03:34Z CAMEL-5958 : Bindy ignores bean class type commit 8a2457896aa4f49246463f1c8b9f9e1736d3d08b Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2013-12-18T15:57:51Z CAMEL-5958 : Bindy ignores bean class type commit a6c89854ed13cabe263ad653b4c01299d7ece919 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2014-09-20T11:54:57Z Merge branch 'master' into CAMEL-5958 commit 3aeed745fa1603da13512008070a9e8231ac5e07 Author: lburgazzoli <lburgazzoli@gmail.com> Date: 2014-09-20T17:29:48Z CAMEL-5958 : Bindy ignores bean class type
        Hide
        ASF GitHub Bot added a comment -

        Github user lburgazzoli closed the pull request at:

        https://github.com/apache/camel/pull/83

        Show
        ASF GitHub Bot added a comment - Github user lburgazzoli closed the pull request at: https://github.com/apache/camel/pull/83
        Hide
        Luca Burgazzoli added a comment -

        Hi Willem,
        I've removed the package support camel-wide (e.g. org.apache.camel.builder.DataFormatClause).

        The patch's target was Camel 3.0 (or any version on which you can break API compatibility) but I can check if I can re-introduce the package support. One of the issues I see is that as today camel-bindy returns a Map<?,?> of models (even if a class is used as source for models) so in the current test cases:

        Map<?, ?> map = (Map<?, ?>) mock.getReceivedExchanges().get(0).getIn().getBody(List.class).get(0);
        WeatherModel model = (WeatherModel) map.values().iterator().next();

        After my patch:

        WeatherModel model = mock.getReceivedExchanges().get(0).getIn().getBody(WeatherModel.class);

        I see two options:
        1) re-introduce the package support, deprecate the API and construct a Map<?,?> of models even if the user specify a class
        2) apply the patch to a camel version on which API compatibility can be broken

        Let me know and I'll work on it

        Show
        Luca Burgazzoli added a comment - Hi Willem, I've removed the package support camel-wide (e.g. org.apache.camel.builder.DataFormatClause). The patch's target was Camel 3.0 (or any version on which you can break API compatibility) but I can check if I can re-introduce the package support. One of the issues I see is that as today camel-bindy returns a Map<?,?> of models (even if a class is used as source for models) so in the current test cases: Map<?, ?> map = (Map<?, ?>) mock.getReceivedExchanges().get(0).getIn().getBody(List.class).get(0); WeatherModel model = (WeatherModel) map.values().iterator().next(); After my patch: WeatherModel model = mock.getReceivedExchanges().get(0).getIn().getBody(WeatherModel.class); I see two options: 1) re-introduce the package support, deprecate the API and construct a Map<?,?> of models even if the user specify a class 2) apply the patch to a camel version on which API compatibility can be broken Let me know and I'll work on it
        Hide
        Willem Jiang added a comment -

        Hi Luca,

        I just reviewed the patch, you removed the package support of BindyCsvFactory.
        I think it could be better if we deprecate the API first, then use the class type directly when user specify it.

        Regards,

        Willem

        Show
        Willem Jiang added a comment - Hi Luca, I just reviewed the patch, you removed the package support of BindyCsvFactory. I think it could be better if we deprecate the API first, then use the class type directly when user specify it. Regards, Willem
        Hide
        Luca Burgazzoli added a comment -

        I've committed some work to my camel fork on github :
        https://github.com/lburgazzoli/camel/commit/34e05bce2b0b8c708a8a8de673f1d7ece28519af

        There still are some test cases to fix and some code is still a little rough but I would greatly appreciate any feedback.

        Show
        Luca Burgazzoli added a comment - I've committed some work to my camel fork on github : https://github.com/lburgazzoli/camel/commit/34e05bce2b0b8c708a8a8de673f1d7ece28519af There still are some test cases to fix and some code is still a little rough but I would greatly appreciate any feedback.

          People

          • Assignee:
            Unassigned
            Reporter:
            Luca Burgazzoli
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:

              Development