Results 1 to 8 of 8

Thread: Use of XsltPayloadTransformer

  1. #1
    Join Date
    Oct 2008
    Location
    Auxerre, France
    Posts
    16

    Question Use of xslt-transformer

    Hi !

    I use yesterday's trunk version and tried

    Code:
    <message-bus />
    
    <file:inbound-channel-adapter id="inputChannel"
    	directory="file:C:/input">
    	<poller>
    		<interval-trigger interval="1000" />
    	</poller>
    </file:inbound-channel-adapter>
    
    <file:outbound-channel-adapter id="outputChannel" directory="C:/output" />
    
    <si-xml:xslt-transformer input-channel="inputChannel" 
    xsl-resource="file:C:/test.xslt" output-channel="outputChannel" />
    with test.xslt :
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<xsl:output method="text"/>
    	<xsl:template match="/person">
    		<xsl:value-of select="name"/>
    	</xsl:template>
    </xsl:stylesheet>
    and test.xml in the input directory :
    Code:
    <?xml version="1.0"?>
    <persons>
    	<person>
    		<name>John</name>
    		<family-name>Smith</family-name>
    	</person>
    </persons>
    The test.xml input file is read but i have nothing in the output directory and no visible error/exception.

    Where I am wrong ?

    Thank you for your help !
    Last edited by OsoPardo; Oct 21st, 2008 at 09:54 AM.

  2. #2
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    There are a few problems here. If you increase the logging level you should see with your current configuration that the message was being rejected by the Xslt transformer with an error message "Failed to create Source for payload type java.io.File" since it did not know what to do with the payload. The message was then added to the default error channel. Currently the Xslt transformer supports Source, String and Document payloads. The file inbound channel adapter by default passes a File instance as the payload hence the Xslt transformer was rejecting the message.

    The below configuration addresses this by using an instance of file-to-string-transformer before passing the message to the Xslt transformer.

    In addition the Xslt transformer will by default return a Result instance so the below configuration also adds a result transformer to convert the output of the Xslt to a String so it can then be correctly written to the output file.

    Code:
    <si:message-bus />
    
    <si:channel id="tranformChannel" />
    
    <file:inbound-channel-adapter id="inputChannel" directory="file:./input">
    	<si:poller>
    		<si:interval-trigger interval="1000" />
    	</si:poller>
    </file:inbound-channel-adapter>
    
    
    <file:file-to-string-transformer id="toStringTransformer" input-channel="inputChannel" output-channel="transformChannel"/>
    
    <file:outbound-channel-adapter id="outputChannel" directory="./output" />
    
    <si-xml:xslt-transformer input-channel="transformChannel" xsl-resource="classpath:test.xslt" output-channel="outputChannel" result-transformer="resultTransformer" />
    		
    		
    <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />
    Jonas Partner
    OpenCredo

  3. #3
    Join Date
    Oct 2008
    Location
    Auxerre, France
    Posts
    16

    Smile

    Thank you !

    Just to inform, that's require the library spring-xml-1.5.3.jar from Spring Web Service.

  4. #4

    Default

    Quote Originally Posted by JonasPartner View Post
    There are a few problems here. If you increase the logging level you should see with your current configuration that the message was being rejected by the Xslt transformer with an error message "Failed to create Source for payload type java.io.File" since it did not know what to do with the payload. The message was then added to the default error channel. Currently the Xslt transformer supports Source, String and Document payloads. The file inbound channel adapter by default passes a File instance as the payload hence the Xslt transformer was rejecting the message.

    The below configuration addresses this by using an instance of file-to-string-transformer before passing the message to the Xslt transformer.

    In addition the Xslt transformer will by default return a Result instance so the below configuration also adds a result transformer to convert the output of the Xslt to a String so it can then be correctly written to the output file.

    Code:
    <si:message-bus />
    
    <si:channel id="tranformChannel" />
    
    <file:inbound-channel-adapter id="inputChannel" directory="file:./input">
    	<si:poller>
    		<si:interval-trigger interval="1000" />
    	</si:poller>
    </file:inbound-channel-adapter>
    
    
    <file:file-to-string-transformer id="toStringTransformer" input-channel="inputChannel" output-channel="transformChannel"/>
    
    <file:outbound-channel-adapter id="outputChannel" directory="./output" />
    
    <si-xml:xslt-transformer input-channel="transformChannel" xsl-resource="classpath:test.xslt" output-channel="outputChannel" result-transformer="resultTransformer" />
    		
    		
    <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />

    Hi I am new member to Spring Source. Firstoff all hello to every members..
    Now my question is that ..How to run this from a test class by passing an XML..Please provide the complete code..

  5. #5

    Default

    Hi,
    How can I test this fuctionality using an test case.simple from a java main function..Plz provide the complete code..

  6. #6
    Join Date
    Nov 2008
    Location
    Swansea, Wales
    Posts
    202

    Default

    You cant pass in the XML via a main method, it's a file inbound adapter polling a directory.

    In the main method you just need to load the application context.

    Code:
    public static void main(String[] args) {
    		new ClassPathXmlApplicationContext("applicationContext.xml", SpringIntegrationDemo.class);
    	}
    Then put a file containing the XML in the directory being polled. In this case ./input In order to run this example you'll also need to create the XSTL too.

  7. #7

    Default

    Actualy I need to transform using XSL, an input XML ie to be generated at runtime and and to get an output XML of another format..by using Spring Integration(using XSLpayload transformer in Spring Integration ). So can you tell me the whole process how to send an input XMl file and get an Output XML file.
    Please provide me the whole code.ie how I need to do the configuration in App-Context.xml andusing the testclass to do the test.

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You should have a look at the XML sample included in the distribution. That includes an XsltTransformer.

Tags for this Thread

Posting Permissions

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