Announcement Announcement Module
Collapse
No announcement yet.
Groovy Bean as Splitter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Groovy Bean as Splitter

    Hello,

    My question seems similar to the one asked about the Router, but I cannot seem to get that proposed solution to work.

    In my case, I'd like to use a Groovy bean as a Splitter. I've tried a number of configuration permutations along the lines of:

    <!-- split method never called -->
    <int:splitter input-channel="channel1" output-channel="channel2">
    <lang:groovy id="fileSplitter" script-source="gov/noaa/ngdc/multibeam/MultibeamSplitter.groovy" />
    </int:splitter>

    or

    <!-- FileNotFoundException -->
    <int:splitter input-channel="channel1" output-channel="channel2" ref="fileSplitter" />
    <lang:groovy id="fileSplitter" script-source="gov/noaa/ngdc/multibeam/MultibeamSplitter.groovy" />


    Can someone please clarify for me or suggest an alternative approach?

    Thanks!

    --john

  • #2
    Hello

    How about start from here: http://static.springsource.org/sprin...er.html#groovy

    Take care,
    Artem

    Comment


    • #3
      Thanks for your reply Cleric.

      Based on your suggestion, I changed from lang:groovy to int-groovy:script, e.g.

      <int:splitter input-channel="channel1" output-channel="channel2">
      <int-groovy:script location="file:src/main/groovy/gov/noaa/ngdc/multibeam/MultibeamSplitter.groovy" />
      </int:splitter>

      This, combined with changing the Splitter from a class to a script, allows the beans to be created and the program to start.

      Is there a way to call a method in a Groovy class (a more direct analog to the Java version) rather than converting the Splitter to a script?

      Thanks again for your help!

      --john
      Last edited by jccartwright; Nov 18th, 2012, 02:52 AM.

      Comment


      • #4
        Is there a way to call a method in a Groovy class
        1. If your groovy script is compiled on application build there is no diference between java-class and groovy-class invoke at the runtime. Just configure a bean and reference it in the the Splitter, and, of course, is method.
        2. If you just place it in the classpath as .groovy file, as it was mentioned in your post, your script should not be full class. It shoulb something like this:
        Code:
        return payload.split()
        without any declaration of class and root-methods.
        With Spring Integration abilirty for scripting now there is no any reason to use 'lang' namespace and write separate interfaces for your scripts. You can use scripts in your SI-application as you can use them in the script-console.
        From other side I see you try to run your program from your IDE and the last one doesn't see your script-files. I's problem around IDE configuration.

        Hope I'm clear...

        Comment


        • #5
          Thanks again Cleric, I really appreciate your help in understanding this.

          I'm still confused on why I'm having trouble using a Groovy class instead of a Java class. Here's the situation:

          1) a groovy class in src/main/groovy which contains a method like: "public List<String> split(File multibeamFile) {...}"
          2) wire this up just like it was a java class, e.g.
          <int:splitter input-channel="channel1" output-channel="channel2" ref="fileSplitter" />
          <bean id="fileSplitter" class="gov.noaa.ngdc.multibeam.GroovyMultibeamFile Splitter" />
          3) confirm that the build (I'm using gradle) is placing a GroovyMultibeamFileSplitter.class in the classes directory

          I'm getting this exception which I don't understand:

          java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public void gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.super$1$wait(long), public void gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.setMetaClass(groovy.lang.MetaClass), public java.lang.Object gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.this$dist$get$1(java.lang.String), public boolean gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.super$1$equals(java.lang.Object), public void gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.super$1$finalize(), public java.util.List gov.noaa.ngdc.multibeam.GroovyMultibeamFileSplitte r.split(java.io.File)]

          Is there something about the method signature that needs to change between the java and groovy classes? What is the Splitter looking for in a method signature in the implementing class?

          --john

          Comment


          • #6
            I think it will be enough just to add 'method' attribute to your <splitter>:
            HTML Code:
            <int:splitter input-channel="channel1" output-channel="channel2" ref="fileSplitter"
            method="split" />
            <bean id="fileSplitter" class="gov.noaa.ngdc.multibeam.GroovyMultibeamFile Splitter" />
            But your payload in the splitter's 'input-channel' should really be a java.io.File, not String...

            Comment


            • #7
              Perfect! just specifying the method in the splitter works fine. My input-channel is not explicitly typed, but is passing java.io.File.

              Thanks for being so helpful with my questions.

              --john

              Comment

              Working...
              X