Results 1 to 7 of 7

Thread: Newbie Transformer How-To question

  1. #1
    Join Date
    May 2011
    Posts
    4

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

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

  3. #3
    Join Date
    May 2011
    Posts
    4

    Default 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!!

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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.

  5. #5
    Join Date
    May 2011
    Posts
    4

    Default

    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.

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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 "/>

  7. #7
    Join Date
    May 2011
    Posts
    4

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •