我有一个要求,即Web服务的请求有效负载必须在路由中的多个活动中使用。在我的特定情况下,传入请求用于执行两个xsl转换。 为了能够访问原始有效负载,我试图将其放入标头中,但是一旦我尝试在有效负载上设置标头,它就会抛出与START_ELEMENT / END_ELEMENT相关的异常
我的路线:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="loadGlobalVars">
<camel:from id="_from1" uri="direct:LoadGlobalVariables"/>
<camel:setHeader headerName="_globalVariables" id="_setHeader1">
<camel:simple resultType="org.w3c.dom.Document">resource:classpath:GlobalVars.xml</camel:simple>
</camel:setHeader>
<camel:setHeader headerName="GetValidationCodes" id="_setValidationCodes">
<camel:simple resultType="org.w3c.dom.Document">resource:classpath:ValidationCodes.xml</camel:simple>
</camel:setHeader>
</route>
<camel:route id="loanServiceRoute">
<from id="getTransactionDtls" uri="cxf:bean:loanService?dataFormat=PAYLOAD&loggingFeatureEnabled=true"/>
<camel:setHeader headerName="originalBody">
<camel:simple resultType="org.w3c.dom.Document">${body}</camel:simple>
</camel:setHeader>
<camel:to id="_loadHeaders" uri="direct:LoadGlobalVariables"/>
<camel:to id="ValidateRequest" uri="xslt:xslt/ValidateTransactionReq.xsl?saxon=true"/>
<camel:setHeader headerName="ValidationOutput" id="_setHeader2">
<camel:simple>${body}</camel:simple>
</camel:setHeader>
<camel:to id="UseCaseSelection" uri="xslt:xslt/UseCaseTypeSelection.xsl?saxon=true"/>
<camel:log id="_log1" message="Output from xslt : ${body}"/>
<removeHeaders id="_removeHeaders1" pattern="*"/>
</camel:route>
</camelContext>
如果我删除以下set header,则不会抛出任何异常。
<camel:setHeader headerName="_globalVariables" id="_setHeader1">
<camel:simple resultType="org.w3c.dom.Document">resource:classpath:GlobalVars.xml</camel:simple>
</camel:setHeader>
例外:
java.lang.IllegalStateException: Current event not START_ELEMENT or END_ELEMENT
at com.ctc.wstx.sr.BasicStreamReader.getNamespaceURI(BasicStreamReader.java:799)
at org.apache.cxf.staxutils.DepthXMLStreamReader.getNamespaceURI(DepthXMLStreamReader.java:130)
at org.apache.cxf.staxutils.DepthXMLStreamReader.getNamespaceURI(DepthXMLStreamReader.java:130)
at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:113)
at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:268)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:451)
at net.sf.saxon.event.Sender.send(Sender.java:153)
at net.sf.saxon.Controller.makeSourceTree(Controller.java:1917)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:573)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:185)
at org.apache.camel.builder.xml.XsltBuilder.process(XsltBuilder.java:141)
at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:103)
at org.apache.camel.component.xslt.XsltEndpoint.onExchange(XsltEndpoint.java:131)
at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.asyncInvoke(CxfConsumer.java:156)
at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.invoke(CxfConsumer.java:133)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:254)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:234)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:76)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1129)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1065)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
我试图理解,如何设置标题会使路由出错?
任何帮助表示赞赏!!
答案 0 :(得分:1)
事实证明我能够找到答案。对于其他可能想知道同样问题的人。
cxf组件为有效负载生成流类型(这是我的假设,但很可能是这种情况)。本质上,我只能读一次流,因此,当我再次尝试使用它时,我得到了异常。
您可以添加streamCache = true,这样可以使用多次就绪。
有关详细信息,请参阅:here