使用spring-ws客户端的Camel路由偶尔会抛出javax.xml.transform.stax.StAXSource异常 [英] Camel route using spring-ws client occasionally throws javax.xml.transform.stax.StAXSource exception

查看:20
本文介绍了使用spring-ws客户端的Camel路由偶尔会抛出javax.xml.transform.stax.StAXSource异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条包含大致代码的骆驼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 请求,并将它传递给 wo 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.

例如,我在几分钟前运行了一个测试,在该测试中我向我的路由发送了一条消息并收到此错误.然后我重新启动了我的服务并重新发送完全相同的消息......它就像一个魅力.相同的代码;相同的环境;同样的测试——两​​个不同的结果.

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客户端的Camel路由偶尔会抛出javax.xml.transform.stax.StAXSource异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆