01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.impl.wsdl.support.soap;
14:
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.apache.log4j.Logger;
21: import org.apache.xmlbeans.SchemaType;
22: import org.apache.xmlbeans.SchemaTypeLoader;
23: import org.apache.xmlbeans.XmlError;
24: import org.apache.xmlbeans.XmlException;
25: import org.apache.xmlbeans.XmlObject;
26: import org.apache.xmlbeans.XmlOptions;
27: import org.apache.xmlbeans.XmlValidationError;
28:
29: /**
30: * Common behaviour for all SOAP Versions
31: *
32: * @author ole.matzura
33: */
34:
35: public abstract class AbstractSoapVersion implements SoapVersion {
36: private final static Logger log = Logger
37: .getLogger(AbstractSoapVersion.class);
38:
39: public void validateSoapEnvelope(String soapMessage,
40: List<XmlError> errors) {
41: List<XmlError> errorList = new ArrayList<XmlError>();
42:
43: try {
44: XmlOptions xmlOptions = new XmlOptions();
45: xmlOptions.setLoadLineNumbers();
46: xmlOptions.setValidateTreatLaxAsSkip();
47: xmlOptions
48: .setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT);
49: XmlObject xmlObject = getSoapEnvelopeSchemaLoader().parse(
50: soapMessage, getEnvelopeType(), xmlOptions);
51: xmlOptions.setErrorListener(errorList);
52: xmlObject.validate(xmlOptions);
53: } catch (XmlException e) {
54: errorList.addAll(e.getErrors());
55: errors.add(XmlError.forMessage(e.getMessage()));
56: } catch (Exception e) {
57: errors.add(XmlError.forMessage(e.getMessage()));
58: } finally {
59: for (XmlError error : errorList) {
60: if (error instanceof XmlValidationError
61: && shouldIgnore((XmlValidationError) error)) {
62: log.warn("Ignoring validation error: "
63: + error.toString());
64: continue;
65: }
66:
67: errors.add(error);
68: }
69: }
70: }
71:
72: protected abstract SchemaTypeLoader getSoapEnvelopeSchemaLoader();
73:
74: public boolean shouldIgnore(XmlValidationError error) {
75: QName offendingQName = error.getOffendingQName();
76: if (offendingQName != null) {
77: if (offendingQName.equals(new QName(getEnvelopeNamespace(),
78: "encodingStyle"))) {
79: return true;
80: } else if (offendingQName.equals(new QName(
81: getEnvelopeNamespace(), "mustUnderstand"))) {
82: return true;
83: }
84: }
85:
86: return false;
87: }
88:
89: public abstract SchemaType getFaultType();
90:
91: public abstract SchemaType getEnvelopeType();
92: }
|