Search code examples
javaapache-camelxercesspring-camel

SAXParseException with Camel 4


org.xml.sax.SAXParseException; lineNumber: 4268; columnNumber: 51; cos-nonambig: "http://camel.apache.org/schema/spring":onFallback and "http://camel.apache.org/schema/spring":onFallback (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.

      at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
      at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.xs.XSConstraints.reportSchemaError(Unknown Source)
      at org.apache.xerces.impl.xs.XSConstraints.fullSchemaChecking(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
      at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)

I'm getting this error when trying to create a new schema from camel-spring.xsd after updated Camel version to 4.0.4 and Java 17

The code is this one, and the error happens in the last line:

import com.google.common.io.Resources;

import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import java.io.ByteArrayInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


public class Camel
{

    public static void main( String[] args ) throws Exception
    {
       SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

       List<Source> tmp = new ArrayList();

       String loc = "camel-spring.xsd";

       URL url = Resources.getResource(loc);
       byte[] bytes = Resources.toByteArray(url);
       StreamSource src = new StreamSource(new ByteArrayInputStream(bytes));
       tmp.add(src);

       schemaFactory.newSchema((Source[]) tmp.toArray(new Source[tmp.size()]));
    }
}

Have you ever seen this error?

I have seen that up camel-spring.xsd 4.x (https://camel.apache.org/schema/spring/) on circuitBreakerDefinition element has two "onFallBack" elements and this is the error. When I comment one of those, I don't get an error. But I can't modify the jar, do you know if there is a way to get the schema from the xsd Camel 4.x?

camel-spring.xsd


Solution

  • You could try setting this feature to false:

    schemaFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
    

    This (very old) documentation mentions that "unique particle attribution" is one of the checks turned off.