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  import com.eviware.soapui.support.StringUtils;
30  
31  /***
32   * SoapVersion for SOAP 1.2
33   * 
34   * @author ole.matzura
35   */
36  
37  public class SoapVersion12 extends AbstractSoapVersion
38  {
39     private final static QName envelopeQName  = new QName(Constants.SOAP12_ENVELOPE_NS, "Envelope");
40     private final static QName bodyQName = new QName(Constants.SOAP12_ENVELOPE_NS, "Body");
41     private final static QName faultQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Fault");
42     private final static QName headerQName = new QName(Constants.SOAP12_ENVELOPE_NS, "Header");
43  	public final static SoapVersion12 instance = new SoapVersion12();
44  	
45     private SchemaTypeLoader soapSchema;
46  	private XmlObject soapSchemaXml;
47  	private XmlObject soapEncodingXml;
48  
49     private SoapVersion12()
50     {
51     	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
52     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
53     	
54     	try
55     	{
56  			soapSchemaXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEnvelope12.xsd"));
57  			soapSchema = XmlBeans.loadXsd(new XmlObject[] { soapSchemaXml });
58  	   	soapEncodingXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEncoding12.xsd"));
59     	}
60     	catch( Exception e )
61     	{
62     		SoapUI.logError( e );
63     	}
64     	finally
65     	{
66     		Thread.currentThread().setContextClassLoader( contextClassLoader );
67     	}
68     }
69     
70     public String getEncodingNamespace()
71  	{
72  		return "http://www.w3.org/2003/05/soap-encoding";
73  	}
74     
75  	public XmlObject getSoapEncodingSchema() throws XmlException, IOException
76  	{
77  		return soapEncodingXml;
78  	}
79  
80  	public XmlObject getSoapEnvelopeSchema() throws XmlException, IOException
81  	{
82  		return soapSchemaXml;
83  	}
84  	
85  	public String getEnvelopeNamespace()
86  	{
87  		return Constants.SOAP12_ENVELOPE_NS;
88  	}
89  
90  	public SchemaType getEnvelopeType()
91  	{
92  		return EnvelopeDocument.type;
93  	}
94  
95  	public String toString()
96  	{
97  		return "SOAP 1.2";
98  	}
99  	
100 	public String getContentTypeHttpHeader(String encoding, String soapAction)
101 	{
102 		String result = getContentType();
103 		
104 		if (encoding != null && encoding.trim().length() > 0)
105 			result += ";charset=" + encoding;
106 		
107 		if( StringUtils.hasContent( soapAction ) )
108 			result += ";action=" + soapAction;
109 		
110 		return result;
111 	}
112 
113 	public String getSoapActionHeader( String soapAction )
114 	{
115 		// SOAP 1.2 has this in the contenttype
116 		return null;
117 	}
118 
119 	public String getContentType()
120 	{
121 		return "application/soap+xml";
122 	}
123 	
124 	public QName getBodyQName()
125 	{
126 		return bodyQName;
127 	}
128 
129 	public QName getEnvelopeQName()
130 	{
131 		return envelopeQName;
132 	}
133 
134 	public QName getHeaderQName()
135 	{
136 		return headerQName;
137 	}
138 
139 	protected SchemaTypeLoader getSoapEnvelopeSchemaLoader()
140 	{
141 		return soapSchema;
142 	}
143 	
144 	public static QName getFaultQName()
145 	{
146 		return faultQName;
147 	}
148 
149 	public SchemaType getFaultType()
150 	{
151 		return FaultDocument.type;
152 	}
153 
154 	public String getName()
155 	{
156 		return "SOAP 1.2";
157 	}
158 }