1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support.soap;
14
15 import org.apache.log4j.Logger;
16 import org.apache.xmlbeans.*;
17
18 import javax.xml.namespace.QName;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 /***
23 * Common behaviour for all SOAP Versions
24 *
25 * @author ole.matzura
26 */
27
28 public abstract class AbstractSoapVersion implements SoapVersion
29 {
30 private final static Logger log = Logger.getLogger(AbstractSoapVersion.class);
31
32 public void validateSoapEnvelope(String soapMessage, List<XmlError> errors)
33 {
34 List<XmlError> errorList = new ArrayList<XmlError>();
35
36 try
37 {
38 XmlOptions xmlOptions = new XmlOptions();
39 xmlOptions.setLoadLineNumbers();
40 xmlOptions.setValidateTreatLaxAsSkip();
41 xmlOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT);
42 XmlObject xmlObject = getSoapEnvelopeSchemaLoader().parse( soapMessage, getEnvelopeType(), xmlOptions);
43 xmlOptions.setErrorListener(errorList);
44 xmlObject.validate(xmlOptions);
45 }
46 catch ( XmlException e )
47 {
48 if( e.getErrors() != null )
49 errorList.addAll( e.getErrors() );
50
51 errors.add( XmlError.forMessage( e.getMessage() ));
52 }
53 catch (Exception e)
54 {
55 errors.add( XmlError.forMessage( e.getMessage() ));
56 }
57 finally
58 {
59 for( XmlError error : errorList )
60 {
61 if( error instanceof XmlValidationError && shouldIgnore( (XmlValidationError) error ))
62 {
63 log.warn( "Ignoring validation error: " + 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 {
76 QName offendingQName = error.getOffendingQName();
77 if( offendingQName != null )
78 {
79 if( offendingQName.equals( new QName( getEnvelopeNamespace(), "encodingStyle")))
80 {
81 return true;
82 }
83 else if( offendingQName.equals( new QName( getEnvelopeNamespace(), "mustUnderstand")))
84 {
85 return true;
86 }
87 }
88
89 return false;
90 }
91
92 public abstract SchemaType getFaultType();
93
94 public abstract SchemaType getEnvelopeType();
95 }