Spring集成文件outbound-gateway和web Service

时间:2015-03-18 10:28:12

标签: spring web-services spring-integration

我是 Spring Integration 的新手,我已经在网上找到了一些例子,我在github上找到了非常有用的回购:

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中遗漏了一个声明,或者我是否正在犯错。 感谢advence ^^

1 个答案:

答案 0 :(得分:1)

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

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

}

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

“努力学习^^”