Spring 集成文件 outbound-gateway 和 webService

Spring integration file outbound-gateway and webService

我是 Spring Integration 的新手,我一直在尝试网上的一些示例,我发现 [=36= 上的回购非常有用] :

spring-integration-samples

为了更好地理解我尝试结合一些示例,但后来卡住了,我的目标是将 ws-inbound-gateway 的示例与文件示例一起使用,以便使用 WS 请求文本创建一个文件文件出站网关,然后发回 WS 的响应。

为此,我对 ws-inbound-gateway 示例的入站网关-config.xml 进行了以下修改:

    <?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>

其他还是一样

不幸的是,当我尝试向 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)

然后当我尝试在浏览器中输入 link 时,我得到:

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)
...

我不知道我是否在我的 web.xml 中遗漏了声明,或者我是否理解错误。 提前致谢^^

使用转换器将 DOM 消息转换为字符串消息并将其发送到服务激活器。像这样:

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

变形金刚豆:

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

和响应 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>");
    }

}

结果是一个包含创建的初始消息内容的文件,响应包含创建的文件的路径。

"Learning hard ^^ "