View Javadoc

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