View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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  /***
31   * SoapVersion for SOAP 1.1
32   * 
33   * @author ole.matzura
34   */
35  
36  public class SoapVersion11 extends AbstractSoapVersion
37  {
38     private final static QName envelopeQName  = new QName(Constants.SOAP11_ENVELOPE_NS, "Envelope");
39     private final static QName bodyQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Body");
40     private final static QName faultQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Fault");
41     private final static QName headerQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Header");
42  	
43     SchemaTypeLoader soapSchema;
44  	SchemaType soapEnvelopeType;
45  	private XmlObject soapSchemaXml;
46  	private XmlObject soapEncodingXml;
47  	private SchemaType soapFaultType;
48  	
49  	public final static SoapVersion11 instance = new SoapVersion11();
50  
51     private SoapVersion11()
52     {
53     	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
54     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
55     	
56     	try
57     	{
58     		XmlOptions options = new XmlOptions();
59           options.setCompileNoValidation();
60           options.setCompileNoPvrRule();
61           options.setCompileDownloadUrls();
62           options.setCompileNoUpaRule();
63           options.setValidateTreatLaxAsSkip();
64     		
65  	   	soapSchemaXml = XmlObject.Factory.parse(
66  	   				SoapUI.class.getResource("/com/eviware/soapui/resources/xsds/soapEnvelope.xsd"), options);
67  			soapSchema = XmlBeans.loadXsd(new XmlObject[] { soapSchemaXml });
68  	
69  	   	soapEnvelopeType = soapSchema.findDocumentType( envelopeQName );
70  	   	soapFaultType = soapSchema.findDocumentType( faultQName );
71  	   	
72  	   	soapEncodingXml = XmlObject.Factory.parse(
73  	   				SoapUI.class.getResource("/com/eviware/soapui/resources/xsds/soapEncoding.xsd"), options);
74     	}
75     	catch( Exception e )
76     	{
77     		SoapUI.logError( e );
78     	}
79     	finally
80     	{
81     		Thread.currentThread().setContextClassLoader( contextClassLoader );
82     	}
83     }
84     
85  	public SchemaType getEnvelopeType()
86  	{
87  		return EnvelopeDocument.type;
88  	}
89  	
90  	public String getEnvelopeNamespace()
91  	{
92  		return Constants.SOAP11_ENVELOPE_NS;
93  	}
94  	
95  	public String getEncodingNamespace()
96  	{
97  		return Constants.SOAP_ENCODING_NS;
98  	}
99  
100 	public XmlObject getSoapEncodingSchema() throws XmlException, IOException
101 	{
102 		return soapEncodingXml;
103 	}
104 
105 	public XmlObject getSoapEnvelopeSchema() throws XmlException, IOException
106 	{
107 		return soapSchemaXml;
108 	}
109 	
110 	public String toString()
111 	{
112 		return "SOAP 1.1";
113 	}
114 
115 	public String getContentTypeHttpHeader(String encoding, String soapAction)
116 	{
117 		if (encoding == null || encoding.trim().length() == 0)
118 			return getContentType();
119 		else
120 			return getContentType() + ";charset=" + encoding;
121 	}
122 
123 	public String getSoapActionHeader( String soapAction )
124 	{
125 		if (soapAction == null || soapAction.length() == 0)
126 		{
127 			soapAction = "\"\"";
128 		}
129 		else
130 		{
131 			soapAction = "\"" + soapAction + "\"";
132 		}
133 		
134 		return soapAction;
135 	}
136 
137 	public String getContentType()
138 	{
139 		return "text/xml";
140 	}
141 
142 	public QName getBodyQName()
143 	{
144 		return bodyQName;
145 	}
146 
147 	public QName getEnvelopeQName()
148 	{
149 		return envelopeQName;
150 	}
151 
152 	public QName getHeaderQName()
153 	{
154 		return headerQName;
155 	}
156 	
157 	protected SchemaTypeLoader getSoapEnvelopeSchemaLoader()
158 	{
159 		return soapSchema;
160 	}
161 
162 	public SchemaType getFaultType()
163 	{
164 		return soapFaultType;
165 	}
166 
167 	public String getName()
168 	{
169 		return "SOAP 1.1";
170 	}
171 
172 	public String getFaultDetailNamespace()
173 	{
174 		return "";
175 	}
176 }