【问题标题】:Spring integration file outbound-gateway and webServiceSpring集成文件outbound-gateway和webService
【发布时间】:2015-05-21 02:09:29
【问题描述】:

我是 Spring Integration 的新手,我一直在网上尝试一些示例,我发现 github 上的 repo 非常有用:

spring-integration-samples

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

为此,我对 ws-inbound-gateway 示例的 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)

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

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 中遗漏了声明,或者我的 chanelling 错误。 提前谢谢^^

【问题讨论】:

  • 我明白了。而不是使用出站网关,我应该在 serviceActivator 中使用 FileWritingMessageHandler 并给出我的消息的转换版本。

标签: spring web-services spring-integration


【解决方案1】:

使用转换器将 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>

变压器 bean:

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

}

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

“努力学习^^”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    相关资源
    最近更新 更多