4 Replies Latest reply on Mar 7, 2013 8:32 AM by smartgridder

    How to Transform Java to XML with Smooks

    smartgridder

      Hey Folks,

       

      I'm trying to transform a java object into a SOAP message. I use the SmooksAction for this transformation and i want to use FreeMarker within the smooks-config.xml via inline.

      Refering to the Smooks User Guide it is soo easy but im stuck on this !

       

      my smooks-conig.xml looks as follows:

       

      {code:xml}

      <?xml version="1.0" encoding='UTF-8'?>

      <smooks-resource-list      xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"

                                    xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"

                                    xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd">

       

           <core:filterSettings type="SAX" defaultSerialization="false"/>

       

           <resource-config selector="example.SOAPAck">

                     <resource>org.milyn.delivery.DomModelCreator</resource>

           </resource-config>

       

           <ftl:freemarker applyOnElement="example.SOAPAck">

                <ftl:template>

                     <!--

                     <sg:Acknowledge xmlns:sg="http://ack">

                           <sg:MessageType>${SOAPAck.messageType}</sg:MessageType>

                     </sg:Acknowledge>

                     -->

                </ftl:template>

           </ftl:freemarker>

      </smooks-resource-list>

      {code}

       

       

      my question is now to what the applyOnElement-Tag refers to?

      My intention is to add Java Objects to the ESB Message in the action chain and the SmooksAction should transform these Objects into my desired SOAP message.

      This seems to be wrong though.

       

      Thanks in advance for any help!

       

      greetings

        • 1. Re: How to Transform Java to XML with Smooks
          tcunning

          This thread has a really good example with lots of links to the right places in the Smooks documentation :

           

          https://community.jboss.org/thread/164165

          • 2. Re: How to Transform Java to XML with Smooks
            smartgridder

            Hey Tom,

            thank you very much for your reply! I read that thread and it was helpful but i still don't understand the applyOnElement tag.

            So far i created a data-model with hash maps and i would like to use my FreeMarker template when my HashMap with the key "acknowledge" is present.

            My smooks-comfig.xml looks like this:

             

            {code:xml}

            <?xml version="1.0" encoding='UTF-8'?>

            <smooks-resource-list           xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"

                                                                        xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"

                                                                        xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd">

             

                      <core:filterSettings type="SAX" defaultSerialization="true"/>

             

                      <resource-config selector="acknowledge">

                                <resource>org.milyn.delivery.DomModelCreator</resource>

                      </resource-config>

             

                      <ftl:freemarker applyOnElement="acknowledge">

                                <ftl:template>

                                          <!--            

                                          <sg:Acknowledge xmlns:sg="urn:http://monitoring.service.esb.soa.jboss.smartgrid">

                                                    <sg:MessageType>${acknowledge.messageType}</sg:MessageType>

                                          </sg:Acknowledge>

                                          -->

                                    </ftl:template>

                      </ftl:freemarker>

            </smooks-resource-list>

            {code}

             

            My intention is, that the applyOnElement would trigger on that...but unfortunatly it doesn't.

             

            The result after the transformation is this:

             

             

            {code:xml}

                 <map>

                      <entry>

                           <string>acknowledge</string>

                           <map>

                                <entry>

                                     <string>messageType</string>

                                     <string>MeasurementPost</string>

                                </entry>

                           </map>

                      </entry>

                      <entry>

                           <string>PTIME</string>

                           <org.milyn.javabean.context.preinstalled.Time>

                           <startMillis>1362057406847</startMillis>

                           <startNanos>20428606624685</startNanos>

                           </org.milyn.javabean.context.preinstalled.Time>

                      </entry>

                      <entry>

                           <string>PUUID</string>

                           <org.milyn.javabean.context.preinstalled.UniqueID />

                      </entry>

                 </map>

            {code}

             

            any suggestions to that? i would appreciate it!

             

            greetings

            • 3. Re: How to Transform Java to XML with Smooks
              smartgridder

              please help! anyone?!

              • 4. Re: How to Transform Java to XML with Smooks
                smartgridder