View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.w3.x2003.x05.soapEnvelope.EnvelopeDocument;
25  import org.w3.x2003.x05.soapEnvelope.FaultDocument;
26  
27  import com.eviware.soapui.SoapUI;
28  import com.eviware.soapui.impl.wsdl.support.Constants;
29  
30  public class SoapVersion12 extends AbstractSoapVersion
31  {
32     private final static QName envelopeQName  = new QName(Constants.SOAP12_ENVELOPE_NS, "Envelope");
33     private final static QName bodyQName = new QName(Constants.SOAP12_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.SOAP12_ENVELOPE_NS, "Header");
36  	public final static SoapVersion12 instance = new SoapVersion12();
37  	
38     private SchemaTypeLoader soapSchema;
39  	private XmlObject soapSchemaXml;
40  	private XmlObject soapEncodingXml;
41  
42     private SoapVersion12()
43     {
44     	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
45     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
46     	
47     	try
48     	{
49  			soapSchemaXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEnvelope12.xsd"));
50  			soapSchema = XmlBeans.loadXsd(new XmlObject[] { soapSchemaXml });
51  	   	soapEncodingXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEncoding12.xsd"));
52     	}
53     	catch( Exception e )
54     	{
55     		e.printStackTrace();
56     	}
57     	finally
58     	{
59     		Thread.currentThread().setContextClassLoader( contextClassLoader );
60     	}
61     }
62     
63     public String getEncodingNamespace()
64  	{
65  		return "http://www.w3.org/2003/05/soap-encoding";
66  	}
67     
68  	public XmlObject getSoapEncodingSchema() throws XmlException, IOException
69  	{
70  		return soapEncodingXml;
71  	}
72  
73  	public XmlObject getSoapEnvelopeSchema() throws XmlException, IOException
74  	{
75  		return soapSchemaXml;
76  	}
77  	
78  	public String getEnvelopeNamespace()
79  	{
80  		return Constants.SOAP12_ENVELOPE_NS;
81  	}
82  
83  	public SchemaType getEnvelopeType()
84  	{
85  		return EnvelopeDocument.type;
86  	}
87  
88  	public String toString()
89  	{
90  		return "SOAP 1.2";
91  	}
92  	
93  	public String getContentTypeHttpHeader(String encoding)
94  	{
95  		if (encoding == null || encoding.trim().length() == 0)
96  			return getContentType();
97  		else
98  			return getContentType() + ";charset=" + encoding;
99  	}
100 
101 	public String getContentType()
102 	{
103 		return "application/soap+xml";
104 	}
105 	
106 	public QName getBodyQName()
107 	{
108 		return bodyQName;
109 	}
110 
111 	public QName getEnvelopeQName()
112 	{
113 		return envelopeQName;
114 	}
115 
116 	public QName getHeaderQName()
117 	{
118 		return headerQName;
119 	}
120 
121 	protected SchemaTypeLoader getSoapEnvelopeSchemaLoader()
122 	{
123 		return soapSchema;
124 	}
125 	
126 	public static QName getFaultQName()
127 	{
128 		return faultQName;
129 	}
130 
131 	public SchemaType getFaultType()
132 	{
133 		return FaultDocument.type;
134 	}
135 }