Announcement Announcement Module
Collapse
No announcement yet.
Newbie Transformer How-To question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie Transformer How-To question

    Hello All,
    How do I use a MethodInvokingTransformer? I have a message going to a channel I want a method to be called on the message's payload and the results passed to the next channel. I was assuming MethodInvokingTransformer would be the way to go but am not sure what the XML would look like. There is no shortcut like object-to-string-transformer, etc... has. What has thrown me for a loop is the fact that the MethodInvokingTransformer does not have an empty constructor. Any help would be greatly appreciated.

    Thank You.

  • #2
    In XML, you can just do this:
    Code:
    <transformer input-channel="in" ref="someBean" method="someMethod" output-channel="out"/>
    Does that help?
    -Mark

    Comment


    • #3
      Still not sure I am doing it right.

      Here is my example:
      Code:
          <channel id="taskQueuePollerExceptionChannel"/>
          <transformer input-channel="taskQueuePollerExceptionChannel" method="getUow" output-channel="logChannel">
              <beans:bean class="org.springframework.integration.transformer.MethodInvokingTransformer" />
          </transformer>
      The problem is MethodInvokingTransformer does not have a 0 argument constructor. I want to call getUow on the payload of the message, then send the response to the next channel.

      Thanks for the fast reply on a Friday!!

      Comment


      • #4
        What object do you want to call getUoW on? *That* is the object you should define as the inner bean. In other words, don't worry about MethodInvokingTransformer - for the most part, you can consider that a class that is internal to the framework.

        Comment


        • #5
          I have a channel 1 that returns object X and sends it to channel 2. I want the channel 2 to call getUoW on X and send it to channel 3. I may be using the wrong mechanism here. It would be easy to write my own transformer but I am trying to use pre-existing things first.

          Thanks Again.

          Comment


          • #6
            Ah, I see. Now I understand what you are doing You just need to use the Spring Expression Language if you want to invoke a method on the *payload* object. Something like this should work:
            Code:
            <transformer input-channel="in" expression="payload.uow" output-channel="out "/>

            Comment


            • #7
              Thank you
              That was exactly what I wanted. It was too easy, threw me off the trail.

              Comment

              Working...
              X