Categories
Articles

Apache CXF – Code First – Schema validation demystified

In my previous article, I talked about how you can use schemaLocation property to override default CXF behaviour for Code First approach. But the approach had one major problem – Defining entire schema structure in one XSD file.

After spending few hours finding an option to get rid of this problem, I could finally found one tweak. The tweak is all about configuration and having an appropriate directory structure so that CXF can make use of already defined XSD structure to validate SOAP requests. Just follow next few steps, we will be evaluating it by considering one sample example.

1. Define XSD with required structure and include/import the XSDs you want to define as common structures. In my case here is the XSD structure.
XSD Structure

2. The starting point for above structure is valueobjects.xsd and it includes one more XSD. (common/commontypes.xsd). The type of firstName element is referenced from commontypes.xsd.

valueobjects.xsd



	
		
			
			
			
			
		
	

CommonTypes.xsd