1
votes

I'm new in Spring Integration and i've been triyng some examples on the net, and I found that very helpful repo on github :

spring-integration-samples

For a better anderstanding I tried combinig some example, but then got stuck, my goal was to use the example of ws-inbound-gateway with the file example in order to create a file with the WS request text using the file outbound-gateway and then send back the response of the WS.

For that I did the folowing modifications to the inbound-gateway-config.xml of the ws-inbound-gateway example:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
    xmlns:int-file="http://www.springframework.org/schema/integration/file"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration/file
        http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">

    <int:channel id="input"/>
    
    <int-ws:inbound-gateway id="ws-inbound-gateway" request-channel="input"/>

    <int-file:outbound-gateway id="mover" request-channel="input"
                               reply-channel="output"
                               directory="file:${java.io.tmpdir}/spring-integration-samples/output" />

    <int:channel id="output"/>
    
    <int:service-activator input-channel="output">
        <bean class="org.springframework.integration.samples.ws.SimpleEchoResponder"/>
    </int:service-activator>        
</beans>

The rest still the same.

Unfortunally i get bthe following Exception when i try to send a request to the WS:

org.springframework.ws.client.WebServiceTransportException: Erreur Interne de Servlet [500]
    at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:695)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:506)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:446)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:429)
    at org.springframework.integration.samples.ws.InContainerTests.testWebServiceRequestAndResponse(InContainerTests.java:52)

and then when i tried entring the link in my browser i got:

cause mère

org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 75; cvc-complex-type.2.4.c : Le caractère générique concordant est strict, mais aucune déclaration ne peut être trouvée pour l'élément 'int-file:outbound-gateway'.
    com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
...

I don't know if I'm missing a declaration in my web.xml or am I getting the chanelling wrong. Thanks in advence ^^

1
I got it. Instead of using the outbound gateway i should have used the FileWritingMessageHandler in a serviceActivator and give a transformed version of my message.Iob

1 Answers

1
votes

Using a transformer to transform the DOM message to a String message and the send it to a service activator. like so:

<int-ws:inbound-gateway id="ws-inbound-gateway" request-channel="input"/>

    <int:channel id="input"/>

    <int:transformer input-channel="input" output-channel="transform" >
        <bean class="org.springframework.integration.samples.ws.SimpleTransformerResponder"/>
    </int:transformer>

    <int:channel id="transform"/>

    <int:service-activator input-channel="transform" output-channel="next">
        <bean class="org.springframework.integration.file.FileWritingMessageHandler" >
            <constructor-arg name="destinationDirectory" value="file:${java.io.tmpdir}/"/>
        </bean>
    </int:service-activator>

    <int:channel id="next"/>

    <int:service-activator input-channel="next">
        <bean class="org.springframework.integration.samples.ws.SimpleEchoResponder" />
    </int:service-activator>

the transformer bean:

public class SimpleTransformerResponder {
    public String transform(DOMSource request) {
        return request.getNode().getTextContent();
    }
}

and the response bean

public class SimpleEchoResponder {

    public Source issueResponseFor(File request) {
        return new DomSourceFactory().createSource(
                "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">" +
                        request.getAbsoluteFile() + "</echoResponse>");
    }

}

the result is a file with the content of the initial message created, and the response contains the path of the file created.

"Learning hard ^^ "