1
2
3
4
5
6
7
8
9
10
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 {
37 private final static Logger log = Logger.getLogger( AbstractSoapVersion.class );
38
39 public void validateSoapEnvelope( String soapMessage, List<XmlError> errors )
40 {
41 List<XmlError> errorList = new ArrayList<XmlError>();
42
43 try
44 {
45 XmlOptions xmlOptions = new XmlOptions();
46 xmlOptions.setLoadLineNumbers();
47 xmlOptions.setValidateTreatLaxAsSkip();
48 xmlOptions.setLoadLineNumbers( XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT );
49 XmlObject xmlObject = getSoapEnvelopeSchemaLoader().parse( soapMessage, getEnvelopeType(), xmlOptions );
50 xmlOptions.setErrorListener( errorList );
51 xmlObject.validate( xmlOptions );
52 }
53 catch( XmlException e )
54 {
55 if( e.getErrors() != null )
56 errorList.addAll( e.getErrors() );
57
58 errors.add( XmlError.forMessage( e.getMessage() ) );
59 }
60 catch( Exception e )
61 {
62 errors.add( XmlError.forMessage( e.getMessage() ) );
63 }
64 finally
65 {
66 for( XmlError error : errorList )
67 {
68 if( error instanceof XmlValidationError && shouldIgnore( ( XmlValidationError )error ) )
69 {
70 log.warn( "Ignoring validation error: " + error.toString() );
71 continue;
72 }
73
74 errors.add( error );
75 }
76 }
77 }
78
79 protected abstract SchemaTypeLoader getSoapEnvelopeSchemaLoader();
80
81 public boolean shouldIgnore( XmlValidationError error )
82 {
83 QName offendingQName = error.getOffendingQName();
84 if( offendingQName != null )
85 {
86 if( offendingQName.equals( new QName( getEnvelopeNamespace(), "encodingStyle" ) ) )
87 {
88 return true;
89 }
90 else if( offendingQName.equals( new QName( getEnvelopeNamespace(), "mustUnderstand" ) ) )
91 {
92 return true;
93 }
94 }
95
96 return false;
97 }
98
99 public abstract SchemaType getFaultType();
100
101 public abstract SchemaType getEnvelopeType();
102 }