我有一个主要流程,它暴露了一个网络服务: -
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>
现在我有另一个流程,它是这个主要流程的代理流程: -
<flow name="ProxyFlow" doc:name="ProxyFlow" processingStrategy="synchronous">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8086" path="proxy/mainData" doc:name="HTTP" />
<!-- This is for SOAP Request validation -->
<message-filter onUnaccepted="ValidationFailFlow" doc:name="filter to validate xml against xsd" throwOnUnaccepted="true" >
<mulexml:is-xml-filter />
</message-filter>
<!-- ends -->
<cxf:proxy-service namespace="http://services.test.com/schema/MainData/V1" service="MainData" payload="envelope" wsdlLocation="MainData.wsdl" doc:name="SOAP"/>
<cxf:proxy-client payload="envelope"
doc:name="SOAP" />
<http:outbound-endpoint exchange-pattern="request-response"
host="localhost" port="8082" path="mainData" method="POST" doc:name="HTTP" />
</flow>
<!-- This sub flow contains the message that need to be displayed in case of validation fails from validation filter -->
<sub-flow name="ValidationFailFlow" doc:name="ValidationFailFlow">
<logger message="SOAP Request is not valid!!" level="INFO" doc:name="Logger"/>
<set-payload value="SOAP Request is not valid .... Message has been rejected by filter." doc:name="Set Payload"/>
</sub-flow>
<!-- ends -->
现在的问题是......由于我在代理流程中使用了验证过滤器 <mulexml:is-xml-filter />
,因此Web服务请求得到验证..但在这种情况下,有效的SOAP请求是抛出异常...例如..以下SOAP请求有效: -
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:insertDataRequest>
<v1:Id>55</v1:Id>
<v1:Name>ghghg</v1:Name>
<v1:Age>666</v1:Age>
<v1:Designation>hghghgh</v1:Designation>
</v1:insertDataRequest>
</soapenv:Body>
</soapenv:Envelope>
但它抛出以下异常: -
java.lang.RuntimeException: Couldn't parse stream.
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1262)
at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:105)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
at org.mule.module.cxf.CxfInboundMessageProcessor.sendToDestination(CxfInboundMessageProcessor.java:338)
at org.mule.module.cxf.CxfInboundMessageProcessor.process(CxfInboundMessageProcessor.java:144)
at org.mule.module.cxf.config.FlowConfiguringMessageProcessor.process(FlowConfiguringMessageProcessor.java:48)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
Caused by: com.ctc.wstx.exc.WstxIOException: Attempted read from closed stream.
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:536)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:585)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:610)
at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:316)
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1260)
... 97 more
Caused by: java.io.IOException: Attempted read from closed stream.
at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:160)
at com.ctc.wstx.io.BaseReader.readBytes(BaseReader.java:155)
at com.ctc.wstx.io.UTF8Reader.loadMore(UTF8Reader.java:368)
at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:111)
at com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:250)
at com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:133)
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:531)
... 101 more
关注 SOAP响应: -
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Couldn't parse stream.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
请帮助...如何使用<mulexml:is-xml-filter />
验证SOAP请求以及异常对有效SOAP请求的含义是什么?
答案 0 :(得分:2)
问题是过滤器使用流,因此cxf代理服务没有任何数据可供使用。
在过滤器之前将对象添加到字符串转换器以将请求加载到内存中。然后它可以由cxf代理服务重新读取。
这样的事情:
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8086" path="proxy/mainData" doc:name="HTTP" />
<!-- Transform to String so we can reread the payload multiple times -->
<object-to-string-transformer />
<!-- This is for SOAP Request validation -->
<message-filter onUnaccepted="ValidationFailFlow" doc:name="filter to validate xml against xsd" throwOnUnaccepted="true" >
<mulexml:is-xml-filter />
</message-filter>
<!-- ends -->