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