使用spring-ws客户端的骆驼路由偶尔会抛出javax.xml.transform.stax.StAXSource异常 [英] Camel route using spring-ws client occasionally throws javax.xml.transform.stax.StAXSource exception
问题描述
我有一个骆驼'seda'路线,大致包含代码:
I have a camel 'seda' route that contains code roughly:
JaxbDataFormat jaxb = new JaxbDataFormat(false);
jaxb.setContextPath("com.example.data.api");
from("seda:validate")
.marshal(jaxb)
.to("spring-ws:" + getDataServiceURL())
.unmarshal(jaxb)
我从 com.example.data.api 发送一个对象,JaxbDataFormat 格式化程序将它设置为一个 SOAP 请求,并将它传递给 spring-ws 以实际发送到我的服务.这在大多数情况下都很有效.
I send an object from com.example.data.api, the JaxbDataFormat formatter sets it up as a SOAP request and passes it along wo spring-ws to actually send to my service. This works like a charm most of the time.
我说大多数"是因为 spring-ws 时不时地抛出一个异常,如下所示:
I say "most" because every now and then, spring-ws throws an exception like so:
org.springframework.ws.client.WebServiceTransformerException: Transformation error: Can't transform a Source of type javax.xml.transform.stax.StAXSource; nested exception is javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:608)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:479)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:470)
at org.apache.camel.component.spring.ws.SpringWebserviceProducer.process(SpringWebserviceProducer.java:81)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
其中的核心是这条错误消息:无法转换 javax.xml.transform.stax.StAXSource 类型的源".
The core of that is this error message: "Can't transform a Source of type javax.xml.transform.stax.StAXSource".
这些都没有意义.Jaxb 编组已经确保所讨论的对象是一个 XML 字符串(根据我所做的任何调试日志记录).此外,这个确切的代码大部分时间都可以工作,只是偶尔会失败.它看起来是随机的.
None of that makes sense. The Jaxb marshalling will have already made sure that the object in question is an XML string (according to any debug logging I do). Furthermore, this exact code works most of the time and only occasionally will fail. It appears random.
例如,我在几分钟前运行了一个测试,我在我的路由中发送了一条消息并收到了这个错误.然后我重新启动了我的服务并重新发送了 exact 相同的消息......它就像一个魅力.相同的代码;相同的环境;相同的测试——两个不同的结果.
For instance, I ran a test just a few minutes ago where I sent a message into my route and got this error. I then restarted my service and resend the exact same message... and it worked like a charm. Same code; same environment; same test -- two different results.
正是这种随机性让这一切变得如此令人抓狂.我应该寻找什么来确保这种情况永远不会发生?
It's this randomness that makes this so maddening. Any ideas what I should be looking for to making sure this never happens?
推荐答案
问题不在于 Camel,而在于 Spring-WS.在 WS 模板配置中修改 transformerFactoryClass 会起作用
The issue is not with Camel but Spring-WS. Modifying the transformerFactoryClass in WS template config would work
<bean id="baseCamelMarshallerWSTemplate" class="org.springframework.ws.client.core.WebServiceTemplate" scope="prototype">
<constructor-arg ref="messageFactory" />
<property name="messageSender">
<ref bean="httpSender"/>
</property>
<property name="checkConnectionForError" value="true"/>
**<property name="transformerFactoryClass" value="com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>**
</bean>
如果你仍然遇到问题,请分享 spring WS 配置和测试用例
If you still face the issue, please share spring WS config and a test case
这篇关于使用spring-ws客户端的骆驼路由偶尔会抛出javax.xml.transform.stax.StAXSource异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!