Announcement Announcement Module
Collapse
No announcement yet.
Comparison result-factory vs result-transformer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comparison result-factory vs result-transformer

    Dear Members

    In section
    24.3 Namespace support for xml transformers

    We have this information

    The namespace support for the marshalling transformer requires an input channel, output channel and a reference to a marshaller. The optional result-type attribute can be used to control the type of result created, valid values are StringResult or DomResult (the default). Where the provided result types are not sufficient a reference to a custom implementation of ResultFactory can be provided as an alternative to setting the result-type attribute using the result-factory attribute. An optional result-transformer can also be specified in order to convert the created Result after marshalling.
    Is possible expand more the idea on the documentation, even better, if some snippet code would be include, about :
    1. when and why use result-factory and result-transformer?
    2. is possible use both in the same time?, If not, which exception I should receive?

    I am understanding we have two types by default StringResult and DomResult, and with result-factory I am able to create a third own type (for example XYXResult). Here arise an obvious question, under which circumstances, the types String or DOM are not useful?, or, what feature is missing for each one?, or, what feature is lacked for each one?. To make me decide to create my own type?

    And I am confused about the orange part exactly in this part

    in order to convert the created Result after marshalling
    Exactly what means?, under which circumstances I would select this? and what is the specific behaviour

    Exists an impact about performance of each one for production?

    Thanks in advanced

  • #2
    The 'result-type' is to specify which type of Result object do you want to deal with. It could be DomResult, StringResult etc. Based on the result-type a particular result factory will be applied. by default it is DomResult. Buit you can also specify 'result-factory' directly. Soi 'result-type' and result-factory' are mutually exclusive.
    Now, once the result of a particular type is created it could also be transformed by specifying 'result-transformer'

    Does that help?

    Comment


    • #3
      Hello Oleg

      Thanks for your time in this reply

      The 'result-type' is to specify which type of Result object do you want to deal with. It could be DomResult, StringResult etc.
      Totally agree and I understood, BTW I am receiving an exception when I work with the default DOMResult, writing a post right now in other thread

      Based on the result-type a particular result factory will be applied.
      I think it is internally handle by Spring Integration with its API because the documentation and in my code I only use for example

      Code:
      <int-xml:marshalling-transformer marshaller="castorMarshaller"
      					 result-type="StringResult"
      					 input-channel="input"
      					 output-channel="xml"									 								 	
      	/>
      and work fine, no problem

      Buit you can also specify 'result-factory' directly.

      Here my doubt and confusion
      1. why specify directly this attribute?
      2. result-factory replace result-type?
      3. is possible use both?

      none snippet code on the documentation working with result-factory is available, thats the reason of my doubts


      Soi 'result-type' and result-factory' are mutually exclusive.
      OK

      Now, once the result of a particular type is created it could also be transformed by specifying 'result-transformer'
      Could I consider this like a post creation manipulation process? And now for here arise a new question

      Why apply a transformation after the object is created? and not while its own initial creation process?, I think the answer of my question should be included below of the snippet code shown in the documentation

      Code:
      <si-xml:marshalling-transformer
          input-channel="marshallingTransformerWithResultTransformer"
          output-channel="output"
          marshaller="marshaller"
          result-transformer="resultTransformer" />
      
      <bean id="resultTransformer"
            class="org.springframework.integration.xml.transformer.ResultToStringTransformer"/>
      I mean in marshaller="marshaller", what job or what is the code used on "marshaller"?, which implementation was used? Castor?, because ResultToStringTransformer API said

      Converts the passed Result to an instance of String. Supports StringResult and DOMResult
      Here arise other question about the bold part, where and how was passed this Result?

      Does that help?
      Again thanks for your time, your answer was useful but now I have new ones

      I know you are very busy, when you get some free time, give me a hand please

      Thanks in advanced

      Comment


      • #4
        result-factory and result-type are mutually exclusive. You can only use one of the other (whichever is more convenient for you). As far as why not do everything at once, its all about separation of responsibility. You may already have a transformer that can take a StringResult, but unfortunately you don't have StringResult. That means you have to convert your payload to StringResult and only than your transformer could be applied.

        Comment


        • #5
          Hello Oleg

          Thanks for the reply

          result-factory and result-type are mutually exclusive. You can only use one of the other (whichever is more convenient for you).
          OK

          As far as why not do everything at once, its all about separation of responsibility.
          OK

          You may already have a transformer that can take a StringResult, but unfortunately you don't have StringResult. That means you have to convert your payload to StringResult
          Now I see clearly the picture

          Thanks a lot!

          Comment

          Working...
          X