I am having the same problem. I set one of my nodes to have a minimum length and I deleted the corresponding data from the xml file. When I run the batch chunk, it gets to the processor with the field being blank. I expected batch to throw a validation exception for that node (before batch gets to the processor I would imagine). Here's my code:
Code:
@Bean
public MultiResourceItemReader XMLMultiResourceReader() throws Exception {
ExtendedMultiResourceItemReader multiResourceItemReader = new ExtendedMultiResourceItemReader();
multiResourceItemReader.setStrict(true);
multiResourceItemReader.setResources(new PathMatchingResourcePatternResolver()
.getResources(fileReadPath));
multiResourceItemReader.setDelegate(getLegalZoomXMLReader());
return multiResourceItemReader;
}
public StaxEventItemReader<PartnerPurchaseOrder> getLegalZoomXMLReader() {
StaxEventItemReader<PartnerPurchaseOrder> staxEventItemReader = new StaxEventItemReader<PartnerPurchaseOrder>();
staxEventItemReader.setFragmentRootElementName("order");
staxEventItemReader.setUnmarshaller(getXMLUnmarshaller());
return staxEventItemReader;
}
@SuppressWarnings("rawtypes")
private Unmarshaller getXMLUnmarshaller() {
Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
Class[] classesToMap = {com.dbcc.ecomm.core.vo.PartnerPurchaseOrder.class,
com.dbcc.ecomm.core.entity.ApplicationUser.class};
unmarshaller.setClassesToBeBound(classesToMap);
Resource classResource = new ClassPathResource("sample-schema.xsd");
unmarshaller.setSchemaLanguage(XMLConstants.W3C_XML_SCHEMA_NS_URI);
unmarshaller.setSchema(classResource);
return unmarshaller;
}
Here is my xsd file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="orders">
<xs:complexType>
<xs:sequence>
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="status">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="user">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="email"/>
<xs:element type="xs:string" name="first-name"/>
<xs:element type="xs:string" name="last-name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is a sample xml file:
Code:
<?xml version="1.0"?>
<orders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="sample-schema.xsd">
<order>
<status></status>
<user>
<email>test@testtestwewewetest.com</email>
<first-name>sdfsdf</first-name>
<last-name>sdfsdfsdf</last-name>
</user>
</order>
</orders>
As you can see, there is validation to check that the minimum length for the status node is 5. It is 0 in the xml file. I do not get any validation exceptions of any kind and the code moves on to the batch processor with that value as "" in the object that this xml file is mapped to. I checked that the code is checking the right location for the xsd file (I just outputted resource.getUrlPath() right after the resource value is set. What am I doing wrong?