Camel Exception: Source parameter of type 'javax.xml.transform.stax.StAXSource' is not accepted by this validator.

Solution In Progress - Updated -

Issue

Similar behaviour to that described in MR-685.

In our camel routes, we have marshalling via a configured JaxbDataFormat, followed by validation via an XSD provided on classpath.

Most of the time, the routes work as expected. However, on some runs of JBoss, we see "Source parameter of type 'javax.xml.transform.stax.StAXSource' is not accepted by this validator." thrown.

Basically, to reproduce, we had to restart JBoss a bunch of times.

Through some debugging we found that upon marshalling, the exchange body is of type byte[]; the type converter is looked up in ValidatingProcessor with the code:

TypeConverter tc = exchange.getContext().getTypeConverterRegistry().lookup(Source.class, body.getClass());

The TypeConverter returned varies on different runs of JBoss. In most cases, the TypeConverter returned does not cause issues.
InstanceMethodTypeConverter:

public org.apache.camel.BytesSource org.apache.camel.converter.jaxp.XmlConverter.toBytesSource(byte[])

However, in some instances,
InstanceMethodTypeConverter:

public javax.xml.transform.stax.StAXSource  org.apache.camel.converter.jaxp.XmlConverter.toStAXSource(byte[],org.apache.camel.Exchange)  throws javax.xml.stream.XMLStreamException

is returned which causes the aforementioned exception.

Unsure if related, but when logging at TRACE level on org.apache.camel.impl.converter.DefaultTypeConverter, we see that in the working case, the BytesSource converter is registered first, and in the problematic case, the StAXSource converter is registered first.

For now we are working around by using convertBodyTo to convert explicitly to StreamSource prior to validation.

Environment

  • JBoss Fuse Service Works 6.0.0
  • Camel 2.10.0.redhat-60024

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.