Camel route using spring-ws client sometimes raises javax.xml.transform.stax.StAXSource exception

I have a camel "seda" route that contains code approximately:

JaxbDataFormat jaxb = new JaxbDataFormat(false); jaxb.setContextPath("com.example.data.api"); from("seda:validate") .marshal(jaxb) .to("spring-ws:" + getDataServiceURL()) .unmarshal(jaxb) 

I am sending an object from com.example.data.api, the JaxbDataFormat formatter sets it as a SOAP request and passes it via wo spring -ws to actually send to my service. It works like a charm most of the time.

I say "most" because from time to time spring-ws throws an exception like:

 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) 

The kernel of this error message is: "Cannot convert source of type javax.xml.transform.stax.StAXSource."

None of this makes sense. Jaxb marshalling should already make sure that the object in question is an XML string (according to any debugging protocol I am doing). In addition, this exact code works most of the time and only occasionally fails. It seems random.

For example, I checked the test just a few minutes ago when I sent a message to my route and received this error. Then I restarted my service and resubmitted the same message ... and it worked like a charm. The same code; the same environment; the same test - two different results.

It is an accident that makes it so crazy. Any ideas what I should look for to make sure this never happens?

+4
source share
1 answer

The problem is not with Camel, but Spring -WS. Modification of the Transformer FactoryClass in the WS template configuration will 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> 

If you are still encountering a problem, tell spring WS config and test case

+1
source

All Articles