Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2002-2010 the original author or authors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.springframework.integration.xml.selector;

Oleg Zhurakousky
 public class XmlValidatingMessageSelector implements MessageSelector {
 	private final Log logger = LogFactory.getLog(this.getClass());
 	private final XmlValidator xmlValidator;
 	private volatile boolean throwExceptionOnRejection;
 	public XmlValidatingMessageSelector(XmlValidator xmlValidator) {
 		Assert.notNull(xmlValidator"XmlValidator must not be null");
 		this. = xmlValidator;

Creates a selector with a default org.springframework.xml.validation.XmlValidator. The validator will be initialized with the provided 'schema' location and 'schemaType'. The valid options for schema type are org.springframework.xml.validation.XmlValidatorFactory.SCHEMA_W3C_XML or org.springframework.xml.validation.XmlValidatorFactory.SCHEMA_RELAX_NG. If no 'schemaType' is provided it will default to org.springframework.xml.validation.XmlValidatorFactory.SCHEMA_W3C_XML;

Throws: if the XmlValidatorFactory fails to create a validator
 	public XmlValidatingMessageSelector(Resource schemaString schemaTypethrows IOException {
 		Assert.notNull(schema"You must provide XML schema location to perform validation");
 		if (!StringUtils.hasText(schemaType)) {
 		this. = XmlValidatorFactory.createValidator(schemaschemaType);
 	public void setThrowExceptionOnRejection(boolean throwExceptionOnRejection) {
 		this. = throwExceptionOnRejection;

Specify the Converter to use when converting payloads prior to validation.
 	public void setConverter(XmlPayloadConverter converter) {
 		Assert.notNull(converter"'converter' must not be null");
 		this. = converter;
 	public boolean accept(Message<?> message) {
 		SAXParseException[] validationExceptions = null;
 		try {
 			validationExceptions = this..validate(this..convertToSource(message.getPayload()));
 		catch (Exception e) {
 			throw new MessageHandlingException(messagee);
 		boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions);
 		if (!validationSuccess) {
				throw new MessageRejectedException(message"Message was rejected due to XML Validation errors"
						new AggregatedXmlMessageValidationException(CollectionUtils.arrayToList(validationExceptions)));
				.debug("Message was rejected due to XML Validation errors");
		return validationSuccess;
New to GrepCode? Check out our FAQ X