View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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.io.IOException;
16  
17  import javax.xml.namespace.QName;
18  
19  import org.apache.xmlbeans.SchemaType;
20  import org.apache.xmlbeans.SchemaTypeLoader;
21  import org.apache.xmlbeans.XmlBeans;
22  import org.apache.xmlbeans.XmlException;
23  import org.apache.xmlbeans.XmlObject;
24  import org.apache.xmlbeans.XmlOptions;
25  import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
26  
27  import com.eviware.soapui.SoapUI;
28  import com.eviware.soapui.impl.wsdl.support.Constants;
29  
30  public class SoapVersion11 extends AbstractSoapVersion
31  {
32     private final static QName envelopeQName  = new QName(Constants.SOAP11_ENVELOPE_NS, "Envelope");
33     private final static QName bodyQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Body");
34     private final static QName faultQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Fault");
35     private final static QName headerQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Header");
36  	
37     SchemaTypeLoader soapSchema;
38  	SchemaType soapEnvelopeType;
39  	private XmlObject soapSchemaXml;
40  	private XmlObject soapEncodingXml;
41  	private SchemaType soapFaultType;
42  	
43  	public final static SoapVersion11 instance = new SoapVersion11();
44  
45     private SoapVersion11()
46     {
47     	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
48     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
49     	
50     	try
51     	{
52     		XmlOptions options = new XmlOptions();
53           options.setCompileNoValidation();
54           options.setCompileNoPvrRule();
55           options.setCompileDownloadUrls();
56           options.setCompileNoUpaRule();
57           options.setValidateTreatLaxAsSkip();
58     		
59  	   	soapSchemaXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEnvelope.xsd"), options);
60  			soapSchema = XmlBeans.loadXsd(new XmlObject[] { soapSchemaXml });
61  	
62  	   	soapEnvelopeType = soapSchema.findDocumentType( envelopeQName );
63  	   	soapFaultType = soapSchema.findDocumentType( faultQName );
64  	   	
65  	   	soapEncodingXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEncoding.xsd"), options);
66     	}
67     	catch( Exception e )
68     	{
69     		e.printStackTrace();
70     	}
71     	finally
72     	{
73     		Thread.currentThread().setContextClassLoader( contextClassLoader );
74     	}
75     }
76     
77  	public SchemaType getEnvelopeType()
78  	{
79  		return EnvelopeDocument.type;
80  	}
81  	
82  	public String getEnvelopeNamespace()
83  	{
84  		return Constants.SOAP11_ENVELOPE_NS;
85  	}
86  	
87  	public String getEncodingNamespace()
88  	{
89  		return Constants.SOAP_ENCODING_NS;
90  	}
91  
92  	public XmlObject getSoapEncodingSchema() throws XmlException, IOException
93  	{
94  		return soapEncodingXml;
95  	}
96  
97  	public XmlObject getSoapEnvelopeSchema() throws XmlException, IOException
98  	{
99  		return soapSchemaXml;
100 	}
101 	
102 	public String toString()
103 	{
104 		return "SOAP 1.1";
105 	}
106 
107 	public String getContentTypeHttpHeader(String encoding)
108 	{
109 		if (encoding == null || encoding.trim().length() == 0)
110 			return getContentType();
111 		else
112 			return getContentType() + ";charset=" + encoding;
113 	}
114 
115 	public String getContentType()
116 	{
117 		return "text/xml";
118 	}
119 
120 	public QName getBodyQName()
121 	{
122 		return bodyQName;
123 	}
124 
125 	public QName getEnvelopeQName()
126 	{
127 		return envelopeQName;
128 	}
129 
130 	public QName getHeaderQName()
131 	{
132 		return headerQName;
133 	}
134 	
135 	protected SchemaTypeLoader getSoapEnvelopeSchemaLoader()
136 	{
137 		return soapSchema;
138 	}
139 
140 	public SchemaType getFaultType()
141 	{
142 		return soapFaultType;
143 	}
144 }